mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 19:29:51 -04:00
feat: added unregister funcitonality
This commit is contained in:
parent
f6b3fb87ea
commit
2ef179048b
|
@ -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'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user