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((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 })), }));