diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-20 15:21:31 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-20 15:21:31 +0700 |
| commit | 1d3f68f4a61bb084938523dea2869087f915bf61 (patch) | |
| tree | 23afa11c1351c27e116a6ae81bc10dd2521e6ea5 /src-migrate/modules/register/stores/useRegisterStore.ts | |
| parent | cf0f7a934bcf256d1daeee98e9f66397fb64b1ee (diff) | |
<iman> update new register
Diffstat (limited to 'src-migrate/modules/register/stores/useRegisterStore.ts')
| -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 })), |
