summaryrefslogtreecommitdiff
path: root/src-migrate/common/stores
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-10-30 09:21:30 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-10-30 09:21:30 +0700
commite8c414325a1e32474e740cc6e7dca8396affc5e3 (patch)
treee84feb31cd8619d208b4558c5fcf30becc5337e0 /src-migrate/common/stores
parent1694c12f75ad06c5e40d6f9a66e245c3e683146c (diff)
parentc82110f7d3a2f85de99045fde7b579e369f15b2c (diff)
Merge branch 'refactor/all' into development
Diffstat (limited to 'src-migrate/common/stores')
-rw-r--r--src-migrate/common/stores/useRegisterStore.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts
new file mode 100644
index 00000000..725bbfda
--- /dev/null
+++ b/src-migrate/common/stores/useRegisterStore.ts
@@ -0,0 +1,57 @@
+import { create } from 'zustand';
+import { RegisterProps } from '../types/auth';
+
+type State = {
+ form: RegisterProps;
+ isValid: boolean;
+ isCheckedTNC: boolean;
+ isOpenTNC: boolean;
+ isValidCaptcha: boolean;
+};
+
+type Action = {
+ updateForm: (name: string, value: string) => void;
+ updateValidCaptcha: (value: boolean) => void;
+ toggleCheckTNC: () => void;
+ openTNC: () => void;
+ closeTNC: () => void;
+};
+
+export const useRegisterStore = create<State & Action>((set) => ({
+ form: {
+ company: '',
+ name: '',
+ email: '',
+ password: '',
+ phone: '',
+ },
+ isValid: false,
+ isCheckedTNC: false,
+ isOpenTNC: false,
+ isValidCaptcha: false,
+ updateForm: (name, value) =>
+ set((state) => {
+ const updatedForm = { ...state.form, [name]: value };
+
+ const fieldKeys = Object.keys(
+ updatedForm
+ ) as (keyof typeof updatedForm)[];
+
+ const allFieldsValid = fieldKeys.every((key) => {
+ const value = updatedForm[key];
+
+ if (key === 'company') return true;
+
+ return value !== '';
+ });
+
+ return {
+ form: updatedForm,
+ isValid: allFieldsValid,
+ };
+ }),
+ toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })),
+ openTNC: () => set(() => ({ isOpenTNC: true })),
+ closeTNC: () => set(() => ({ isOpenTNC: false })),
+ updateValidCaptcha: (value) => set(() => ({ isValidCaptcha: value })),
+}));