diff --git a/src/hooks/useBooking.ts b/src/hooks/useBooking.ts index a6a092c..efafab2 100644 --- a/src/hooks/useBooking.ts +++ b/src/hooks/useBooking.ts @@ -55,22 +55,17 @@ export default function useBooking(initialServiceId?: string) { }, []) const submit = useCallback((): boolean => { - let result = false - setState((s) => { - const nextErrors: BookingErrors = {} - if (!s.contact.name.trim()) nextErrors.name = 'Name is required.' - if (!isValidEmail(s.contact.email)) nextErrors.email = 'A valid email is required.' - if (!s.contact.phone.trim()) nextErrors.phone = 'Phone is required.' - setErrors(nextErrors) - if (Object.keys(nextErrors).length > 0) { - result = false - return s - } - result = true - return { ...s, step: 'confirmed' } - }) - return result - }, []) + const nextErrors: BookingErrors = {} + if (!state.contact.name.trim()) nextErrors.name = 'Name is required.' + if (!isValidEmail(state.contact.email)) nextErrors.email = 'A valid email is required.' + if (!state.contact.phone.trim()) nextErrors.phone = 'Phone is required.' + setErrors(nextErrors) + if (Object.keys(nextErrors).length > 0) { + return false + } + setState((s) => ({ ...s, step: 'confirmed' })) + return true + }, [state.contact]) const reset = useCallback(() => { setState(initialState(initialServiceId))