From 6a29fdfd5047939f3e50e01113c01e3da84b8093 Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Tue, 25 Nov 2025 20:46:04 +0700 Subject: [PATCH] refactor(glob:form): update form handling and type definitions - Migrate from Form component to vee-validate useForm - Update combobox component to support number values - Modify base model ID type for mock data - Improve type safety in treatment report schema - Add proper form submission handling --- .../app/doctor/fields/select-doctor.vue | 2 +- .../app/treatment-report/entry-form.vue | 81 +++++++++++++------ .../content/treatment-report/add.vue | 8 ++ .../pub/my-ui/combobox/combobox.vue | 6 +- app/components/pub/my-ui/combobox/index.ts | 8 +- app/models/_base.ts | 5 +- app/schemas/treatment-report.schema.ts | 16 +++- 7 files changed, 86 insertions(+), 40 deletions(-) diff --git a/app/components/app/doctor/fields/select-doctor.vue b/app/components/app/doctor/fields/select-doctor.vue index daa55062..8921350c 100644 --- a/app/components/app/doctor/fields/select-doctor.vue +++ b/app/components/app/doctor/fields/select-doctor.vue @@ -27,7 +27,7 @@ const { class: containerClass, labelClass, colSpan = 1, doctors = [] } = props const opts = computed(() => { return doctors.map((doc) => ({ - value: doc.id.toString(), + value: doc.id, label: parseName(doc.employee.person as Person), })) }) diff --git a/app/components/app/treatment-report/entry-form.vue b/app/components/app/treatment-report/entry-form.vue index 8cc7db1a..77367f97 100644 --- a/app/components/app/treatment-report/entry-form.vue +++ b/app/components/app/treatment-report/entry-form.vue @@ -1,7 +1,10 @@ diff --git a/app/components/content/treatment-report/add.vue b/app/components/content/treatment-report/add.vue index 6789238e..e92cd473 100644 --- a/app/components/content/treatment-report/add.vue +++ b/app/components/content/treatment-report/add.vue @@ -4,6 +4,7 @@ import { genDoctor, type Doctor } from '~/models/doctor' // components import AppTreatmentReportEntry from '~/components/app/treatment-report/entry-form.vue' +import type { TreatmentReportFormData } from '~/schemas/treatment-report.schema' const doctors = ref([]) @@ -17,5 +18,12 @@ const doctors = ref([]) diff --git a/app/components/pub/my-ui/combobox/combobox.vue b/app/components/pub/my-ui/combobox/combobox.vue index 713edd57..de544717 100644 --- a/app/components/pub/my-ui/combobox/combobox.vue +++ b/app/components/pub/my-ui/combobox/combobox.vue @@ -5,7 +5,7 @@ import { type Item } from './index' const props = defineProps<{ id?: string - modelValue?: string + modelValue?: string | number items: Item[] placeholder?: string searchPlaceholder?: string @@ -15,8 +15,8 @@ const props = defineProps<{ }>() const emit = defineEmits<{ - 'update:modelValue': [value: string] - 'update:searchText': [value: string] + 'update:modelValue': [value: string | number] + 'update:searchText': [value: string | number] }>() const open = ref(false) diff --git a/app/components/pub/my-ui/combobox/index.ts b/app/components/pub/my-ui/combobox/index.ts index e4864f7f..f3038de7 100644 --- a/app/components/pub/my-ui/combobox/index.ts +++ b/app/components/pub/my-ui/combobox/index.ts @@ -1,5 +1,5 @@ export interface Item { - value: string + value: string | number label: string code?: string priority?: number @@ -7,12 +7,12 @@ export interface Item { export function recStrToItem(input: Record): Item[] { const items: Item[] = [] - let idx = 0; + let idx = 0 for (const key in input) { if (input.hasOwnProperty(key)) { items.push({ - value: key || ('unknown-' + idx), - label: input[key] || ('unknown-' + idx), + value: key || 'unknown-' + idx, + label: input[key] || 'unknown-' + idx, }) } idx++ diff --git a/app/models/_base.ts b/app/models/_base.ts index 6aaa99fc..ed6f7204 100644 --- a/app/models/_base.ts +++ b/app/models/_base.ts @@ -1,4 +1,3 @@ - export interface Base { id: number createdAt: string | null @@ -20,7 +19,9 @@ export interface TreeItem { export function genBase(): Base { return { - id: 0, + // -1 buat mock data + // backend harusnya non-negative/ > 0 (untuk auto increment constraint) jadi harusnya aman ya + id: -1, createdAt: '', updatedAt: '', } diff --git a/app/schemas/treatment-report.schema.ts b/app/schemas/treatment-report.schema.ts index 5bb247d0..eeb1c889 100644 --- a/app/schemas/treatment-report.schema.ts +++ b/app/schemas/treatment-report.schema.ts @@ -4,10 +4,18 @@ const isoDateTime = z.string().min(1, 'Tanggal / waktu wajib diisi') const positiveInt = z.number().int().nonnegative() const OperatorTeamSchema = z.object({ - dpjpId: z.number().int(), - operatorId: z.number().int(), - assistantOperatorId: z.number().int().optional().nullable(), - instrumentNurseId: z.number().int().optional().nullable(), + dpjpId: z.coerce + .number({ + invalid_type_error: 'Dokter Pemeriksa wajib diisi', + }) + .int(), + operatorId: z.coerce + .number({ + invalid_type_error: 'Operator wajib diisi', + }) + .int(), + assistantOperatorId: z.coerce.number().int().optional().nullable(), + instrumentNurseId: z.coerce.number().int().optional().nullable(), surgeryDate: isoDateTime, actionDiagnosis: z.string().min(1),