feat/prescription: added submit
This commit is contained in:
@@ -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[]
|
||||
|
||||
@@ -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' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -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"
|
||||
/>
|
||||
|
||||
<RecordConfirmation
|
||||
@@ -163,4 +178,16 @@ function submit(data: Prescription) {
|
||||
@cancel=""
|
||||
>
|
||||
</RecordConfirmation>
|
||||
|
||||
<RecordConfirmation
|
||||
v-model:open="isSubmitConfirmationOpen"
|
||||
action="delete"
|
||||
customTitle="Ajukan Resep"
|
||||
customMessage="Proses akan mengajukan resep ini untuk diproses lebih lanjut. Lanjutkan?"
|
||||
customConfirmText="Ajukan"
|
||||
:record="recItem"
|
||||
@confirm="() => handleActionSubmit(recId, getMyList, toast)"
|
||||
@cancel=""
|
||||
>
|
||||
</RecordConfirmation>
|
||||
</template>
|
||||
|
||||
@@ -119,8 +119,9 @@ function handleCancel() {
|
||||
|
||||
<template>
|
||||
<Confirmation
|
||||
v-model:open="isOpen" :title="finalTitle" :message="finalMessage" :confirm-text="finalConfirmText"
|
||||
:cancel-text="finalCancelText" :variant="actionConfig.variant" size="md" @confirm="handleConfirm"
|
||||
v-model:open="isOpen" :title="finalTitle" :message="finalMessage" :confirm-text="finalConfirmText"
|
||||
:cancel-text="finalCancelText" :variant="actionConfig.variant" size="md"
|
||||
@confirm="handleConfirm"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<!-- Slot untuk informasi tambahan record -->
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<string, any>) || {}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error(`Error submitting ${name}:`, error)
|
||||
throw new Error(`Failed to submit ${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user