feat(unit-position): implement crud operations and update ui components
- Add new handler, service, and schema files for unit-position - Update list configuration and entry form components - Modify page title and integrate employee relation - Implement CRUD operations with proper validation
This commit is contained in:
@@ -3,16 +3,17 @@
|
||||
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
|
||||
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
|
||||
import RecordConfirmation from '~/components/pub/my-ui/confirmation/record-confirmation.vue'
|
||||
import AppUnitList from '~/components/app/unit/list.vue'
|
||||
import AppUnitEntryForm from '~/components/app/unit/entry-form.vue'
|
||||
import AppUnitPositionList from '~/components/app/unit-position/list.vue'
|
||||
import AppUnitPositionEntryForm from '~/components/app/unit-position/entry-form.vue'
|
||||
|
||||
// Helpers
|
||||
import { usePaginatedList } from '~/composables/usePaginatedList'
|
||||
import { toast } from '~/components/pub/ui/toast'
|
||||
import { config } from '~/components/app/unit-position/list.cfg'
|
||||
|
||||
// Types
|
||||
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
|
||||
import { UnitSchema, type UnitFormData } from '~/schemas/unit.schema'
|
||||
import { type UnitPositionFormData, UnitPositionSchema } from '~/schemas/unit-position.schema'
|
||||
|
||||
// Handlers
|
||||
import {
|
||||
@@ -28,13 +29,15 @@ import {
|
||||
handleActionEdit,
|
||||
handleActionRemove,
|
||||
handleCancelForm,
|
||||
} from '~/handlers/unit.handler'
|
||||
} from '~/handlers/unit-position.handler'
|
||||
|
||||
// Services
|
||||
import { getList, getDetail } from '~/services/unit.service'
|
||||
import { getValueLabelList as getInstallationList } from '~/services/installation.service'
|
||||
import { getList, getDetail } from '~/services/unit-position.service'
|
||||
import { getValueLabelList as getValueLabelUnitList } from '~/services/unit.service'
|
||||
import { getValueLabelList as getEmployeeLabelList } from '~/services/employee.service'
|
||||
|
||||
const installations = ref<{ value: string; label: string }[]>([])
|
||||
const units = ref<{ value: string; label: string }[]>([])
|
||||
const employees = ref<{ value: string | number; label: string }[]>([])
|
||||
const title = ref('')
|
||||
|
||||
const {
|
||||
@@ -44,7 +47,7 @@ const {
|
||||
searchInput,
|
||||
handlePageChange,
|
||||
handleSearch,
|
||||
fetchData: getUnitList,
|
||||
fetchData: getListUnit,
|
||||
} = usePaginatedList({
|
||||
fetchFn: async (params: any) => {
|
||||
const result = await getList({
|
||||
@@ -52,11 +55,11 @@ const {
|
||||
sort: 'createdAt:asc',
|
||||
'page-number': params['page-number'] || 0,
|
||||
'page-size': params['page-size'] || 10,
|
||||
includes: 'installation',
|
||||
includes: 'unit,Employee.Person',
|
||||
})
|
||||
return { success: result.success || false, body: result.body || {} }
|
||||
},
|
||||
entityName: 'unit',
|
||||
entityName: 'unit-position',
|
||||
})
|
||||
|
||||
const headerPrep: HeaderPrep = {
|
||||
@@ -104,12 +107,12 @@ watch([recId, recAction], () => {
|
||||
switch (recAction.value) {
|
||||
case ActionEvents.showDetail:
|
||||
getCurrentUnitDetail(recId.value)
|
||||
title.value = 'Detail Unit'
|
||||
title.value = 'Detail Unit Posisi'
|
||||
isReadonly.value = true
|
||||
break
|
||||
case ActionEvents.showEdit:
|
||||
getCurrentUnitDetail(recId.value)
|
||||
title.value = 'Edit Unit'
|
||||
title.value = 'Edit Unit Posisi'
|
||||
isReadonly.value = false
|
||||
break
|
||||
case ActionEvents.showConfirmDelete:
|
||||
@@ -119,8 +122,18 @@ watch([recId, recAction], () => {
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
installations.value = await getInstallationList()
|
||||
await getUnitList()
|
||||
try {
|
||||
units.value = await getValueLabelUnitList({ sort: 'createdAt:asc', 'page-size': 100 })
|
||||
employees.value = await getEmployeeLabelList({ sort: 'createdAt:asc', 'page-size': 100, includes: 'person' })
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
// show toast
|
||||
toast({
|
||||
title: 'Terjadi Kesalahan',
|
||||
description: 'Terjadi kesalahan saat memuat data',
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -140,7 +153,7 @@ onMounted(async () => {
|
||||
|
||||
<Dialog
|
||||
v-model:open="isFormEntryDialogOpen"
|
||||
:title="!!recItem ? title : 'Tambah Unit'"
|
||||
:title="!!recItem ? title : 'Tambah Unit Posisi'"
|
||||
size="lg"
|
||||
prevent-outside
|
||||
@update:open="
|
||||
@@ -151,45 +164,41 @@ onMounted(async () => {
|
||||
"
|
||||
>
|
||||
<AppUnitPositionEntryForm
|
||||
:schema="UnitSchema"
|
||||
:installations="installations"
|
||||
:schema="UnitPositionSchema"
|
||||
:units="units"
|
||||
:employees="employees"
|
||||
:values="recItem"
|
||||
:is-loading="isProcessing"
|
||||
:is-readonly="isReadonly"
|
||||
@submit="
|
||||
(values: UnitFormData | Record<string, any>, resetForm: () => void) => {
|
||||
(values: UnitPositionFormData | Record<string, any>, resetForm: () => void) => {
|
||||
if (recId > 0) {
|
||||
handleActionEdit(recId, values, getUnitList, resetForm, toast)
|
||||
handleActionEdit(recId, values, getListUnit, resetForm, toast)
|
||||
return
|
||||
}
|
||||
handleActionSave(values, getUnitList, resetForm, toast)
|
||||
handleActionSave(values, getListUnit, resetForm, toast)
|
||||
}
|
||||
"
|
||||
@cancel="handleCancelForm"
|
||||
/>
|
||||
</Dialog>
|
||||
|
||||
<!-- Record Confirmation Modal -->
|
||||
<RecordConfirmation
|
||||
v-model:open="isRecordConfirmationOpen"
|
||||
action="delete"
|
||||
:record="recItem"
|
||||
@confirm="() => handleActionRemove(recId, getUnitList, toast)"
|
||||
@confirm="() => handleActionRemove(recId, getListUnit, toast)"
|
||||
@cancel=""
|
||||
>
|
||||
<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 }}
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user