From 90710579ba1c12060877f6ec2d26103f9c31058d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 23 Oct 2023 17:11:33 +0700 Subject: Refactor and migrate register page --- src-migrate/common/stores/useRegisterStore.ts | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src-migrate/common/stores/useRegisterStore.ts (limited to 'src-migrate/common/stores') diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts new file mode 100644 index 00000000..fcd2cd8b --- /dev/null +++ b/src-migrate/common/stores/useRegisterStore.ts @@ -0,0 +1,52 @@ +import { create } from 'zustand'; +import { RegisterProps } from '../types/auth'; + +type State = { + form: RegisterProps; + isValid: boolean; + isCheckedTNC: boolean; + isOpenTNC: boolean; +}; + +type Action = { + updateForm: (name: string, value: string) => void; + toggleCheckTNC: () => void; + openTNC: () => void; + closeTNC: () => void; +}; + +export const useRegisterStore = create((set) => ({ + form: { + company: '', + name: '', + email: '', + password: '', + }, + isValid: false, + isCheckedTNC: false, + isOpenTNC: 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 })), +})); -- cgit v1.2.3 From cf6da809621b4ebe8c9acedb035b689e7e1b60b1 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 25 Oct 2023 17:27:32 +0700 Subject: Update register page --- src-migrate/common/stores/useRegisterStore.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src-migrate/common/stores') diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts index fcd2cd8b..725bbfda 100644 --- a/src-migrate/common/stores/useRegisterStore.ts +++ b/src-migrate/common/stores/useRegisterStore.ts @@ -6,10 +6,12 @@ type State = { 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; @@ -21,10 +23,12 @@ export const useRegisterStore = create((set) => ({ name: '', email: '', password: '', + phone: '', }, isValid: false, isCheckedTNC: false, isOpenTNC: false, + isValidCaptcha: false, updateForm: (name, value) => set((state) => { const updatedForm = { ...state.form, [name]: value }; @@ -49,4 +53,5 @@ export const useRegisterStore = create((set) => ({ toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })), openTNC: () => set(() => ({ isOpenTNC: true })), closeTNC: () => set(() => ({ isOpenTNC: false })), + updateValidCaptcha: (value) => set(() => ({ isValidCaptcha: value })), })); -- cgit v1.2.3