From cef2c6a2fed852de2e8ae5a60447b28e753b052f Mon Sep 17 00:00:00 2001 From: isra el Date: Fri, 14 Mar 2025 17:20:47 +0300 Subject: [PATCH] chore(api): add email verification CTA in dashboard --- .../(components)/dashboard-layout.tsx | 7 +- .../(components)/verify-email-alert.tsx | 86 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 web/app/(app)/dashboard/(components)/verify-email-alert.tsx diff --git a/web/app/(app)/dashboard/(components)/dashboard-layout.tsx b/web/app/(app)/dashboard/(components)/dashboard-layout.tsx index e7a3abe..0260f3f 100644 --- a/web/app/(app)/dashboard/(components)/dashboard-layout.tsx +++ b/web/app/(app)/dashboard/(components)/dashboard-layout.tsx @@ -14,6 +14,8 @@ import { useSession } from 'next-auth/react' import { JoinCommunityModal } from '@/components/shared/join-community-modal' import { ContributeModal } from '@/components/shared/contribute-modal' import UpgradeToProAlert from './upgrade-to-pro-alert' +import VerifyEmailAlert from './verify-email-alert' + export default function Dashboard({ children, }: { @@ -66,17 +68,20 @@ export default function Dashboard({ + - + + + diff --git a/web/app/(app)/dashboard/(components)/verify-email-alert.tsx b/web/app/(app)/dashboard/(components)/verify-email-alert.tsx new file mode 100644 index 0000000..0473419 --- /dev/null +++ b/web/app/(app)/dashboard/(components)/verify-email-alert.tsx @@ -0,0 +1,86 @@ +import { Alert, AlertDescription } from '@/components/ui/alert' +import { Button } from '@/components/ui/button' +import { ApiEndpoints } from '@/config/api' +import httpBrowserClient from '@/lib/httpBrowserClient' +import { useQuery } from '@tanstack/react-query' +import Link from 'next/link' +import { useMemo } from 'react' +import { Mail, ShieldAlert } from 'lucide-react' + +export default function VerifyEmailAlert() { + const { + data: userData, + isLoading: isLoadingUserData, + error: userDataError, + } = useQuery({ + queryKey: ['whoAmI'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.auth.whoAmI()) + .then((res) => res.data.data), + }) + + const ctaMessages = useMemo( + () => [ + 'Hey there! Verify your email to keep your service running smoothly.', + 'Quick heads up - we need to verify your email to prevent any interruptions.', + 'Just a friendly reminder to verify your email and avoid service disruptions.', + 'Your account needs email verification to ensure uninterrupted service.', + 'One small step to go - verify your email to keep your account active and running.', + ], + [] + ) + + const buttonTexts = useMemo( + () => [ + 'Verify Email', + "Let's Do This", + 'Verify Now', + 'Complete Verification', + ], + [] + ) + + const randomCta = useMemo(() => { + const randomIndex = Math.floor(Math.random() * ctaMessages.length) + return ctaMessages[randomIndex] + }, [ctaMessages]) + + const randomButtonText = useMemo(() => { + const randomIndex = Math.floor(Math.random() * buttonTexts.length) + return buttonTexts[randomIndex] + }, [buttonTexts]) + + if (isLoadingUserData || !userData || userDataError) { + return null + } + + // If email is already verified, don't show the alert + if (userData.emailVerifiedAt) { + return null + } + + return ( + + + + + {randomCta} + +
+ +
+
+
+ ) +}