summaryrefslogtreecommitdiff
path: root/src-migrate/common/stores/useRegisterStore.ts
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-01-13 10:35:22 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-01-13 10:35:22 +0700
commitf62b2345f463695ef0f8f79830cd76b6e0332821 (patch)
treec06ff12a8312e3a02b0203f588db0f4da044c911 /src-migrate/common/stores/useRegisterStore.ts
parentee0b5893ac039ab05fe8247647364a923d707da3 (diff)
Refactor src migrate folder
Diffstat (limited to 'src-migrate/common/stores/useRegisterStore.ts')
-rw-r--r--src-migrate/common/stores/useRegisterStore.ts60
1 files changed, 0 insertions, 60 deletions
diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts
deleted file mode 100644
index 90ce8a2b..00000000
--- a/src-migrate/common/stores/useRegisterStore.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import { create } from 'zustand';
-import { RegisterProps } from '../types/auth';
-import { registerSchema } from '../validations/auth';
-import { ZodError } from 'zod';
-
-type State = {
- form: RegisterProps;
- errors: {
- [key in keyof RegisterProps]?: string;
- };
- isCheckedTNC: boolean;
- isOpenTNC: boolean;
- isValidCaptcha: boolean;
-};
-
-type Action = {
- updateForm: (name: string, value: string) => void;
- updateValidCaptcha: (value: boolean) => void;
- toggleCheckTNC: () => void;
- openTNC: () => void;
- closeTNC: () => void;
- validate: () => void;
-};
-
-export const useRegisterStore = create<State & Action>((set, get) => ({
- form: {
- company: '',
- name: '',
- email: '',
- password: '',
- phone: '',
- },
- updateForm: (name, value) =>
- set((state) => ({ form: { ...state.form, [name]: value } })),
-
- errors: {},
- 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 });
- }
- }
- },
- isCheckedTNC: false,
- toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })),
-
- isOpenTNC: false,
- openTNC: () => set(() => ({ isOpenTNC: true })),
- closeTNC: () => set(() => ({ isOpenTNC: false })),
-
- isValidCaptcha: false,
- updateValidCaptcha: (value) => set(() => ({ isValidCaptcha: value })),
-}));