From 32654b0b11fdcb42bb7a25e3fde525a9e3a457f9 Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Mon, 24 Nov 2025 16:06:24 +0700 Subject: [PATCH] wip: ui fix layout fix(patient-form): add error handling in patient submission and simplify family form - Wrap patient submission in try-catch to show appropriate error messages - Simplify family parents form by removing conditional rendering and adding disabled state - Update form fields to use consistent labels and disable when not sharing family data feat(family-form): improve family data form handling and UI - Add edit mode detection to conditionally set default family data - Restructure form fields display based on shareFamilyData value - Show disabled placeholder fields when family data is not shared --- .../app/person/family-parents-form.vue | 182 ++++++++++-------- app/components/content/patient/add.vue | 91 +++++---- 2 files changed, 154 insertions(+), 119 deletions(-) diff --git a/app/components/app/person/family-parents-form.vue b/app/components/app/person/family-parents-form.vue index 04bebecc..8c41a3c8 100644 --- a/app/components/app/person/family-parents-form.vue +++ b/app/components/app/person/family-parents-form.vue @@ -4,6 +4,7 @@ import { toTypedSchema } from '@vee-validate/zod' import { FieldArray } from 'vee-validate' // component +import * as DE from '~/components/pub/my-ui/doc-entry' import { Form } from '~/components/pub/ui/form' import { SelectEducation } from '~/components/app/patient/fields' import { InputBase } from '~/components/pub/my-ui/form' @@ -17,33 +18,45 @@ const props = defineProps<{ const formSchema = toTypedSchema(props.schema) const formRef = ref() +const isFamilyFormDisabled = ref(true) -// Watcher untuk mengatur families ketika shareFamilyData berubah -watch( - () => formRef.value?.values?.shareFamilyData, - (newValue) => { - if (newValue === '1' && formRef.value) { - // Ketika memilih "Ya", pastikan ada data families untuk mother dan father - const currentFamilies = formRef.value.values?.families || [] - if (currentFamilies.length === 0) { - formRef.value.setFieldValue('families', [ - { relation: 'mother', name: undefined, education: undefined, occupation: undefined }, - { relation: 'father', name: undefined, education: undefined, occupation: undefined }, - ]) - } - } else if (newValue === '0' && formRef.value) { - // Ketika memilih "Tidak", kosongkan families - formRef.value.setFieldValue('families', []) - } - }, - { immediate: false }, -) +const isEditing = computed(() => !!props.initialValues?.id) defineExpose({ validate: () => formRef.value?.validate(), resetForm: () => formRef.value?.resetForm(), values: computed(() => formRef.value?.values), }) + +watch( + () => formRef.value?.values?.shareFamilyData, + (newValue) => { + if (!formRef.value) return + + const currentFamilies = formRef.value.values?.families || [] + + if (newValue === '1') { + isFamilyFormDisabled.value = false + + // CREATE MODE — Auto default + if (!isEditing.value && currentFamilies.length === 0) { + formRef.value.setFieldValue('families', [ + { relation: 'mother', name: '', education: '', occupation: '' }, + { relation: 'father', name: '', education: '', occupation: '' }, + ]) + } + + return + } + + isFamilyFormDisabled.value = true + + if (!isEditing.value) { + formRef.value.setFieldValue('families', []) + } + }, + { immediate: true }, +)