diff --git a/app/components/app/prescription/list.vue b/app/components/app/prescription/list.vue
index ae5126ca..fbff7b10 100644
--- a/app/components/app/prescription/list.vue
+++ b/app/components/app/prescription/list.vue
@@ -5,7 +5,6 @@ import Nav from '~/components/pub/my-ui/nav-footer/ca-ed-su.vue'
import type { Prescription } from '~/models/prescription';
import PrescriptionItem from '~/components/app/prescription-item/list.vue';
-import { add } from 'date-fns';
interface Props {
data: Prescription[]
diff --git a/app/components/content/prescription/list.vue b/app/components/content/prescription/list.vue
index 844cb04f..68e2069f 100644
--- a/app/components/content/prescription/list.vue
+++ b/app/components/content/prescription/list.vue
@@ -22,6 +22,8 @@ import {
import { getList, getDetail } from '~/services/prescription.service'
import List from '~/components/app/prescription/list.vue'
import type { Prescription } from '~/models/prescription'
+import { submit } from '~/services/prescription.service'
+import type { ToastFn } from '~/handlers/_handler'
const props = defineProps<{
encounter_id: number
@@ -31,6 +33,7 @@ const route = useRoute()
const { setQueryParams } = useQueryParam()
const title = ref('')
+const isSubmitConfirmationOpen = ref(false)
const plainEid = route.params.id
const encounter_id = (plainEid && typeof plainEid == 'string') ? parseInt(plainEid) : 0
@@ -125,13 +128,13 @@ watch([isFormEntryDialogOpen], async () => {
}
})
-function cancel(data: Prescription) {
+function confirmCancel(data: Prescription) {
recId.value = data.id
recItem.value = data
isRecordConfirmationOpen.value = true
}
-function edit(data: Prescription) {
+function goToEdit(data: Prescription) {
setQueryParams({
'mode': 'entry',
'id': data.id.toString()
@@ -139,9 +142,21 @@ function edit(data: Prescription) {
recItem.value = data
}
-function submit(data: Prescription) {
+function confirmSubmit(data: Prescription) {
+ recId.value = data.id
+ recItem.value = data
+ isSubmitConfirmationOpen.value = true
}
+async function handleActionSubmit(id: number, refresh: () => void, toast: ToastFn) {
+ const result = await submit(id)
+ if (result.success) {
+ toast({ title: 'Berhasil', description: 'Resep telah di ajukan', variant: 'default' })
+ setTimeout(refresh, 300)
+ } else {
+ toast({ title: 'Gagal', description: 'Gagal menjalankan perintah', variant: 'destructive' })
+ }
+}
@@ -150,9 +165,9 @@ function submit(data: Prescription) {
v-if="!isLoading.dataListLoading"
:data="data"
:pagination-meta="paginationMeta"
- @cancel="cancel"
- @edit="edit"
- @submit="submit"
+ @cancel="confirmCancel"
+ @edit="goToEdit"
+ @submit="confirmSubmit"
/>
+
+ handleActionSubmit(recId, getMyList, toast)"
+ @cancel=""
+ >
+
diff --git a/app/components/pub/my-ui/confirmation/record-confirmation.vue b/app/components/pub/my-ui/confirmation/record-confirmation.vue
index cff54b2b..b241b2c4 100644
--- a/app/components/pub/my-ui/confirmation/record-confirmation.vue
+++ b/app/components/pub/my-ui/confirmation/record-confirmation.vue
@@ -119,8 +119,9 @@ function handleCancel() {
diff --git a/app/handlers/prescription.handler.ts b/app/handlers/prescription.handler.ts
index 62e1861e..10bea176 100644
--- a/app/handlers/prescription.handler.ts
+++ b/app/handlers/prescription.handler.ts
@@ -1,4 +1,4 @@
-import { createCrudHandler, genCrudHandler } from '~/handlers/_handler'
+import { genCrudHandler } from '~/handlers/_handler'
import { create, update, remove } from '~/services/prescription.service'
export const {
diff --git a/app/services/prescription.service.ts b/app/services/prescription.service.ts
index 150357ab..7bdc9f51 100644
--- a/app/services/prescription.service.ts
+++ b/app/services/prescription.service.ts
@@ -1,4 +1,5 @@
import * as base from './_crud-base'
+import { xfetch } from '~/composables/useXfetch'
const path = '/api/v1/prescription'
const name = 'prescription'
@@ -22,3 +23,16 @@ export function update(id: number | string, data: any) {
export function remove(id: number | string) {
return base.remove(path, id)
}
+
+export async function submit(id: number) {
+ try {
+ const resp = await xfetch(`${path}/${id}/submit`, 'PATCH')
+ const result: any = {}
+ result.success = resp.success
+ result.body = (resp.body as Record) || {}
+ return result
+ } catch (error) {
+ console.error(`Error submitting ${name}:`, error)
+ throw new Error(`Failed to submit ${name}`)
+ }
+}