@@ -5,7 +5,7 @@ import {Card} from "../../common/Card";
55import { Button , Center , Container , PinInput , Select , Stack , Text , TextInput } from "@mantine/core" ;
66import classes from "./Welcome.module.scss" ;
77import { useForm } from "@mantine/form" ;
8- import { useMediaQuery } from "@mantine/hooks" ;
8+ import { useDebouncedValue , useMediaQuery } from "@mantine/hooks" ;
99import { Event } from "../../../types.ts" ;
1010import { useCreateEvent } from "../../../mutations/useCreateEvent.ts" ;
1111import { NavLink , useNavigate } from "react-router" ;
@@ -57,6 +57,7 @@ const ConfirmVerificationPin = ({progressInfo}: {
5757 const confirmEmailMutation = useConfirmEmailWithCode ( ) ;
5858 const resendMutation = useResendEmailConfirmation ( ) ;
5959 const [ resendCooldown , setResendCooldown ] = useState ( 0 ) ;
60+ const [ completedPin , setCompletedPin ] = useState ( '' ) ;
6061 const isMobile = useMediaQuery ( '(max-width: 768px)' ) ;
6162
6263 const form = useForm ( {
@@ -68,6 +69,16 @@ const ConfirmVerificationPin = ({progressInfo}: {
6869 }
6970 } ) ;
7071
72+ // Debounce the completed pin value
73+ const [ debouncedPin ] = useDebouncedValue ( completedPin , 800 ) ;
74+
75+ // Auto-submit when debounced pin is complete
76+ useEffect ( ( ) => {
77+ if ( debouncedPin . length === 5 && ! confirmEmailMutation . isPending ) {
78+ handleSubmit ( { pin : debouncedPin } ) ;
79+ }
80+ } , [ debouncedPin ] ) ;
81+
7182 useEffect ( ( ) => {
7283 if ( resendCooldown > 0 ) {
7384 const timer = setTimeout ( ( ) => setResendCooldown ( resendCooldown - 1 ) , 1000 ) ;
@@ -83,9 +94,13 @@ const ConfirmVerificationPin = ({progressInfo}: {
8394 onSuccess : ( ) => {
8495 showSuccess ( t `Email verified successfully!` ) ;
8596 form . reset ( ) ;
97+ setCompletedPin ( '' ) ;
8698 } ,
8799 onError : ( error ) => {
88100 showError ( error . response ?. data ?. message || t `Failed to verify email` ) ;
101+ // Clear the pin on error so user can try again
102+ form . reset ( ) ;
103+ setCompletedPin ( '' ) ;
89104 }
90105 }
91106 ) ;
@@ -148,9 +163,13 @@ const ConfirmVerificationPin = ({progressInfo}: {
148163 error = { ! ! form . errors . pin }
149164 className = { classes . pinInput }
150165 gap = { isMobile ? 8 : "sm" }
151- onComplete = { ( value ) => {
166+ onChange = { ( value ) => {
152167 form . setFieldValue ( 'pin' , value ) ;
153- handleSubmit ( { pin : value } ) ;
168+ if ( value . length === 5 ) {
169+ setCompletedPin ( value ) ;
170+ } else {
171+ setCompletedPin ( '' ) ;
172+ }
154173 } }
155174 />
156175 </ Center >
0 commit comments