feat: added unregister funcitonality

This commit is contained in:
Rushil Umaretiya 2021-04-11 00:56:38 -04:00
parent f6b3fb87ea
commit 2ef179048b
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959

View File

@ -89,13 +89,28 @@ export default function Pool() {
} }
}, [user, id, pool]); }, [user, id, pool]);
const onUnregister = useCallback(() => {
if (user) {
makeAPIPostCall(`/pools/${id}/leave`).then(() => {
if (pool) {
let participants: string[] = [];
pool.participant_ids.forEach((e) => participants.push(e));
setPool({
...pool,
participant_ids: [...participants],
});
}
});
}
}, [user, id, pool]);
useEffect(() => { useEffect(() => {
makeAPIGetCall(`/pools/${id}`).then((response) => { makeAPIGetCall(`/pools/${id}`).then((response) => {
if (response.data.data) { if (response.data.data) {
setPool(response.data.data); setPool(response.data.data);
} }
}); });
}, [id]); }, [id, pool]);
return ( return (
<Card style={{ margin: '3rem auto', padding: '1rem 1rem', width: '50%' }}> <Card style={{ margin: '3rem auto', padding: '1rem 1rem', width: '50%' }}>
@ -119,7 +134,11 @@ export default function Pool() {
variant="contained" variant="contained"
color="primary" color="primary"
style={{ marginTop: '0.5rem' }} style={{ marginTop: '0.5rem' }}
onClick={onRegister} onClick={
pool.participant_ids?.includes(user._id)
? onUnregister
: onRegister
}
> >
{pool.participant_ids?.includes(user._id) {pool.participant_ids?.includes(user._id)
? 'Unregister' ? 'Unregister'