Refactor: Enhance email change status handling

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 15:45:05 +00:00
parent 04d0ff5606
commit d556243ff6
3 changed files with 37 additions and 15 deletions

View File

@@ -20,7 +20,7 @@ import {
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { useToast } from '@/hooks/use-toast';
import { toast } from 'sonner';
import { supabase } from '@/integrations/supabase/client';
import { Loader2, Mail, CheckCircle2, AlertCircle } from 'lucide-react';
import { TurnstileCaptcha } from '@/components/auth/TurnstileCaptcha';
@@ -49,7 +49,6 @@ interface EmailChangeDialogProps {
}
export function EmailChangeDialog({ open, onOpenChange, currentEmail, userId }: EmailChangeDialogProps) {
const { toast } = useToast();
const { theme } = useTheme();
const [step, setStep] = useState<Step>('verification');
const [loading, setLoading] = useState(false);
@@ -79,19 +78,15 @@ export function EmailChangeDialog({ open, onOpenChange, currentEmail, userId }:
const onSubmit = async (data: EmailFormData) => {
if (!captchaToken) {
toast({
title: 'CAPTCHA Required',
toast.error('CAPTCHA Required', {
description: 'Please complete the CAPTCHA verification.',
variant: 'destructive'
});
return;
}
if (data.newEmail.toLowerCase() === currentEmail.toLowerCase()) {
toast({
title: 'Same Email',
toast.error('Same Email', {
description: 'The new email is the same as your current email.',
variant: 'destructive'
});
return;
}
@@ -162,13 +157,15 @@ export function EmailChangeDialog({ open, onOpenChange, currentEmail, userId }:
});
}
toast.success('Email change initiated', {
description: 'Check both email addresses for confirmation links.',
});
setStep('success');
} catch (error: any) {
console.error('Email change error:', error);
toast({
title: 'Error',
description: error.message || 'Failed to change email address',
variant: 'destructive'
toast.error('Failed to change email', {
description: error.message || 'Please try again.',
});
} finally {
setLoading(false);