summaryrefslogtreecommitdiff
path: root/src-migrate/common/stores
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-11-13 06:13:25 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-11-13 06:13:25 +0000
commit69575d143e29eed51fa733238126341ebda280e8 (patch)
treef3f5f251a66fed452241768e900fdd60ae8af87c /src-migrate/common/stores
parentfeea1a2602e22659fe73cb55e31c3d01f57218a4 (diff)
parent5a9210e560ca47d8f4d8c43b06fc93d1d064a6f6 (diff)
Merged in refactor/all (pull request #115)
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.ts26
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 })),