summaryrefslogtreecommitdiff
path: root/src-migrate
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-18 17:08:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-18 17:08:55 +0700
commit548e2b48b1c2f6521037765f96083a8d79f611d6 (patch)
treeb2b1d8d924ec973d683e8fb0157b302bc7b037de /src-migrate
parent87ffd2fa7edc240693ddd81401ef23c5cd1bbb3e (diff)
<iman> add pengiriman section
Diffstat (limited to 'src-migrate')
-rw-r--r--src-migrate/modules/register/stores/usePengajuanTempoStore.ts71
-rw-r--r--src-migrate/types/tempo.ts13
-rw-r--r--src-migrate/validations/tempo.ts9
3 files changed, 90 insertions, 3 deletions
diff --git a/src-migrate/modules/register/stores/usePengajuanTempoStore.ts b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
index 7f1bcbb0..0d397c78 100644
--- a/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
+++ b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts
@@ -1,6 +1,14 @@
import { create } from 'zustand';
-import { TempoProps, TempoPropsKontakPerson } from '~/types/tempo';
-import { TempoSchema, TempoSchemaKontakPerson } from '~/validations/tempo';
+import {
+ TempoProps,
+ TempoPropsKontakPerson,
+ TempoPropsPengiriman,
+} from '~/types/tempo';
+import {
+ TempoSchema,
+ TempoSchemaKontakPerson,
+ TempoSchemaPengiriman,
+} from '~/validations/tempo';
import { boolean, ZodError } from 'zod';
type State = {
@@ -156,3 +164,62 @@ export const usePengajuanTempoStoreKontakPerson = create<
},
}),
}));
+
+type StatePengiriman = {
+ formPengiriman: TempoPropsPengiriman;
+ errorsPengiriman: {
+ [key in keyof TempoPropsPengiriman]?: string;
+ };
+};
+type ActionPengiriman = {
+ updateFormPengiriman: (name: string, value: string) => void;
+
+ validatePengiriman: () => void;
+ resetFormPengiriman: () => void;
+};
+export const usePengajuanTempoStorePengiriman = create<
+ StatePengiriman & ActionPengiriman
+>((set, get) => ({
+ formPengiriman: {
+ PICName: '',
+ streetPengiriman: '',
+ statePengiriman: '',
+ cityPengiriman: '',
+ zip: '',
+ invoicePic: '',
+ },
+ updateFormPengiriman: (name, value) =>
+ set((state) => ({
+ formPengiriman: { ...state.formPengiriman, [name]: value },
+ })),
+
+ errorsPengiriman: {},
+ validatePengiriman: () => {
+ try {
+ TempoSchemaPengiriman.parse(get().formPengiriman);
+ set({ errorsPengiriman: {} });
+ } catch (error) {
+ if (error instanceof ZodError) {
+ const errorsPengiriman: StatePengiriman['errorsPengiriman'] = {};
+ error.errors.forEach(
+ (e) =>
+ (errorsPengiriman[e.path[0] as keyof TempoPropsPengiriman] =
+ e.message)
+ );
+ set({ errorsPengiriman });
+ }
+ }
+ },
+
+ resetFormPengiriman: () =>
+ set({
+ formPengiriman: {
+ PICName: '',
+ streetPengiriman: '',
+ statePengiriman: '',
+ cityPengiriman: '',
+ zip: '',
+ invoicePic: '',
+ },
+ }),
+}));
diff --git a/src-migrate/types/tempo.ts b/src-migrate/types/tempo.ts
index 85680cba..6e3f2502 100644
--- a/src-migrate/types/tempo.ts
+++ b/src-migrate/types/tempo.ts
@@ -1,4 +1,8 @@
-import { TempoSchema, TempoSchemaKontakPerson } from '~/validations/tempo';
+import {
+ TempoSchema,
+ TempoSchemaKontakPerson,
+ TempoSchemaPengiriman,
+} from '~/validations/tempo';
import { OdooApiRes } from './odoo';
import { z } from 'zod';
@@ -29,11 +33,18 @@ export type tempoPropsKontakPerson = {
financeName: string;
purchasingMobile: string;
};
+export type tempoPropsPengiriman = {
+ PICName: string;
+ streetPengiriman: string;
+ statePengiriman: string;
+ cityPengiriman: string;
+};
export type TempoApiProps = OdooApiRes<TempoProps>;
export type TempoProps = z.infer<typeof TempoSchema>;
export type TempoPropsKontakPerson = z.infer<typeof TempoSchemaKontakPerson>;
+export type TempoPropsPengiriman = z.infer<typeof TempoSchemaPengiriman>;
export type TempoResApiProps = {
Tempo: boolean;
diff --git a/src-migrate/validations/tempo.ts b/src-migrate/validations/tempo.ts
index 756bb722..7adfa780 100644
--- a/src-migrate/validations/tempo.ts
+++ b/src-migrate/validations/tempo.ts
@@ -26,6 +26,7 @@ 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' }),
financeName: z.string().min(1, { message: 'Nama harus diisi' }),
@@ -61,3 +62,11 @@ export const TempoSchemaKontakPerson = z.object({
.email({ message: 'Email harus menggunakan format example@mail.com' }),
purchasingName: z.string().min(1, { message: 'Nama harus diisi' }),
});
+export const TempoSchemaPengiriman = z.object({
+ PICName: z.string().min(1, { message: 'Nama harus diisi' }),
+ streetPengiriman: z.string().min(1, { message: 'Alamat harus diisi' }),
+ statePengiriman: z.string().min(1, { message: 'Provinsi harus dipilih' }),
+ cityPengiriman: z.string().min(1, { message: 'Kota harus dipilih' }),
+ zip: z.string().min(1, { message: 'Kode pos harus diisi' }),
+ invoicePic: z.string().min(1, { message: 'Nama pic invoice harus diisi' }),
+});