mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
Integrate CreatePool into the Group page
This commit is contained in:
parent
a8d4e1a692
commit
b0c03b4887
|
@ -4,7 +4,6 @@ import Nav from './components/Nav';
|
||||||
import Group from './components/Group';
|
import Group from './components/Group';
|
||||||
import Pool from './components/Pool';
|
import Pool from './components/Pool';
|
||||||
import Profile from './components/Profile';
|
import Profile from './components/Profile';
|
||||||
import CreatePool from './components/CreatePool';
|
|
||||||
import CreateGroup from './components/CreateGroup';
|
import CreateGroup from './components/CreateGroup';
|
||||||
import Groups from './components/Groups';
|
import Groups from './components/Groups';
|
||||||
import MyGroups from './components/MyGroups';
|
import MyGroups from './components/MyGroups';
|
||||||
|
@ -26,7 +25,6 @@ function App() {
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route component={Main} path="/about" />
|
<Route component={Main} path="/about" />
|
||||||
<Route component={Authenticator} path="/auth/:provider/callback" />
|
<Route component={Authenticator} path="/auth/:provider/callback" />
|
||||||
<Route component={CreatePool} path="/create_pool" />
|
|
||||||
<Route component={CreateGroup} path="/create_group" />
|
<Route component={CreateGroup} path="/create_group" />
|
||||||
<Route component={MyGroups} path="/mygroups" />
|
<Route component={MyGroups} path="/mygroups" />
|
||||||
<Route component={UpdatePool} path="/update_pool" />
|
<Route component={UpdatePool} path="/update_pool" />
|
||||||
|
|
|
@ -8,11 +8,7 @@ import { searchForPlaces } from '../api/google';
|
||||||
import { makeAPIPostCall, makeAPIGetCall } from '../api/utils';
|
import { makeAPIPostCall, makeAPIGetCall } from '../api/utils';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import { makeAPIPostCall } from '../api/utils';
|
import PlacesAutocomplete from 'react-places-autocomplete';
|
||||||
import PlacesAutocomplete, {
|
|
||||||
geocodeByAddress,
|
|
||||||
getLatLng,
|
|
||||||
} from 'react-places-autocomplete';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
|
@ -26,7 +22,7 @@ const useStyles = makeStyles((theme) => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const CreatePool = () => {
|
const CreatePool = ({ groupID }: { groupID?: string }) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [title, setTitle] = useState('No Title');
|
const [title, setTitle] = useState('No Title');
|
||||||
const [capacity, setCapacity] = useState(0);
|
const [capacity, setCapacity] = useState(0);
|
||||||
|
@ -188,6 +184,7 @@ const CreatePool = () => {
|
||||||
name="group-select"
|
name="group-select"
|
||||||
id="group-select"
|
id="group-select"
|
||||||
onChange={(event) => setGroup(event.target.value)}
|
onChange={(event) => setGroup(event.target.value)}
|
||||||
|
defaultValue={groupID}
|
||||||
>
|
>
|
||||||
<option value="">Select a group</option>
|
<option value="">Select a group</option>
|
||||||
{groups.map((group) => (
|
{groups.map((group) => (
|
||||||
|
@ -279,7 +276,6 @@ const CreatePool = () => {
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { useParams } from 'react-router-dom';
|
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import Card from '@material-ui/core/Card';
|
import Card from '@material-ui/core/Card';
|
||||||
import Typography from '@material-ui/core/Typography';
|
import Typography from '@material-ui/core/Typography';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
import { makeAPIGetCall } from '../api/utils';
|
import { makeAPIGetCall } from '../api/utils';
|
||||||
|
import CreatePool from './CreatePool';
|
||||||
|
|
||||||
const maybePluralize = (count: number, noun: string, suffix = 's') =>
|
const maybePluralize = (count: number, noun: string, suffix = 's') =>
|
||||||
`${count} ${noun}${count !== 1 ? suffix : ''}`;
|
`${count} ${noun}${count !== 1 ? suffix : ''}`;
|
||||||
|
@ -41,6 +42,7 @@ export default function Group() {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [group, setGroup] = useState<Carpool.Group>();
|
const [group, setGroup] = useState<Carpool.Group>();
|
||||||
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
|
const [pools, setPools] = useState<Carpool.Pool[]>(SAMPLE_POOLS);
|
||||||
|
const [createPoolVisible, setCreatePoolVisible] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
makeAPIGetCall(`/groups/${id}`).then((res) => {
|
makeAPIGetCall(`/groups/${id}`).then((res) => {
|
||||||
|
@ -80,16 +82,18 @@ export default function Group() {
|
||||||
<Typography variant="h3" align="center">
|
<Typography variant="h3" align="center">
|
||||||
Pools
|
Pools
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<div>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => (window.location.href = '/create_pool')}
|
onClick={() => setCreatePoolVisible((v) => !v)}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
>
|
>
|
||||||
Create Pool
|
{createPoolVisible ? 'Cancel' : 'Create Pool'}
|
||||||
</Button>
|
</Button>
|
||||||
<div className="container">
|
{createPoolVisible && <CreatePool groupID={group._id} />}
|
||||||
{pools.map((pool, index) => {
|
</div>
|
||||||
return (
|
{pools.map((pool, index) => (
|
||||||
<Card style={{ margin: '0.5em' }} key={index}>
|
<Card style={{ margin: '0.5rem', padding: '0.5rem' }} key={index}>
|
||||||
<a href={'/pools/' + pool._id} className="card-title">
|
<a href={'/pools/' + pool._id} className="card-title">
|
||||||
{pool.title}
|
{pool.title}
|
||||||
</a>
|
</a>
|
||||||
|
@ -102,8 +106,7 @@ export default function Group() {
|
||||||
{maybePluralize(pool.comments.length, 'comment')}
|
{maybePluralize(pool.comments.length, 'comment')}
|
||||||
</p>
|
</p>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
))}
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,8 +11,6 @@ import Box from '@material-ui/core/Box';
|
||||||
import { makeAPIGetCall, makeAPIPostCall } from '../api/utils';
|
import { makeAPIGetCall, makeAPIPostCall } from '../api/utils';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import GoogleMapReact from 'google-map-react';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
maxWidth: 345,
|
maxWidth: 345,
|
||||||
|
@ -32,24 +30,6 @@ const useStyles = makeStyles((theme) => ({
|
||||||
const Groups = () => {
|
const Groups = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [state, setState] = useState({
|
|
||||||
MyGroups: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
group_title: 'TJ',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const callAPI = () => {
|
|
||||||
fetch(`${process.env.REACT_APP_API_ENDPOINT}/groups/`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
if (data !== undefined) {
|
|
||||||
setState(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const [groups, setGroups] = useState<Carpool.Group[]>([
|
const [groups, setGroups] = useState<Carpool.Group[]>([
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user