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
This commit is contained in:
Khafid Prayoga
2025-11-24 16:06:24 +07:00
parent f3474eb0b5
commit 32654b0b11
2 changed files with 154 additions and 119 deletions
+57 -34
View File
@@ -135,49 +135,72 @@ async function composeFormData(): Promise<Patient> {
// #region Utilities & event handlers
async function handleActionClick(eventType: string) {
if (eventType === 'submit') {
const patient: Patient = await composeFormData()
let createdPatientId = 0
try {
if (eventType === 'submit') {
const patient: Patient = await composeFormData()
let createdPatientId = 0
const response = await handleActionSave(
patient,
() => {},
() => {},
toast,
)
const response = await handleActionSave(
patient,
() => {},
() => {},
toast,
)
const data = (response?.body?.data ?? null) as PatientBase | null
if (!data) return
createdPatientId = data.id
const data = (response?.body?.data ?? null) as PatientBase | null
if (!data) return
createdPatientId = data.id
if (residentIdentityFile.value) {
void uploadAttachment(residentIdentityFile.value, createdPatientId, 'ktp')
}
if (familyCardFile.value) {
void uploadAttachment(familyCardFile.value, createdPatientId, 'kk')
}
if (residentIdentityFile.value) {
void uploadAttachment(residentIdentityFile.value, createdPatientId, 'ktp')
}
if (familyCardFile.value) {
void uploadAttachment(familyCardFile.value, createdPatientId, 'kk')
}
// If has callback provided redirect to callback with patientData
if (props.callbackUrl) {
await navigateTo(props.callbackUrl + '?patient-id=' + patient.id)
// If has callback provided redirect to callback with patientData
if (props.callbackUrl && props.callbackUrl.length > 0) {
await navigateTo(props.callbackUrl + '?patient-id=' + createdPatientId)
return
}
// Navigate to patient list or show success message
await navigateTo('/client/patient')
return
}
// Navigate to patient list or show success message
await navigateTo('/client/patient')
return
}
if (eventType === 'cancel') {
if (props.callbackUrl) {
await navigateTo(props.callbackUrl)
return
}
if (eventType === 'cancel') {
if (props.callbackUrl) {
await navigateTo(props.callbackUrl)
return
await navigateTo({
name: 'client-patient',
})
// handleCancelForm()
}
} catch (error) {
// Show error toast to user
if (typeof error === 'string') {
toast({
title: 'Error',
description: error,
variant: 'destructive',
})
} else if (error instanceof Error) {
toast({
title: 'Error',
description: error.message || 'Terjadi kesalahan saat menyimpan data',
variant: 'destructive',
})
} else {
toast({
title: 'Error',
description: 'Terjadi kesalahan saat menyimpan data',
variant: 'destructive',
})
}
await navigateTo({
name: 'client-patient',
})
// handleCancelForm()
}
}
// #endregion