feat(unit): add unit detail page with position management
- Create new unit detail page with route and navigation - Add unit detail component to display basic unit information - Implement position list management with pagination and actions - Include position creation, editing and deletion functionality - Update unit model to include installation relationship
This commit is contained in:
No files matched your search
@@ -0,0 +1,35 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { Unit } from '~/models/unit'
|
||||||
|
import DetailRow from '~/components/pub/my-ui/form/view/detail-row.vue'
|
||||||
|
|
||||||
|
// #region Props & Emits
|
||||||
|
defineProps<{
|
||||||
|
unit: Unit
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region State & Computed
|
||||||
|
|
||||||
|
// #region Lifecycle Hooks
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Functions
|
||||||
|
|
||||||
|
// #endregion region
|
||||||
|
|
||||||
|
// #region Utilities & event handlers
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Watchers
|
||||||
|
// #endregion
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<DetailRow label="Kode">{{ unit.code || '-' }}</DetailRow>
|
||||||
|
<DetailRow label="Nama">{{ unit.name || '-' }}</DetailRow>
|
||||||
|
<!-- <DetailRow label="Nama Instalasi">{{ unit.installation?.name || '-' }}</DetailRow> -->
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import type { Config, RecComponent } from '~/components/pub/my-ui/data-table'
|
||||||
|
import { defineAsyncComponent } from 'vue'
|
||||||
|
import type { UnitPosition } from '~/models/unit-position'
|
||||||
|
|
||||||
|
type SmallDetailDto = any
|
||||||
|
|
||||||
|
const action = defineAsyncComponent(() => import('~/components/pub/my-ui/data/dropdown-action-ud.vue'))
|
||||||
|
|
||||||
|
export const config: Config = {
|
||||||
|
cols: [{}, {}, {}, {}, {}, { width: 50 }],
|
||||||
|
|
||||||
|
headers: [
|
||||||
|
[
|
||||||
|
{ label: '#' },
|
||||||
|
{ label: 'Kode Posisi' },
|
||||||
|
{ label: 'Nama Posisi' },
|
||||||
|
{ label: 'Karyawan' },
|
||||||
|
{ label: 'Status Kepala' },
|
||||||
|
{ label: '' },
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
keys: ['index', 'code', 'name', 'employee', 'head', 'action'],
|
||||||
|
|
||||||
|
delKeyNames: [
|
||||||
|
{ key: 'code', label: 'Kode' },
|
||||||
|
{ key: 'name', label: 'Nama' },
|
||||||
|
],
|
||||||
|
|
||||||
|
parses: {
|
||||||
|
employee: (rec: unknown): unknown => {
|
||||||
|
const recX = rec as UnitPosition
|
||||||
|
const fullName = [recX.employee?.person.frontTitle, recX.employee?.person.name, recX.employee?.person.endTitle]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')
|
||||||
|
.trim()
|
||||||
|
|
||||||
|
return fullName || '-'
|
||||||
|
},
|
||||||
|
head: (rec: unknown): unknown => {
|
||||||
|
const recX = rec as SmallDetailDto
|
||||||
|
return recX.headStatus ? 'Ya' : 'Tidak'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
action(rec, idx) {
|
||||||
|
const res: RecComponent = {
|
||||||
|
idx,
|
||||||
|
rec: rec as object,
|
||||||
|
component: action,
|
||||||
|
props: {
|
||||||
|
size: 'sm',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
htmls: {},
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// Components
|
||||||
|
import PaginationView from '~/components/pub/my-ui/pagination/pagination-view.vue'
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { PaginationMeta } from '~/components/pub/my-ui/pagination/pagination.type'
|
||||||
|
|
||||||
|
// Configs
|
||||||
|
import { config } 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">
|
||||||
|
<PubMyUiDataTable
|
||||||
|
v-bind="config"
|
||||||
|
:rows="data"
|
||||||
|
:skeleton-size="paginationMeta?.pageSize"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-2 flex justify-end border-t-slate-300 py-2">
|
||||||
|
<PubMyUiNavFooterBa
|
||||||
|
@click="
|
||||||
|
navigateTo({
|
||||||
|
name: 'org-src-unit',
|
||||||
|
})
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
||||||
|
import RecordConfirmation from '~/components/pub/my-ui/confirmation/record-confirmation.vue'
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
|
||||||
|
|
||||||
|
// Service
|
||||||
|
import type { Unit } from '~/models/unit'
|
||||||
|
import { getDetail as getDetailUnit } from '~/services/unit.service'
|
||||||
|
|
||||||
|
// #region installtaion positions
|
||||||
|
import { config } from '~/components/app/unit/detail/list.cfg'
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
import { usePaginatedList } from '~/composables/usePaginatedList'
|
||||||
|
import { toast } from '~/components/pub/ui/toast'
|
||||||
|
|
||||||
|
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
|
||||||
|
// Types
|
||||||
|
import { type UnitPositionFormData, UnitPositionSchema } from '~/schemas/unit-position.schema'
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
import {
|
||||||
|
recId,
|
||||||
|
recAction,
|
||||||
|
recItem,
|
||||||
|
isReadonly,
|
||||||
|
isProcessing,
|
||||||
|
isFormEntryDialogOpen,
|
||||||
|
isRecordConfirmationOpen,
|
||||||
|
onResetState,
|
||||||
|
handleActionSave,
|
||||||
|
handleActionEdit,
|
||||||
|
handleActionRemove,
|
||||||
|
handleCancelForm,
|
||||||
|
} from '~/handlers/unit-position.handler'
|
||||||
|
|
||||||
|
// Services
|
||||||
|
import { getList, getDetail as getDetailUnitPosition } from '~/services/unit-position.service'
|
||||||
|
import { getValueLabelList as getEmployeeLabelList } from '~/services/employee.service'
|
||||||
|
|
||||||
|
const employees = ref<{ value: string | number; label: string }[]>([])
|
||||||
|
|
||||||
|
const title = ref('')
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Props & Emits
|
||||||
|
const props = defineProps<{
|
||||||
|
unitId: string
|
||||||
|
}>()
|
||||||
|
const unit = ref<Unit>({} as Unit)
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region State & Computed
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
paginationMeta,
|
||||||
|
searchInput,
|
||||||
|
handlePageChange,
|
||||||
|
handleSearch,
|
||||||
|
fetchData: getPositionList,
|
||||||
|
} = usePaginatedList({
|
||||||
|
fetchFn: async (params: any) => {
|
||||||
|
console.log(props.unitId)
|
||||||
|
const result = await getList({
|
||||||
|
'unit-id': props.unitId,
|
||||||
|
includes: 'Employee.Person',
|
||||||
|
search: params.search,
|
||||||
|
sort: 'createdAt:asc',
|
||||||
|
'page-no-limit': true,
|
||||||
|
})
|
||||||
|
return { success: result.success || false, body: result.body || {} }
|
||||||
|
},
|
||||||
|
entityName: 'unit-position',
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataMap = computed(() => {
|
||||||
|
return data.value.map((v, i) => {
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
index: i + 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const headerPrep: HeaderPrep = {
|
||||||
|
title: 'Detail Instalasi',
|
||||||
|
icon: 'i-lucide-user',
|
||||||
|
refSearchNav: {
|
||||||
|
placeholder: 'Cari (min. 3 karakter)...',
|
||||||
|
minLength: 3,
|
||||||
|
debounceMs: 500,
|
||||||
|
showValidationFeedback: true,
|
||||||
|
onInput: (value: string) => {
|
||||||
|
searchInput.value = value
|
||||||
|
},
|
||||||
|
onClick: () => {},
|
||||||
|
onClear: () => {},
|
||||||
|
},
|
||||||
|
addNav: {
|
||||||
|
label: 'Tambah Posisi',
|
||||||
|
icon: 'i-lucide-plus',
|
||||||
|
onClick: () => {
|
||||||
|
recItem.value = null
|
||||||
|
recId.value = 0
|
||||||
|
isFormEntryDialogOpen.value = true
|
||||||
|
isReadonly.value = false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Lifecycle Hooks
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const result = await getDetailUnit(props.unitId)
|
||||||
|
if (result.success) {
|
||||||
|
unit.value = result.body.data || {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await getEmployeeLabelList({ sort: 'createdAt:asc', 'page-size': 100, includes: 'person' })
|
||||||
|
employees.value = res
|
||||||
|
} catch (err) {
|
||||||
|
// show toast
|
||||||
|
toast({
|
||||||
|
title: 'Terjadi Kesalahan',
|
||||||
|
description: 'Terjadi kesalahan saat memuat data',
|
||||||
|
variant: 'destructive',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Functions
|
||||||
|
// #endregion region
|
||||||
|
|
||||||
|
// #region Utilities & event handlers
|
||||||
|
// #endregion
|
||||||
|
|
||||||
|
// #region Watchers
|
||||||
|
// #endregion
|
||||||
|
provide('rec_id', recId)
|
||||||
|
provide('rec_action', recAction)
|
||||||
|
provide('rec_item', recItem)
|
||||||
|
provide('table_data_loader', isLoading)
|
||||||
|
|
||||||
|
// Watch for row actions when recId or recAction changes
|
||||||
|
watch([recId, recAction], () => {
|
||||||
|
console.log(recId, recAction)
|
||||||
|
switch (recAction.value) {
|
||||||
|
case ActionEvents.showEdit:
|
||||||
|
getDetailUnitPosition(recId.value)
|
||||||
|
title.value = 'Edit Posisi'
|
||||||
|
isReadonly.value = false
|
||||||
|
isFormEntryDialogOpen.value = true
|
||||||
|
break
|
||||||
|
case ActionEvents.showConfirmDelete:
|
||||||
|
isRecordConfirmationOpen.value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Header
|
||||||
|
:prep="headerPrep"
|
||||||
|
:ref-search-nav="headerPrep.refSearchNav"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<AppUnitDetail :unit="unit" />
|
||||||
|
<div class="h-6"></div>
|
||||||
|
|
||||||
|
<AppUnitDetailList
|
||||||
|
:data="dataMap"
|
||||||
|
:pagination-meta="paginationMeta"
|
||||||
|
@page-change="handlePageChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
v-model:open="isFormEntryDialogOpen"
|
||||||
|
:title="!!recItem ? title : 'Tambah Posisi'"
|
||||||
|
size="lg"
|
||||||
|
prevent-outside
|
||||||
|
@update:open="
|
||||||
|
(value: any) => {
|
||||||
|
onResetState()
|
||||||
|
isFormEntryDialogOpen = value
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<AppUnitPositionEntry
|
||||||
|
:schema="UnitPositionSchema"
|
||||||
|
:unit-id="unitId"
|
||||||
|
:employees="employees"
|
||||||
|
:values="recItem"
|
||||||
|
:is-loading="isProcessing"
|
||||||
|
:is-readonly="isReadonly"
|
||||||
|
@submit="
|
||||||
|
(values: UnitPositionFormData | Record<string, any>, resetForm: () => void) => {
|
||||||
|
console.log(values)
|
||||||
|
if (recId > 0) {
|
||||||
|
handleActionEdit(recId, values, getPositionList, onResetState, toast)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
handleActionSave(values, getPositionList, onResetState, toast)
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@cancel="handleCancelForm"
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
<RecordConfirmation
|
||||||
|
v-model:open="isRecordConfirmationOpen"
|
||||||
|
action="delete"
|
||||||
|
:record="recItem"
|
||||||
|
@confirm="() => handleActionRemove(recId, getPositionList, toast)"
|
||||||
|
@cancel=""
|
||||||
|
>
|
||||||
|
<template #default="{ record }">
|
||||||
|
<div class="space-y-1 text-sm">
|
||||||
|
<p
|
||||||
|
v-for="field in config.delKeyNames"
|
||||||
|
:key="field.key"
|
||||||
|
:v-if="record?.[field.key]"
|
||||||
|
>
|
||||||
|
<span class="font-semibold">{{ field.label }}:</span>
|
||||||
|
{{ record[field.key] }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</RecordConfirmation>
|
||||||
|
</template>
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import * as z from 'zod'
|
|
||||||
|
|
||||||
export const unitConf = {
|
|
||||||
msg: {
|
|
||||||
placeholder: '--- pilih instalasi',
|
|
||||||
search: 'kode, nama instalasi',
|
|
||||||
empty: 'instalasi tidak ditemukan',
|
|
||||||
},
|
|
||||||
items: [
|
|
||||||
{ value: '1', label: 'Instalasi Medis', code: 'MED' },
|
|
||||||
{ value: '2', label: 'Instalasi Keperawatan', code: 'NUR' },
|
|
||||||
{ value: '3', label: 'Instalasi Administrasi', code: 'ADM' },
|
|
||||||
{ value: '4', label: 'Instalasi Penunjang Non-Medis', code: 'SUP' },
|
|
||||||
{ value: '5', label: 'Instalasi Pendidikan & Pelatihan', code: 'EDU' },
|
|
||||||
{ value: '6', label: 'Instalasi Farmasi', code: 'PHA' },
|
|
||||||
{ value: '7', label: 'Instalasi Radiologi', code: 'RAD' },
|
|
||||||
{ value: '8', label: 'Instalasi Laboratorium', code: 'LAB' },
|
|
||||||
{ value: '9', label: 'Instalasi Keuangan', code: 'FIN' },
|
|
||||||
{ value: '10', label: 'Instalasi SDM', code: 'HR' },
|
|
||||||
{ value: '11', label: 'Instalasi Teknologi Informasi', code: 'ITS' },
|
|
||||||
{ value: '12', label: 'Instalasi Pemeliharaan & Sarana', code: 'MNT' },
|
|
||||||
{ value: '13', label: 'Instalasi Gizi / Catering', code: 'CAT' },
|
|
||||||
{ value: '14', label: 'Instalasi Keamanan', code: 'SEC' },
|
|
||||||
{ value: '15', label: 'Instalasi Gawat Darurat', code: 'EMR' },
|
|
||||||
{ value: '16', label: 'Instalasi Bedah Sentral', code: 'SUR' },
|
|
||||||
{ value: '17', label: 'Instalasi Rawat Jalan', code: 'OUT' },
|
|
||||||
{ value: '18', label: 'Instalasi Rawat Inap', code: 'INP' },
|
|
||||||
{ value: '19', label: 'Instalasi Rehabilitasi Medik', code: 'REB' },
|
|
||||||
{ value: '20', label: 'Instalasi Penelitian & Pengembangan', code: 'RSH' },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
export const schemaConf = z.object({
|
|
||||||
name: z
|
|
||||||
.string({
|
|
||||||
required_error: 'Nama unit harus diisi',
|
|
||||||
})
|
|
||||||
.min(1, 'Nama unit harus diisi'),
|
|
||||||
|
|
||||||
code: z
|
|
||||||
.string({
|
|
||||||
required_error: 'Kode unit harus diisi',
|
|
||||||
})
|
|
||||||
.min(1, 'Kode unit harus diisi'),
|
|
||||||
parentId: z.preprocess(
|
|
||||||
(input: unknown) => {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
// Handle empty string case
|
|
||||||
if (input.trim() === '') {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return Number(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
return input
|
|
||||||
},
|
|
||||||
z
|
|
||||||
.number({
|
|
||||||
required_error: 'Instalasi induk harus dipilih',
|
|
||||||
})
|
|
||||||
.refine((num) => num > 0, 'Instalasi induk harus dipilih'),
|
|
||||||
),
|
|
||||||
})
|
|
||||||
@@ -103,9 +103,23 @@ const getCurrentUnitDetail = async (id: number | string) => {
|
|||||||
watch([recId, recAction], () => {
|
watch([recId, recAction], () => {
|
||||||
switch (recAction.value) {
|
switch (recAction.value) {
|
||||||
case ActionEvents.showDetail:
|
case ActionEvents.showDetail:
|
||||||
getCurrentUnitDetail(recId.value)
|
if (Number(recId.value) > 0) {
|
||||||
title.value = 'Detail Unit'
|
const id = Number(recId.value)
|
||||||
isReadonly.value = true
|
|
||||||
|
recAction.value = ''
|
||||||
|
recItem.value = null
|
||||||
|
recId.value = 0
|
||||||
|
isFormEntryDialogOpen.value = false
|
||||||
|
isReadonly.value = false
|
||||||
|
|
||||||
|
navigateTo({
|
||||||
|
name: 'org-src-unit-id',
|
||||||
|
params: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
case ActionEvents.showEdit:
|
case ActionEvents.showEdit:
|
||||||
getCurrentUnitDetail(recId.value)
|
getCurrentUnitDetail(recId.value)
|
||||||
|
|||||||
+4
-2
@@ -1,9 +1,11 @@
|
|||||||
import { type Base, genBase } from "./_base"
|
import { type Base, genBase } from './_base'
|
||||||
|
import { type Installation } from '~/models/installation'
|
||||||
export interface Unit extends Base {
|
export interface Unit extends Base {
|
||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
installation_id?: number | string | null
|
installation_id?: number | string | null
|
||||||
|
|
||||||
|
installation?: Installation
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genUnit(): Unit {
|
export function genUnit(): Unit {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// import type { PagePermission } from '~/models/role'
|
||||||
|
import Error from '~/components/pub/my-ui/error/error.vue'
|
||||||
|
// import { PAGE_PERMISSIONS } from '~/lib/page-permission'
|
||||||
|
|
||||||
|
definePageMeta({
|
||||||
|
// middleware: ['rbac'],
|
||||||
|
roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
|
||||||
|
title: 'Detail Divisi',
|
||||||
|
contentFrame: 'cf-container-lg',
|
||||||
|
})
|
||||||
|
|
||||||
|
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>
|
||||||
|
<template v-if="canRead">
|
||||||
|
<ContentUnitDetail :unit-id="String(route.params.id)" />
|
||||||
|
</template>
|
||||||
|
<Error
|
||||||
|
v-else
|
||||||
|
:status-code="403"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import * as base from './_crud-base'
|
import * as base from './_crud-base'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import type { Unit } from "~/models/unit";
|
import type { Unit } from '~/models/unit'
|
||||||
|
|
||||||
const path = '/api/v1/unit'
|
const path = '/api/v1/unit'
|
||||||
const name = 'unit'
|
const name = 'unit'
|
||||||
|
|||||||
Reference in New Issue
Block a user