From 0d821cbe3105684af7a0db5affd228defe66f75f Mon Sep 17 00:00:00 2001 From: Abizrh Date: Thu, 20 Nov 2025 00:13:44 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20chore=20(general-consent):?= =?UTF-8?q?=20adjust=20general=20consent=20list=20and=20form=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/general-consent/list.cfg.ts | 35 ++++++++++++++++--- .../content/general-consent/form.vue | 22 ++++++++++-- .../content/general-consent/list.vue | 33 ++++++++++------- 3 files changed, 71 insertions(+), 19 deletions(-) diff --git a/app/components/app/general-consent/list.cfg.ts b/app/components/app/general-consent/list.cfg.ts index 3e634d44..c2f57c54 100644 --- a/app/components/app/general-consent/list.cfg.ts +++ b/app/components/app/general-consent/list.cfg.ts @@ -18,12 +18,41 @@ export const config: Config = { { label: '' }, ], ], - keys: ['date', 'dstUnit.name', 'dstDoctor.name', 'responsible', 'problem', 'solution', 'action'], + keys: ['date', 'relatives', 'responsible', 'informant', 'witness1', 'witness2', 'action'], delKeyNames: [ { key: 'data', label: 'Tanggal' }, { key: 'dstDoctor.name', label: 'Dokter' }, ], parses: { + date(rec) { + const recX = rec as GeneralConsent + return recX?.createdAt?.substring(0, 10) || '-' + }, + relatives(rec) { + const recX = rec as GeneralConsent + const parsed = JSON.parse(recX?.value || '{}') + return parsed?.relatives?.join(', ') || '-' + }, + responsible(rec) { + const recX = rec as GeneralConsent + const parsed = JSON.parse(recX?.value || '{}') + return parsed?.responsible || '-' + }, + informant(rec) { + const recX = rec as GeneralConsent + const parsed = JSON.parse(recX?.value || '{}') + return parsed?.informant || '-' + }, + witness1(rec) { + const recX = rec as GeneralConsent + const parsed = JSON.parse(recX?.value || '{}') + return parsed?.witness1 || '-' + }, + witness2(rec) { + const recX = rec as GeneralConsent + const parsed = JSON.parse(recX?.value || '{}') + return parsed?.witness2 || '-' + }, action(rec, idx) { const res: RecComponent = { idx, @@ -35,10 +64,6 @@ export const config: Config = { } return res }, - date(rec) { - const recX = rec as GeneralConsent - return recX.date?.substring(0, 10) || '-' - }, }, components: { action(rec, idx) { diff --git a/app/components/content/general-consent/form.vue b/app/components/content/general-consent/form.vue index d9b67fec..8c15ceb0 100644 --- a/app/components/content/general-consent/form.vue +++ b/app/components/content/general-consent/form.vue @@ -8,6 +8,8 @@ import { GeneralConsentSchema } from '~/schemas/general-consent.schema' import { toast } from '~/components/pub/ui/toast' import { handleActionSave, handleActionEdit } from '~/handlers/general-consent.handler' import { create } from '~/services/generate-file.service' +// Services +import { getDetail } from '~/services/general-consent.service' const { backToList } = useQueryMode('mode') const route = useRoute() @@ -57,10 +59,26 @@ async function getProcedures() { } onMounted(() => { - getProcedures() - getDiagnoses() + const mode = route.query.mode + const recordId = route.query['record-id'] + + if (mode === 'entry' && recordId) { + loadEntryForEdit(+recordId) + } }) +// TODO: mapping data detail when edit +const loadEntryForEdit = async (id: number) => { + const result = await getDetail(id) + + if (result?.success) { + const data = result.body?.data || {} + + console.log('Mapping data:', data) + // Set state utk form + } +} + function handleClick(type: string) { if (type === 'prosedur') { isOpenProcedure.value = true diff --git a/app/components/content/general-consent/list.vue b/app/components/content/general-consent/list.vue index 588ff849..caba7f7c 100644 --- a/app/components/content/general-consent/list.vue +++ b/app/components/content/general-consent/list.vue @@ -28,7 +28,7 @@ import { handleActionEdit, handleActionRemove, handleCancelForm, -} from '~/handlers/consultation.handler' +} from '~/handlers/general-consent.handler' // Services import { getList, getDetail } from '~/services/general-consent.service' @@ -42,8 +42,9 @@ interface Props { } const props = defineProps() const emits = defineEmits(['add', 'edit']) +const router = useRouter() +const route = useRoute() -const { recordId } = useQueryCRUDRecordId() const { goToEntry, backToList } = useQueryCRUDMode('mode') let units = ref<{ value: string; label: string }[]>([]) @@ -93,6 +94,17 @@ const headerPrep: HeaderPrep = { }, } +const goEdit = (id: string) => { + router.replace({ + path: route.path, + query: { + ...route.query, + mode: 'entry', + 'record-id': id, + }, + }) +} + const today = new Date() provide('rec_id', recId) @@ -110,16 +122,13 @@ const getMyDetail = async (id: number | string) => { } // Watch for row actions when recId or recAction changes -watch([recId, recAction], () => { - switch (recAction.value) { - case ActionEvents.showDetail: - getMyDetail(recId.value) - title.value = 'Detail Konsultasi' - isReadonly.value = true - break - case ActionEvents.showConfirmDelete: - isRecordConfirmationOpen.value = true - break +watch(recId, () => { + console.log('recId', recId.value) + if (recAction.value === ActionEvents.showEdit) { + goEdit(recId.value) + return + } else { + isRecordConfirmationOpen.value = true } })