summaryrefslogtreecommitdiff
path: root/src-migrate
diff options
context:
space:
mode:
Diffstat (limited to 'src-migrate')
-rw-r--r--src-migrate/modules/register/stores/usePengajuanTempoStore.ts86
-rw-r--r--src-migrate/types/tempo.ts20
-rw-r--r--src-migrate/validations/tempo.ts30
3 files changed, 133 insertions, 3 deletions
diff --git a/src-migrate/modules/register/stores/usePengajuanTempoStore.ts b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
index 6f3bc13d..8891e6ea 100644
--- a/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
+++ b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
@@ -1,6 +1,6 @@
import { create } from 'zustand';
-import { TempoProps } from '~/types/tempo';
-import { TempoSchema } from '~/validations/tempo';
+import { TempoProps, TempoPropsKontakPerson } from '~/types/tempo';
+import { TempoSchema, TempoSchemaKontakPerson } from '~/validations/tempo';
import { boolean, ZodError } from 'zod';
type State = {
@@ -91,3 +91,85 @@ export const usePengajuanTempoStore = create<State & Action>((set, get) => ({
},
}),
}));
+
+type StateKontakPerson = {
+ form: TempoPropsKontakPerson;
+ errors: {
+ [key in keyof TempoPropsKontakPerson]?: string;
+ };
+ isCheckedTNC: boolean;
+ isOpenTNC: boolean;
+ isValidCaptcha: boolean;
+};
+export const usePengajuanTempoStoreKontakPerson = create<
+ StateKontakPerson & Action
+>((set, get) => ({
+ form: {
+ direkturName: '',
+ direkturMobile: '',
+ direkturEmail: '',
+ industry_id: '',
+ street: '',
+ state: '',
+ city: '',
+ zip: '',
+ bankName: '',
+ accountName: '',
+ accountNumber: '',
+ estimasi: '',
+ tempoDuration: '',
+ bersedia: '',
+ categoryProduk: '',
+ tempoLimit: '',
+ },
+ updateForm: (name, value) =>
+ set((state) => ({ form: { ...state.form, [name]: value } })),
+
+ errors: {},
+ validate: () => {
+ try {
+ TempoSchemaKontakPerson.parse(get().form);
+ set({ errors: {} });
+ } catch (error) {
+ if (error instanceof ZodError) {
+ const errors: StateKontakPerson['errors'] = {};
+ error.errors.forEach(
+ (e) => (errors[e.path[0] as keyof TempoPropsKontakPerson] = 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 })),
+
+ resetForm: () =>
+ set({
+ form: {
+ direkturName: '',
+ direkturMobile: '',
+ direkturEmail: '',
+ industry_id: '',
+ street: '',
+ state: '',
+ city: '',
+ zip: '',
+ bankName: '',
+ accountName: '',
+ accountNumber: '',
+ estimasi: '',
+ tempoDuration: '',
+ bersedia: '',
+ categoryProduk: '',
+ tempoLimit: '',
+ },
+ }),
+}));
diff --git a/src-migrate/types/tempo.ts b/src-migrate/types/tempo.ts
index f8a3c5b8..a4bd3d0a 100644
--- a/src-migrate/types/tempo.ts
+++ b/src-migrate/types/tempo.ts
@@ -1,4 +1,4 @@
-import { TempoSchema } from '~/validations/tempo';
+import { TempoSchema, TempoSchemaKontakPerson } from '~/validations/tempo';
import { OdooApiRes } from './odoo';
import { z } from 'zod';
@@ -18,9 +18,27 @@ export type tempoProps = {
bersedia: string;
};
+export type tempoPropsKontakPerson = {
+ direkturName: string;
+ direkturMobile: string;
+ direkturEmail: string;
+ industry_id: string;
+ street: string;
+ state: string;
+ city: string;
+ zip: string;
+ bankName: string;
+ accountName: string;
+ accountNumber: string;
+ estimasi: string;
+ tempoDuration: string;
+ bersedia: string;
+};
+
export type TempoApiProps = OdooApiRes<TempoProps>;
export type TempoProps = z.infer<typeof TempoSchema>;
+export type TempoPropsKontakPerson = z.infer<typeof TempoSchemaKontakPerson>;
export type TempoResApiProps = {
Tempo: boolean;
diff --git a/src-migrate/validations/tempo.ts b/src-migrate/validations/tempo.ts
index 6999c1c6..dca60869 100644
--- a/src-migrate/validations/tempo.ts
+++ b/src-migrate/validations/tempo.ts
@@ -26,3 +26,33 @@ export const TempoSchema = z.object({
.string()
.min(1, { message: 'Category produk harus dipilih' }),
});
+export const TempoSchemaKontakPerson = z.object({
+ direkturName: z.string().min(1, { message: 'Nama harus diisi' }),
+ direkturMobile: z
+ .string()
+ .min(1, { message: 'Nomor telepon harus diisi' })
+ .refine((val) => /^\d{10,12}$/.test(val), {
+ message: 'Format nomor telepon tidak valid, contoh: 081234567890',
+ }),
+ direkturEmail: z
+ .string()
+ .min(1, { message: 'Email harus diisi' })
+ .email({ message: 'Email harus menggunakan format example@mail.com' }),
+ street: z.string().min(1, { message: 'Alamat harus diisi' }),
+ industry_id: z.string().min(1, { message: 'Jenis usaha harus dipilih' }),
+ zip: z.string().min(1, { message: 'Kode pos harus diisi' }),
+ state: z.string().min(1, { message: 'Provinsi harus dipilih' }),
+ city: z.string().min(1, { message: 'Kota harus dipilih' }),
+ bankName: z.string().min(1, { message: 'Nama bank harus diisi' }),
+ accountName: z.string().min(1, { message: 'Nama rekening harus diisi' }),
+ accountNumber: z.string().min(1, { message: 'Nomor rekening harus diisi' }),
+ estimasi: z
+ .string()
+ .min(1, { message: 'Estimasi pemmbelian pertahun harus diisi' }),
+ tempoDuration: z.string().min(1, { message: 'Durasi tempo harus dipilih' }),
+ tempoLimit: z.string().min(1, { message: 'Limit tempo harus dipilih' }),
+ bersedia: z.string().min(1, { message: 'Harus dipilih' }),
+ categoryProduk: z
+ .string()
+ .min(1, { message: 'Category produk harus dipilih' }),
+});