diff options
Diffstat (limited to 'src-migrate/modules/register/stores')
| -rw-r--r-- | src-migrate/modules/register/stores/useRegisterStore.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src-migrate/modules/register/stores/useRegisterStore.ts b/src-migrate/modules/register/stores/useRegisterStore.ts index 1438ccc2..19a055ae 100644 --- a/src-migrate/modules/register/stores/useRegisterStore.ts +++ b/src-migrate/modules/register/stores/useRegisterStore.ts @@ -5,6 +5,7 @@ import { ZodError } from 'zod'; type State = { form: RegisterProps; + formBisnis: RegisterProps; errors: { [key in keyof RegisterProps]?: string; }; @@ -15,11 +16,13 @@ type State = { type Action = { updateForm: (name: string, value: string) => void; + updateFormBisnis: (name: string, value: string) => void; updateValidCaptcha: (value: boolean) => void; toggleCheckTNC: () => void; openTNC: () => void; closeTNC: () => void; validate: () => void; + validateFormBisnis: () => void; }; export const useRegisterStore = create<State & Action>((set, get) => ({ @@ -31,8 +34,19 @@ export const useRegisterStore = create<State & Action>((set, get) => ({ phone: '', document: File, }, + formBisnis: { + company: '', + name: '', + email: '', + password: '', + phone: '', + document: File, + }, updateForm: (name, value) => set((state) => ({ form: { ...state.form, [name]: value } })), + + updateFormBisnis: (name, value) => + set((state) => ({ formBisnis: { ...state.formBisnis, [name]: value } })), errors: {}, validate: () => { @@ -49,6 +63,22 @@ export const useRegisterStore = create<State & Action>((set, get) => ({ } } }, + + validateFormBisnis: () => { + try { + registerSchema.parse(get().formBisnis); + 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 }); + } + } + }, + isCheckedTNC: false, toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })), |
