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}
) }