From cca03563f224e30380b359d14366bf132189795e Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sun, 22 Aug 2021 19:09:56 -0400 Subject: [PATCH] add bio/profile --- src/components/App.tsx | 2 + .../Authentication/AuthenticationContext.ts | 1 + src/components/Header/Header.tsx | 1 + .../ProfileForSelf/ProfileForSelf.tsx | 93 +++++++++++++++++++ src/components/api.ts | 4 + 5 files changed, 101 insertions(+) create mode 100644 src/components/ProfileForSelf/ProfileForSelf.tsx diff --git a/src/components/App.tsx b/src/components/App.tsx index 9314c31..d5c28b5 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -19,6 +19,7 @@ const CarpoolPage = lazy(() => import('./Carpool/CarpoolPage')); const EventPage = lazy(() => import('./Event/EventPage')); const GroupPage = lazy(() => import('./Group/GroupPage')); const GroupSharedLinkResolver = lazy(() => import('./GroupSharedLinkResolver')); +const ProfileForSelf = lazy(() => import('./ProfileForSelf/ProfileForSelf')); const style: CSSProperties = { display: 'flex', @@ -63,6 +64,7 @@ export default function App() { + Log out + Profile
{notifications.length > 0 ? ( { + await updateBio(temporaryBio); + refreshLocalUser(); + setEditingBio(false); + }, + [refreshLocalUser] + ) + ); + + useEffect(() => { + if (me?.bio) { + setTemporaryBio(me?.bio); + } + }, [me?.bio]); + + if (!me) { + return null; + } + + return ( +
+

{me.name}

+

{me.bio}

+ {editingBio ? ( + <> + {onClickedSaveBioStatus === AsyncCallbackStatus.REJECTED && ( +

Error saving bio.

+ )} + {onClickedSaveBioStatus !== AsyncCallbackStatus.PENDING ? ( + <> + + onClickedSaveBio(temporaryBio)} + style={{ + backgroundColor: '#f8f8f8', + width: '100%', + }} + > + Save + + + ) : ( + {}} + style={{ + backgroundColor: '#f8f8f8', + width: '100%', + }} + > + Saving... + + )} + + ) : ( + <> + setEditingBio(true)} + style={{ + backgroundColor: '#f8f8f8', + width: '100%', + }} + > + Edit Bio + + + )} +
+ ); +} diff --git a/src/components/api.ts b/src/components/api.ts index ec0cd40..135fd4e 100644 --- a/src/components/api.ts +++ b/src/components/api.ts @@ -298,3 +298,7 @@ export async function getPotentialInvitees( ): Promise { return await get(`/carpools/${carpoolId}/potential_invitees`); } + +export async function updateBio(bio: string) { + return await post('/users/@me/bio', { bio }); +}