mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 11:51:14 -05:00
Refactor: Enhance email change status handling
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user