🐛 fix (general-consent): fix mapping data from api

This commit is contained in:
Abizrh
2025-11-20 00:35:25 +07:00
parent 0d821cbe31
commit f1307980ff
3 changed files with 22 additions and 6 deletions
@@ -10,7 +10,8 @@ import { handleActionSave, handleActionEdit } from '~/handlers/general-consent.h
import { create } from '~/services/generate-file.service'
// Services
import { getDetail } from '~/services/general-consent.service'
const { backToList } = useQueryMode('mode')
const { backToList } = useQueryCRUDMode('mode')
const { recordId } = useQueryCRUDRecordId('record-id')
const route = useRoute()
const isOpenProcedure = ref(false)
@@ -74,8 +75,15 @@ const loadEntryForEdit = async (id: number) => {
if (result?.success) {
const data = result.body?.data || {}
console.log('Mapping data:', data)
// Set state utk form
const value = JSON.parse(data.value || '{}')
console.log('Mapping data:', value)
model.value.witness1 = value?.witness1 || ''
model.value.witness2 = value?.witness2 || ''
model.value.informant = value?.informant || ''
model.value.responsibleName = value?.responsible || ''
model.value.responsiblePhone = value?.responsiblePhone || ''
model.value.relatives = value?.relatives || []
console.log('model', model.value)
}
}
@@ -95,7 +103,6 @@ async function actionHandler(type: string) {
return
}
if (type === 'print') {
console.log('print')
isOpenDiagnose.value = true
return
}
@@ -89,7 +89,6 @@ const headerPrep: HeaderPrep = {
icon: 'i-lucide-plus',
onClick: () => {
goToEntry()
emits('add')
},
},
}
+11 -1
View File
@@ -19,7 +19,17 @@ export function useQueryCRUDMode(key: string = 'mode') {
})
const goToEntry = () => (mode.value = 'entry')
const backToList = () =>(mode.value = 'list')
const backToList = () => {
router.push({
path: route.path,
query: {
...route.query,
mode: 'list',
// HAPUS record-id
'record-id': undefined,
},
})
}
return { mode, goToEntry, backToList }
}