From 7963318fa6f38ffa48bd44ae26615ce909c2d711 Mon Sep 17 00:00:00 2001 From: Ihsaan Ahmed Yasin <68300319+iyasinn@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:08:18 -0400 Subject: [PATCH] Enhance connection modal features (#100) * Add loading symbol to connection * REmove console.log * Cleaned up and updated the startup modal to make it cleaner * Made lots of changes to modal to improving styling + errors handling + UX flow * Reoganize packages --- components/startups/StartupProfileTile.tsx | 158 ++++++++++++++------- package.json | 1 + yarn.lock | 5 + 3 files changed, 116 insertions(+), 48 deletions(-) diff --git a/components/startups/StartupProfileTile.tsx b/components/startups/StartupProfileTile.tsx index b384805..12ae853 100644 --- a/components/startups/StartupProfileTile.tsx +++ b/components/startups/StartupProfileTile.tsx @@ -1,5 +1,7 @@ -import { useState, Fragment } from "react"; +import { useState, Fragment, useCallback } from "react"; import { Dialog, Transition } from "@headlessui/react"; +import { CheckCircleIcon, XCircleIcon } from "@heroicons/react/solid"; +import { FaSlack, FaEnvelope } from "react-icons/fa"; import useSupabase from "../../hooks/useSupabase"; import supabase from "../../utils/supabaseClient"; import { StartupProfile, StartupProfileMetadata } from "../../utils/types"; @@ -25,12 +27,16 @@ export default function StartupProfileTile({ } = startupProfile; const displayName = profileName ?? profileUsername; + const slackLink = (profileSlackLink as string) ?? "https://app.slack.com/client/T04JWPLEL5B/C04KPD6KS80"; const { role, headshot_src: headshotSrc } = startupProfileMetadata; const [connectDialogOpen, setConnectDialogOpen] = useState(false); - const [connectionSent, setConnectionSent] = useState(false); + const [connectionStatus, setConnectionStatus] = useState<{ + success: boolean; + message: string; + } | null>(null); const [connectionMessage, setConnectionMessage] = useState(""); const { rank } = useSupabase(); @@ -40,14 +46,14 @@ export default function StartupProfileTile({ const anonymousPersonImage = "https://www.shutterstock.com/image-vector/default-avatar-profile-icon-social-600nw-1677509740.jpg"; - function sendConnectionMessage() { + const [isLoading, setIsLoading] = useState(false); + + const sendConnectionMessage = useCallback(() => { const session = supabase.auth.session(); - // Null handling. - if (!session) { - return; - } + if (!session) return; const { access_token: accessToken } = session; + setIsLoading(true); const body = JSON.stringify({ recipient: profileEmail, message: connectionMessage, @@ -59,13 +65,30 @@ export default function StartupProfileTile({ Authorization: `Bearer ${accessToken}`, }, body, - }).then((response) => { - if (response.ok) { + }) + .then(async (response) => { setConnectDialogOpen(false); - setConnectionSent(true); - } - }); - } + setIsLoading(false); + + if (response.ok) { + setConnectionStatus({ + success: true, + message: "Connection sent successfully!", + }); + } else { + const errorBody = await response.text(); + setConnectionStatus({ success: false, message: errorBody }); + } + }) + .catch((error) => { + console.log("Error sending connection request:", error); + setIsLoading(false); + setConnectionStatus({ + success: false, + message: "An error occurred while sending the connection request.", + }); + }); + }, [profileEmail, connectionMessage]); return (
@@ -81,10 +104,21 @@ export default function StartupProfileTile({

{displayName}

{role}

- {connectionSent ? ( -

- connection sent successfully! -

+ {connectionStatus ? ( +
+ {connectionStatus.success ? ( + + ) : ( + + )} +

{connectionStatus.message}

+
) : ( - - ) : ( + )} + + {v1Member && ( +
+
+ + Send an email message +
+
+
+