update getPool API request

This commit is contained in:
Michael Fatemi 2021-04-10 21:26:27 -04:00
parent 9b13a27331
commit 7e6951ac03

View File

@ -5,7 +5,7 @@ import Card from '@material-ui/core/Card';
import Textarea from '@material-ui/core/TextareaAutosize'; import Textarea from '@material-ui/core/TextareaAutosize';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import Comment from './Comment'; import Comment from './Comment';
import { makeAPIPostCall } from '../api/utils'; import { makeAPIGetCall, makeAPIPostCall } from '../api/utils';
import AuthenticationContext from './AuthenticationContext'; import AuthenticationContext from './AuthenticationContext';
// eslint-disable-next-line // eslint-disable-next-line
@ -89,11 +89,9 @@ export default function Pool() {
}, [user, id, pool]); }, [user, id, pool]);
useEffect(() => { useEffect(() => {
fetch(`${process.env.REACT_APP_API_ENDPOINT}/pool/${id}`) makeAPIGetCall('/pool', { poolID: id }).then((response) => {
.then((response) => response.json()) if (response.data.data) {
.then((data) => { setPool(response.data.data);
if (data !== undefined) {
setPool(data);
} }
}); });
}, [id]); }, [id]);
@ -106,7 +104,7 @@ export default function Pool() {
{pool.title} {pool.title}
</Typography> </Typography>
<Typography variant="subtitle1"> <Typography variant="subtitle1">
<b>Capacity</b>: {pool.participant_ids.length} / {pool.capacity} <b>Capacity</b>: {pool.participant_ids?.length} / {pool.capacity}
</Typography> </Typography>
<Typography variant="subtitle1"> <Typography variant="subtitle1">
<b>Start Time</b>: {pool.start_time} <b>Start Time</b>: {pool.start_time}
@ -122,7 +120,7 @@ export default function Pool() {
style={{ marginTop: '0.5rem' }} style={{ marginTop: '0.5rem' }}
onClick={onRegister} onClick={onRegister}
> >
{pool.participant_ids.includes(user._id) {pool.participant_ids?.includes(user._id)
? 'Unregister' ? 'Unregister'
: 'Register'} : 'Register'}
</Button> </Button>