feat(patient): add patient handler and refactor form submission
- Introduce new patient handler using genCrudHandler for CRUD operations - Refactor patient entry form to use handler for save operations - Separate form data composition from submission logic - Handle file uploads and navigation after successful submission
This commit is contained in:
No files matched your search
@@ -129,23 +129,34 @@ export function genCrudHandler<T = any>(crud: {
|
||||
recItem.value = null
|
||||
}
|
||||
|
||||
async function handleActionSave(values: any, refresh: () => void, reset: () => void, toast: ToastFn) {
|
||||
async function handleActionSave(
|
||||
values: any,
|
||||
refresh: () => void,
|
||||
reset: () => void,
|
||||
toast: ToastFn,
|
||||
): Promise<any | null> {
|
||||
isProcessing.value = true
|
||||
|
||||
let successResponse: any = null
|
||||
|
||||
await handleAsyncAction<[any], any>({
|
||||
action: crud.create,
|
||||
args: [values],
|
||||
toast,
|
||||
successMessage: 'Data berhasil disimpan',
|
||||
errorMessage: 'Gagal menyimpan data',
|
||||
onSuccess: () => {
|
||||
onSuccess: (result) => {
|
||||
isFormEntryDialogOpen.value = false
|
||||
if (refresh) refresh()
|
||||
successResponse = result
|
||||
},
|
||||
onFinally: (isSuccess: boolean) => {
|
||||
if (isSuccess) setTimeout(reset, 500)
|
||||
isProcessing.value = false
|
||||
},
|
||||
})
|
||||
|
||||
return successResponse
|
||||
}
|
||||
|
||||
async function handleActionEdit(
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Handlers
|
||||
import { genCrudHandler } from '~/handlers/_handler'
|
||||
|
||||
// Services
|
||||
import { postPatient as create, patchPatient as update, removePatient as remove } from '~/services/patient.service'
|
||||
|
||||
export const {
|
||||
recId,
|
||||
recAction,
|
||||
recItem,
|
||||
isReadonly,
|
||||
isProcessing,
|
||||
isFormEntryDialogOpen,
|
||||
isRecordConfirmationOpen,
|
||||
onResetState,
|
||||
handleActionSave,
|
||||
handleActionEdit,
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} = genCrudHandler({
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
})
|
||||
Reference in New Issue
Block a user