diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-10 16:23:33 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-10 16:23:33 +0700 |
| commit | 5a9210e560ca47d8f4d8c43b06fc93d1d064a6f6 (patch) | |
| tree | e5ac9162bd86829dd149278cdf9db70076816200 /src-migrate/common/stores | |
| parent | 4bed066c03dc55a8f811ff2e23e019d8adc64495 (diff) | |
Add close on modal otp activation, change validation register schema, fix term and condition checkbox
Diffstat (limited to 'src-migrate/common/stores')
| -rw-r--r-- | src-migrate/common/stores/useRegisterStore.ts | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts index ab2d7410..90ce8a2b 100644 --- a/src-migrate/common/stores/useRegisterStore.ts +++ b/src-migrate/common/stores/useRegisterStore.ts @@ -1,7 +1,7 @@ import { create } from 'zustand'; import { RegisterProps } from '../types/auth'; import { registerSchema } from '../validations/auth'; -import { ValidationError } from 'yup'; +import { ZodError } from 'zod'; type State = { form: RegisterProps; @@ -34,18 +34,20 @@ export const useRegisterStore = create<State & Action>((set, get) => ({ set((state) => ({ form: { ...state.form, [name]: value } })), errors: {}, - validate: () => - registerSchema - .validate(get().form, { abortEarly: false }) - .then(() => set({ errors: {} })) - .catch((err: ValidationError) => { - const validationErrors: State['errors'] = {}; - err.inner.forEach( - (e) => (validationErrors[e.path as keyof RegisterProps] = e.message) + validate: () => { + try { + registerSchema.parse(get().form); + set({ errors: {} }); + } catch (error) { + if (error instanceof ZodError) { + const errors: State['errors'] = {}; + error.errors.forEach( + (e) => (errors[e.path[0] as keyof RegisterProps] = e.message) ); - set({ errors: validationErrors }); - }), - + set({ errors }); + } + } + }, isCheckedTNC: false, toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })), |
