summaryrefslogtreecommitdiff
path: root/src-migrate/common/stores/useRegisterStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src-migrate/common/stores/useRegisterStore.ts')
-rw-r--r--src-migrate/common/stores/useRegisterStore.ts45
1 files changed, 10 insertions, 35 deletions
diff --git a/src-migrate/common/stores/useRegisterStore.ts b/src-migrate/common/stores/useRegisterStore.ts
index d6c7db2a..ab2d7410 100644
--- a/src-migrate/common/stores/useRegisterStore.ts
+++ b/src-migrate/common/stores/useRegisterStore.ts
@@ -8,7 +8,6 @@ type State = {
errors: {
[key in keyof RegisterProps]?: string;
};
- isValid: boolean;
isCheckedTNC: boolean;
isOpenTNC: boolean;
isValidCaptcha: boolean;
@@ -31,53 +30,29 @@ export const useRegisterStore = create<State & Action>((set, get) => ({
password: '',
phone: '',
},
+ updateForm: (name, value) =>
+ set((state) => ({ form: { ...state.form, [name]: value } })),
+
errors: {},
validate: () =>
registerSchema
.validate(get().form, { abortEarly: false })
- .then(() => {
- set({
- errors: {},
- isValid: false,
- });
- })
+ .then(() => set({ errors: {} }))
.catch((err: ValidationError) => {
const validationErrors: State['errors'] = {};
err.inner.forEach(
(e) => (validationErrors[e.path as keyof RegisterProps] = e.message)
);
- set({
- errors: validationErrors,
- isValid: false,
- });
+ set({ errors: validationErrors });
}),
- 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,
- };
- }),
+ 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 })),
}));