feat(subspecialist): add subspecialist management components and pages
- Implement list view with pagination and search functionality - Create form for adding subspecialist entries - Add configuration for subspecialist data validation and dropdown options
This commit is contained in:
No files matched your search
@@ -0,0 +1,213 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { FormErrors } from '~/types/error'
|
||||||
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
|
import Combobox from '~/components/pub/custom-ui/form/combobox.vue'
|
||||||
|
import FieldGroup from '~/components/pub/custom-ui/form/field-group.vue'
|
||||||
|
import Field from '~/components/pub/custom-ui/form/field.vue'
|
||||||
|
import Label from '~/components/pub/custom-ui/form/label.vue'
|
||||||
|
|
||||||
|
interface SubSpecialistFormData {
|
||||||
|
name: string
|
||||||
|
code: string
|
||||||
|
installationId: string
|
||||||
|
unitId: string
|
||||||
|
specialistId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
schema: any
|
||||||
|
initialValues?: Partial<SubSpecialistFormData>
|
||||||
|
errors?: FormErrors
|
||||||
|
installation: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
unit: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
specialist: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'submit': [values: SubSpecialistFormData, resetForm: () => void]
|
||||||
|
'cancel': [resetForm: () => void]
|
||||||
|
'installationChanged': [id: string]
|
||||||
|
'unitChanged': [id: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const formSchema = toTypedSchema(props.schema)
|
||||||
|
|
||||||
|
// Form submission handler
|
||||||
|
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) {
|
||||||
|
const formData: SubSpecialistFormData = {
|
||||||
|
name: values.name || '',
|
||||||
|
code: values.code || '',
|
||||||
|
installationId: values.installationId || '',
|
||||||
|
unitId: values.unitId || '',
|
||||||
|
specialistId: values.specialistId || '',
|
||||||
|
}
|
||||||
|
emit('submit', formData, resetForm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form cancel handler
|
||||||
|
function onCancelForm({ resetForm }: { resetForm: () => void }) {
|
||||||
|
emit('cancel', resetForm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watch for installation changes
|
||||||
|
function onInstallationChanged(installationId: string, setFieldValue: any) {
|
||||||
|
setFieldValue('unitId', '', false)
|
||||||
|
setFieldValue('specialistId', '', false)
|
||||||
|
emit('installationChanged', installationId || '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUnitChanged(unitId: string, setFieldValue: any) {
|
||||||
|
setFieldValue('specialistId', '', false)
|
||||||
|
emit('unitChanged', unitId || '')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Form
|
||||||
|
v-slot="{
|
||||||
|
handleSubmit,
|
||||||
|
resetForm,
|
||||||
|
values,
|
||||||
|
setFieldValue,
|
||||||
|
}" as="" keep-values :validation-schema="formSchema"
|
||||||
|
:initial-values="initialValues"
|
||||||
|
>
|
||||||
|
<form id="entry-form" @submit="handleSubmit($event, (values) => onSubmitForm(values, { resetForm }))">
|
||||||
|
<div class="mb-5 border-b border-b-slate-300 pb-3 text-lg xl:text-xl">
|
||||||
|
<div class="flex flex-col justify-between">
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="name">Nama</Label>
|
||||||
|
<Field id="name" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="name">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
id="name" type="text" placeholder="Masukkan nama spesialisasi" autocomplete="off"
|
||||||
|
v-bind="componentField"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="code">Kode</Label>
|
||||||
|
<Field id="code" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="code">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
id="code" type="text" placeholder="Masukkan kode spesialisasi" autocomplete="off"
|
||||||
|
v-bind="componentField"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="installationId">Instalasi</Label>
|
||||||
|
<Field id="installationId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="installationId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="installationId" v-bind="componentField" :items="installation.items"
|
||||||
|
:placeholder="installation.msg.placeholder" :search-placeholder="installation.msg.search"
|
||||||
|
:empty-message="installation.msg.empty"
|
||||||
|
@update:model-value="(value) => onInstallationChanged(value, setFieldValue)"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="unitId">Unit</Label>
|
||||||
|
<Field id="unitId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="unitId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="unitId" :disabled="!values.installationId" v-bind="componentField" :items="unit.items"
|
||||||
|
:placeholder="unit.msg.placeholder" :search-placeholder="unit.msg.search"
|
||||||
|
:empty-message="unit.msg.empty"
|
||||||
|
@update:model-value="(value) => onUnitChanged(value, setFieldValue)"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="specialistId">Specialist</Label>
|
||||||
|
<Field id="specialistId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="specialistId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="specialistId" :disabled="!values.unitId" v-bind="componentField" :items="specialist.items"
|
||||||
|
:placeholder="specialist.msg.placeholder" :search-placeholder="specialist.msg.search"
|
||||||
|
:empty-message="specialist.msg.empty"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-2 mt-4">
|
||||||
|
<Button type="button" variant="outline" @click="onCancelForm({ resetForm })">
|
||||||
|
Batal
|
||||||
|
</Button>
|
||||||
|
<Button type="submit">
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import type {
|
||||||
|
Col,
|
||||||
|
KeyLabel,
|
||||||
|
RecComponent,
|
||||||
|
RecStrFuncComponent,
|
||||||
|
RecStrFuncUnknown,
|
||||||
|
Th,
|
||||||
|
} from '~/components/pub/custom-ui/data/types'
|
||||||
|
import { defineAsyncComponent } from 'vue'
|
||||||
|
|
||||||
|
type SmallDetailDto = any
|
||||||
|
|
||||||
|
const action = defineAsyncComponent(() => import('~/components/pub/custom-ui/data/dropdown-action-ud.vue'))
|
||||||
|
|
||||||
|
export const cols: Col[] = [{ width: 100 }, {}, {}, {}, { width: 50 }]
|
||||||
|
|
||||||
|
export const header: Th[][] = [
|
||||||
|
[{ label: 'Id' }, { label: 'Nama' }, { label: 'Kode' }, { label: 'Specialist' }, { label: '' }],
|
||||||
|
]
|
||||||
|
export const keys = ['id', 'name', 'cellphone', 'religion_code', 'action']
|
||||||
|
|
||||||
|
export const delKeyNames: KeyLabel[] = [
|
||||||
|
{ key: 'code', label: 'Kode' },
|
||||||
|
{ key: 'name', label: 'Nama' },
|
||||||
|
]
|
||||||
|
|
||||||
|
export const funcParsed: RecStrFuncUnknown = {
|
||||||
|
name: (rec: unknown): unknown => {
|
||||||
|
const recX = rec as SmallDetailDto
|
||||||
|
return `${recX.firstName} ${recX.lastName || ''}`.trim()
|
||||||
|
},
|
||||||
|
unit: (rec: unknown): unknown => {
|
||||||
|
const recX = rec as SmallDetailDto
|
||||||
|
return recX.unit?.name || '-'
|
||||||
|
},
|
||||||
|
specialist: (rec: unknown): unknown => {
|
||||||
|
const recX = rec as SmallDetailDto
|
||||||
|
return recX.specialist?.name || '-'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const funcComponent: RecStrFuncComponent = {
|
||||||
|
action(rec, idx) {
|
||||||
|
const res: RecComponent = {
|
||||||
|
idx,
|
||||||
|
rec: rec as object,
|
||||||
|
component: action,
|
||||||
|
props: {
|
||||||
|
size: 'sm',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const funcHtml: RecStrFuncUnknown = {}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { PaginationMeta } from '~/components/pub/custom-ui/pagination/pagination.type'
|
||||||
|
import PaginationView from '~/components/pub/custom-ui/pagination/pagination-view.vue'
|
||||||
|
import { cols, funcComponent, funcHtml, funcParsed, header, keys } from './list-cfg'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
data: any[]
|
||||||
|
paginationMeta: PaginationMeta
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
pageChange: [page: number]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
function handlePageChange(page: number) {
|
||||||
|
emit('pageChange', page)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="space-y-4">
|
||||||
|
<PubBaseDataTable
|
||||||
|
:rows="data" :cols="cols" :header="header" :keys="keys" :func-parsed="funcParsed"
|
||||||
|
:func-html="funcHtml" :func-component="funcComponent" :skeleton-size="paginationMeta?.pageSize"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PaginationView :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
|
|
||||||
export const specialistConf = z.object({
|
export const schemaConf = z.object({
|
||||||
name: z
|
name: z
|
||||||
.string({
|
.string({
|
||||||
required_error: 'Nama spesialisasi harus diisi',
|
required_error: 'Nama spesialisasi harus diisi',
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-c
|
|||||||
import { ActionEvents } from '~/components/pub/custom-ui/data/types'
|
import { ActionEvents } from '~/components/pub/custom-ui/data/types'
|
||||||
import Header from '~/components/pub/custom-ui/nav-header/header.vue'
|
import Header from '~/components/pub/custom-ui/nav-header/header.vue'
|
||||||
import { usePaginatedList } from '~/composables/usePaginatedList'
|
import { usePaginatedList } from '~/composables/usePaginatedList'
|
||||||
import { createFilteredUnitConf, installationConf, specialistConf, unitConf } from './entry'
|
import { createFilteredUnitConf, installationConf, schemaConf, unitConf } from './entry'
|
||||||
|
|
||||||
// #region State & Computed
|
// #region State & Computed
|
||||||
// Dialog state
|
// Dialog state
|
||||||
@@ -210,7 +210,7 @@ watch(recId, () => {
|
|||||||
<AppSpecialistEntryForm
|
<AppSpecialistEntryForm
|
||||||
:installation="installationConf"
|
:installation="installationConf"
|
||||||
:unit="filteredUnitConf"
|
:unit="filteredUnitConf"
|
||||||
:schema="specialistConf"
|
:schema="schemaConf"
|
||||||
:disabled-unit="!selectedInstallationId"
|
:disabled-unit="!selectedInstallationId"
|
||||||
:initial-values="{ name: '', code: '', installationId: '', unitId: '' }"
|
:initial-values="{ name: '', code: '', installationId: '', unitId: '' }"
|
||||||
@submit="onSubmitForm"
|
@submit="onSubmitForm"
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import * as z from 'zod'
|
||||||
|
|
||||||
|
export const schemaConf = z.object({
|
||||||
|
name: z
|
||||||
|
.string({
|
||||||
|
required_error: 'Nama spesialisasi harus diisi',
|
||||||
|
})
|
||||||
|
.min(3, 'Nama spesialisasi minimal 3 karakter'),
|
||||||
|
|
||||||
|
code: z
|
||||||
|
.string({
|
||||||
|
required_error: 'Kode spesialisasi harus diisi',
|
||||||
|
})
|
||||||
|
.min(3, 'Kode spesialisasi minimal 3 karakter'),
|
||||||
|
|
||||||
|
installationId: z
|
||||||
|
.string({
|
||||||
|
required_error: 'Instalasi harus dipilih',
|
||||||
|
})
|
||||||
|
.min(1, 'Instalasi harus dipilih'),
|
||||||
|
|
||||||
|
unitId: z
|
||||||
|
.string({
|
||||||
|
required_error: 'Unit harus dipilih',
|
||||||
|
})
|
||||||
|
.min(1, 'Unit harus dipilih'),
|
||||||
|
specialistId: z
|
||||||
|
.string({
|
||||||
|
required_error: 'Specialist harus dipilih',
|
||||||
|
})
|
||||||
|
.min(1, 'Specialist harus dipilih'),
|
||||||
|
})
|
||||||
|
|
||||||
|
// Unit mapping berdasarkan installation
|
||||||
|
export const installationUnitMapping: Record<string, string[]> = {
|
||||||
|
'1': ['1', '3'],
|
||||||
|
'2': ['2', '3'],
|
||||||
|
'3': ['1', '2', '3'],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unitConf = {
|
||||||
|
msg: {
|
||||||
|
placeholder: '---pilih unit',
|
||||||
|
search: 'kode, nama unit',
|
||||||
|
empty: 'unit tidak ditemukan',
|
||||||
|
},
|
||||||
|
items: [
|
||||||
|
{ value: '1', label: 'Instalasi Medis', code: 'MED' },
|
||||||
|
{ value: '2', label: 'Instalasi Keperawatan', code: 'NUR' },
|
||||||
|
{ value: '3', label: 'Instalasi Administrasi', code: 'ADM' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const specialistConf = {
|
||||||
|
msg: {
|
||||||
|
placeholder: '---pilih specialist',
|
||||||
|
search: 'kode, nama specialist',
|
||||||
|
empty: 'specialist tidak ditemukan',
|
||||||
|
},
|
||||||
|
items: [
|
||||||
|
{ value: '1', label: 'Spesialis Jantung', code: 'CARD' },
|
||||||
|
{ value: '2', label: 'Spesialis Mata', code: 'OPHT' },
|
||||||
|
{ value: '3', label: 'Spesialis Bedah', code: 'SURG' },
|
||||||
|
{ value: '4', label: 'Spesialis Anak', code: 'PEDI' },
|
||||||
|
{ value: '5', label: 'Spesialis Kandungan', code: 'OBGY' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const installationConf = {
|
||||||
|
msg: {
|
||||||
|
placeholder: '---pilih instalasi',
|
||||||
|
search: 'kode, nama instalasi',
|
||||||
|
empty: 'instalasi tidak ditemukan',
|
||||||
|
},
|
||||||
|
items: [
|
||||||
|
{ value: '1', label: 'Ambulatory', code: 'AMB' },
|
||||||
|
{ value: '2', label: 'Inpatient', code: 'IMP' },
|
||||||
|
{ value: '3', label: 'Emergency', code: 'EMER' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function untuk filter unit berdasarkan installation
|
||||||
|
export function getFilteredUnits(installationId: string) {
|
||||||
|
if (!installationId || !installationUnitMapping[installationId]) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const allowedUnitIds = installationUnitMapping[installationId]
|
||||||
|
return unitConf.items.filter((unit) => allowedUnitIds.includes(unit.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function untuk membuat unit config yang ter-filter
|
||||||
|
export function createFilteredUnitConf(installationId: string) {
|
||||||
|
return {
|
||||||
|
...unitConf,
|
||||||
|
items: getFilteredUnits(installationId),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { HeaderPrep } from '~/components/pub/custom-ui/data/types'
|
||||||
|
import AppSubspecialistEntryForm from '~/components/app/subspecialist/entry-form.vue'
|
||||||
|
import Dialog from '~/components/pub/base/modal/dialog.vue'
|
||||||
|
import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue'
|
||||||
|
import { ActionEvents } from '~/components/pub/custom-ui/data/types'
|
||||||
|
import Header from '~/components/pub/custom-ui/nav-header/header.vue'
|
||||||
|
import { usePaginatedList } from '~/composables/usePaginatedList'
|
||||||
|
import { createFilteredUnitConf, installationConf, schemaConf, specialistConf, unitConf } from './entry'
|
||||||
|
|
||||||
|
// #region State & Computed
|
||||||
|
// Dialog state
|
||||||
|
const isFormEntryDialogOpen = ref(false)
|
||||||
|
const isRecordConfirmationOpen = ref(false)
|
||||||
|
|
||||||
|
// Table action rowId provider
|
||||||
|
const recId = ref<number>(0)
|
||||||
|
const recAction = ref<string>('')
|
||||||
|
const recItem = ref<any>(null)
|
||||||
|
|
||||||
|
// State untuk tracking installation, unit, dan specialist yang dipilih di form
|
||||||
|
const selectedInstallationId = ref<string>('')
|
||||||
|
const selectedUnitId = ref<string>('')
|
||||||
|
|
||||||
|
// Computed untuk filtered unit berdasarkan installation yang dipilih
|
||||||
|
const filteredUnitConf = computed(() => {
|
||||||
|
if (!selectedInstallationId.value) {
|
||||||
|
return { ...unitConf, items: [] }
|
||||||
|
}
|
||||||
|
return createFilteredUnitConf(selectedInstallationId.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
paginationMeta,
|
||||||
|
searchInput,
|
||||||
|
handlePageChange,
|
||||||
|
handleSearch,
|
||||||
|
fetchData: getSubSpecialistList,
|
||||||
|
} = usePaginatedList({
|
||||||
|
fetchFn: fetchSubSpecialistData,
|
||||||
|
entityName: 'subspecialist',
|
||||||
|
})
|
||||||
|
|
||||||
|
const headerPrep: HeaderPrep = {
|
||||||
|
title: 'Sub Specialist',
|
||||||
|
icon: 'i-lucide-box',
|
||||||
|
refSearchNav: {
|
||||||
|
placeholder: 'Cari (min. 3 karakter)...',
|
||||||
|
minLength: 3,
|
||||||
|
debounceMs: 500,
|
||||||
|
showValidationFeedback: true,
|
||||||
|
onInput: (_val: string) => {
|
||||||
|
// Handle search input - this will be triggered by the header component
|
||||||
|
},
|
||||||
|
onClick: () => {
|
||||||
|
// Handle search button click if needed
|
||||||
|
},
|
||||||
|
onClear: () => {
|
||||||
|
// Handle search clear
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addNav: {
|
||||||
|
label: 'Tambah Sub Specialist',
|
||||||
|
icon: 'i-lucide-send',
|
||||||
|
onClick: () => {
|
||||||
|
isFormEntryDialogOpen.value = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
provide('rec_id', recId)
|
||||||
|
provide('rec_action', recAction)
|
||||||
|
provide('rec_item', recItem)
|
||||||
|
provide('table_data_loader', isLoading)
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Functions
|
||||||
|
async function fetchSubSpecialistData(params: any) {
|
||||||
|
const endpoint = transform('/api/v1/patient', params)
|
||||||
|
return await xfetch(endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDeleteRow(record: any) {
|
||||||
|
try {
|
||||||
|
// TODO : hit backend request untuk delete
|
||||||
|
console.log('Deleting record:', record)
|
||||||
|
|
||||||
|
// Simulate API call
|
||||||
|
// const response = await xfetch(`/api/v1/subspecialist/${record.id}`, {
|
||||||
|
// method: 'DELETE'
|
||||||
|
// })
|
||||||
|
|
||||||
|
// Refresh data setelah berhasil delete
|
||||||
|
await getSubSpecialistList()
|
||||||
|
|
||||||
|
// TODO: Show success message
|
||||||
|
console.log('Record deleted successfully')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting record:', error)
|
||||||
|
// TODO: Show error message
|
||||||
|
} finally {
|
||||||
|
// Reset record state
|
||||||
|
recId.value = 0
|
||||||
|
recAction.value = ''
|
||||||
|
recItem.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle confirmation result
|
||||||
|
function handleConfirmDelete(record: any, action: string) {
|
||||||
|
console.log('Confirmed action:', action, 'for record:', record)
|
||||||
|
handleDeleteRow(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCancelConfirmation() {
|
||||||
|
// Reset record state when cancelled
|
||||||
|
recId.value = 0
|
||||||
|
recAction.value = ''
|
||||||
|
recItem.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// #endregion region
|
||||||
|
|
||||||
|
// #region Form event handlers
|
||||||
|
|
||||||
|
function onCancelForm(resetForm: () => void) {
|
||||||
|
isFormEntryDialogOpen.value = false
|
||||||
|
selectedInstallationId.value = ''
|
||||||
|
selectedUnitId.value = ''
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
resetForm()
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInstallationChanged(installationId: string) {
|
||||||
|
selectedInstallationId.value = installationId
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUnitChanged(unitId: string) {
|
||||||
|
selectedUnitId.value = unitId
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSubmitForm(values: any, resetForm: () => void) {
|
||||||
|
let isSuccess = false
|
||||||
|
try {
|
||||||
|
// TODO: Implement form submission logic
|
||||||
|
console.log('Form submitted:', values)
|
||||||
|
|
||||||
|
// Simulate API call
|
||||||
|
// const response = await xfetch('/api/v1/subspecialist', {
|
||||||
|
// method: 'POST',
|
||||||
|
// body: JSON.stringify(values)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// If successful, mark as success and close dialog
|
||||||
|
isFormEntryDialogOpen.value = false
|
||||||
|
isSuccess = true
|
||||||
|
|
||||||
|
// Reset selection ketika form berhasil submit
|
||||||
|
selectedInstallationId.value = ''
|
||||||
|
selectedUnitId.value = ''
|
||||||
|
|
||||||
|
// Refresh data after successful submission
|
||||||
|
await getSubSpecialistList()
|
||||||
|
|
||||||
|
// TODO: Show success message
|
||||||
|
console.log('Sub Specialist created successfully')
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.warn('Error submitting form:', error)
|
||||||
|
isSuccess = false
|
||||||
|
// Don't close dialog or reset form on error
|
||||||
|
// TODO: Show error message to user
|
||||||
|
} finally {
|
||||||
|
if (isSuccess) {
|
||||||
|
setTimeout(() => {
|
||||||
|
resetForm()
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Watchers
|
||||||
|
|
||||||
|
// Watch for row actions
|
||||||
|
watch(recId, () => {
|
||||||
|
switch (recAction.value) {
|
||||||
|
case ActionEvents.showEdit:
|
||||||
|
// TODO: Handle edit action
|
||||||
|
// isFormEntryDialogOpen.value = true
|
||||||
|
break
|
||||||
|
case ActionEvents.showConfirmDelete:
|
||||||
|
// Trigger confirmation modal open
|
||||||
|
isRecordConfirmationOpen.value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="rounded-md border p-4">
|
||||||
|
<Header v-model="searchInput" :prep="headerPrep" @search="handleSearch" />
|
||||||
|
<AppSubspecialistList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
|
||||||
|
<Dialog v-model:open="isFormEntryDialogOpen" :title="headerPrep.addNav?.label!" size="lg" prevent-outside>
|
||||||
|
<AppSubspecialistEntryForm
|
||||||
|
:installation="installationConf"
|
||||||
|
:unit="filteredUnitConf"
|
||||||
|
:specialist="specialistConf"
|
||||||
|
:schema="schemaConf"
|
||||||
|
:initial-values="{ name: '', code: '', installationId: '', unitId: '', specialistId: '' }"
|
||||||
|
@submit="onSubmitForm"
|
||||||
|
@cancel="onCancelForm"
|
||||||
|
@installation-changed="onInstallationChanged"
|
||||||
|
@unit-changed="onUnitChanged"
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<RecordConfirmation
|
||||||
|
v-model:open="isRecordConfirmationOpen"
|
||||||
|
action="delete"
|
||||||
|
:record="recItem"
|
||||||
|
@confirm="handleConfirmDelete"
|
||||||
|
@cancel="handleCancelConfirmation"
|
||||||
|
>
|
||||||
|
<template #default="{ record }">
|
||||||
|
<div class="text-sm">
|
||||||
|
<p><strong>ID:</strong> {{ record?.id }}</p>
|
||||||
|
<p v-if="record?.name"><strong>Nama:</strong> {{ record.name }}</p>
|
||||||
|
<p v-if="record?.code"><strong>Kode:</strong> {{ record.code }}</p>
|
||||||
|
<p v-if="record?.specialist"><strong>Specialist:</strong> {{ record.specialist?.name }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</RecordConfirmation>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// import type { PagePermission } from '~/models/role'
|
||||||
|
import Error from '~/components/pub/base/error/error.vue'
|
||||||
|
// import { PAGE_PERMISSIONS } from '~/lib/page-permission'
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
// middleware: ['rbac'],
|
||||||
|
roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
|
||||||
|
title: 'List Specialist',
|
||||||
|
contentFrame: 'cf-full-width',
|
||||||
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
useHead({
|
||||||
|
title: () => route.meta.title as string,
|
||||||
|
})
|
||||||
|
|
||||||
|
// const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
|
||||||
|
|
||||||
|
// const { checkRole, hasReadAccess } = useRBAC()
|
||||||
|
|
||||||
|
// // Check if user has access to this page
|
||||||
|
// const hasAccess = checkRole(roleAccess)
|
||||||
|
// if (!hasAccess) {
|
||||||
|
// navigateTo('/403')
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Define permission-based computed properties
|
||||||
|
// const canRead = hasReadAccess(roleAccess)
|
||||||
|
const canRead = true
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div v-if="canRead">
|
||||||
|
<ContentSubspecialistList />
|
||||||
|
</div>
|
||||||
|
<Error v-else :status-code="403" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user