Feat: API Integration supporting doc upload

This commit is contained in:
hasyim_kai
2025-11-13 16:16:26 +07:00
parent b2a512314b
commit 56109564cb
19 changed files with 401 additions and 101 deletions

No files matched your search

+33 -21
View File
@@ -2,10 +2,11 @@
import { useRouter } from 'vue-router'
import type { ExposedForm } from '~/types/form'
import Action from '~/components/pub/my-ui/nav-footer/ba-dr-su.vue'
import { handleActionSave,} from '~/handlers/patient.handler'
import { handleActionSave,} from '~/handlers/supporting-document.handler'
import { toast } from '~/components/pub/ui/toast'
import Confirmation from '~/components/pub/my-ui/confirmation/confirmation.vue'
import { DocumentUploadSchema } from '~/schemas/document-upload.schema'
import { getDetail } from '~/services/supporting-document.service'
// #region Props & Emits
const props = defineProps<{
@@ -15,15 +16,26 @@ const props = defineProps<{
// form related state
const route = useRoute()
const encounterId = typeof route.params.id == 'string' ? parseInt(route.params.id) : 0
const docId = typeof route.params.document_id == 'string' ? parseInt(route.params.document_id) : 0
const inputForm = ref<ExposedForm<any> | null>(null)
// #endregion
// #region State & Computed
const router = useRouter()
const isConfirmationOpen = ref(false)
const { user } = useUserStore()
const initialValues = {
officer: user.user_name,
}
// #endregion
// #region Lifecycle Hooks
onMounted(async () => {
const result = await getDetail(docId)
if (result.success) {
inputForm.value?.setValues(result.body.data)
}
})
// #endregion
// #region Functions
@@ -32,40 +44,39 @@ function goBack() {
}
async function handleConfirmAdd() {
const controlLetter = await composeFormData()
let createdControlLetterId = 0
const inputData = await composeFormData()
let createdDataId = 0
const response = await handleActionSave(
controlLetter,
() => { },
() => { },
toast,
)
// const response = await handleActionSave(
// inputData,
// () => { },
// () => { },
// toast,
// )
const data = (response?.body?.data ?? null)
if (!data) return
createdControlLetterId = data.id
// const data = (response?.body?.data ?? null)
// if (!data) return
// createdDataId = data.id
// // If has callback provided redirect to callback with patientData
if (props.callbackUrl) {
navigateTo(props.callbackUrl + '?control-letter-id=' + controlLetter.id)
}
goBack()
// // // If has callback provided redirect to callback with patientData
// if (props.callbackUrl) {
// navigateTo(props.callbackUrl + '?control-letter-id=' + inputData.id)
// }
// goBack()
}
async function composeFormData(): Promise<any> {
const [controlLetter,] = await Promise.all([
const [inputFormState,] = await Promise.all([
inputForm.value?.validate(),
])
const results = [controlLetter]
const results = [inputFormState]
const allValid = results.every((r) => r?.valid)
// exit, if form errors happend during validation
if (!allValid) return Promise.reject('Form validation failed')
const formData = controlLetter?.values
const formData = inputFormState?.values
formData.encounter_id = encounterId
return new Promise((resolve) => resolve(formData))
}
@@ -103,6 +114,7 @@ function handleCancelAdd() {
<AppDocumentUploadEntryForm
ref="inputForm"
:schema="DocumentUploadSchema"
:initial-values="initialValues"
/>
<div class="my-2 flex justify-end py-2">