From bac9a9aa27dfdabe408a44193e3a3e660b9f821e Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Wed, 14 Jul 2021 12:16:31 -0400 Subject: [PATCH] feature: creating carpools with pre-invited users: complete! --- src/components/Event/EventCarpools.tsx | 14 +++++++++----- src/components/api.ts | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/Event/EventCarpools.tsx b/src/components/Event/EventCarpools.tsx index 0dd2a1f..a08e170 100644 --- a/src/components/Event/EventCarpools.tsx +++ b/src/components/Event/EventCarpools.tsx @@ -112,10 +112,14 @@ export default function Carpools() { setHasCarpool(alreadyInCarpool); }, [alreadyInCarpool, setHasCarpool]); - const createEmptyCarpool = useCallback(() => { + const createCarpoolCallback = useCallback(() => { setCreationStatus('pending'); - createCarpool({ name: me.name + "'s Carpool", eventId: event.id }) + createCarpool({ + name: me.name + "'s Carpool", + eventId: event.id, + invitedUserIds: tentativeInvites.toArray(), + }) .then(({ id }) => { setCreatedCarpoolId(id); setCreationStatus('completed'); @@ -123,7 +127,7 @@ export default function Carpools() { .catch(() => { setCreationStatus('errored'); }); - }, [event.id, me.name]); + }, [event.id, me.name, tentativeInvites]); const tentativeInviteNames = useMemo(() => { if (!signups) return []; @@ -146,7 +150,7 @@ export default function Carpools() { You have invited these people to carpool with you: {tentativeInviteNames.join(',')} {creationStatus === null @@ -162,7 +166,7 @@ export default function Carpools() { <> Available to drive? {creationStatus === null diff --git a/src/components/api.ts b/src/components/api.ts index 61fd027..ac09a49 100644 --- a/src/components/api.ts +++ b/src/components/api.ts @@ -175,11 +175,13 @@ export async function getCarpool(id: number): Promise { export async function createCarpool({ eventId, name, + invitedUserIds, }: { eventId: number; name: string; + invitedUserIds: number[]; }): Promise<{ id: number }> { - return await post('/carpools/', { eventId, name }); + return await post('/carpools/', { eventId, name, invitedUserIds }); } export async function sendCarpoolInvite(carpoolId: number, userId: number) {