'use client'; import { useRouter } from 'next/navigation'; import { Edit, Loader, Mail, MoreHorizontal, X } from 'lucide-react'; import type { getTeamByUrl } from '@documenso/lib/server-only/team/get-team'; import { trpc } from '@documenso/trpc/react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@documenso/ui/primitives/dropdown-menu'; import { useToast } from '@documenso/ui/primitives/use-toast'; import { UpdateTeamEmailDialog } from '~/components/(teams)/dialogs/update-team-email-dialog'; export type TeamsSettingsPageProps = { team: Awaited>; }; export const TeamEmailDropdown = ({ team }: TeamsSettingsPageProps) => { const router = useRouter(); const { toast } = useToast(); const { mutateAsync: resendEmailVerification, isLoading: isResendingEmailVerification } = trpc.team.resendTeamEmailVerification.useMutation({ onSuccess: () => { toast({ title: 'Success', description: 'Email verification has been resent', duration: 5000, }); }, onError: () => { toast({ title: 'Something went wrong', variant: 'destructive', duration: 10000, description: 'Unable to resend verification at this time. Please try again.', }); }, }); const { mutateAsync: deleteTeamEmail, isLoading: isDeletingTeamEmail } = trpc.team.deleteTeamEmail.useMutation({ onSuccess: () => { toast({ title: 'Success', description: 'Team email has been removed', duration: 5000, }); }, onError: () => { toast({ title: 'Something went wrong', variant: 'destructive', duration: 10000, description: 'Unable to remove team email at this time. Please try again.', }); }, }); const { mutateAsync: deleteTeamEmailVerification, isLoading: isDeletingTeamEmailVerification } = trpc.team.deleteTeamEmailVerification.useMutation({ onSuccess: () => { toast({ title: 'Success', description: 'Email verification has been removed', duration: 5000, }); }, onError: () => { toast({ title: 'Something went wrong', variant: 'destructive', duration: 10000, description: 'Unable to remove email verification at this time. Please try again.', }); }, }); const onRemove = async () => { if (team.teamEmail) { await deleteTeamEmail({ teamId: team.id }); } if (team.emailVerification) { await deleteTeamEmailVerification({ teamId: team.id }); } router.refresh(); }; return ( {!team.teamEmail && team.emailVerification && ( { e.preventDefault(); void resendEmailVerification({ teamId: team.id }); }} > {isResendingEmailVerification ? ( ) : ( )} Resend verification )} {team.teamEmail && ( e.preventDefault()}> Edit } /> )} onRemove()} > Remove ); };