From 1dc42be406aa6562074f61c33336f5dab1132dba Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Thu, 30 Oct 2025 12:14:32 +0700 Subject: [PATCH] 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 --- .../app/unit-position/entry-form.vue | 44 +++++++---- app/components/app/unit-position/list.cfg.ts | 12 +-- app/components/content/unit-position/list.vue | 77 +++++++++++-------- app/handlers/unit-position.handler.ts | 24 ++++++ app/models/unit-position.ts | 3 + .../org-src/unit-position/index.vue | 2 +- app/schemas/unit-position.schema.ts | 24 ++++++ app/services/unit-position.service.ts | 25 ++++++ 8 files changed, 153 insertions(+), 58 deletions(-) create mode 100644 app/handlers/unit-position.handler.ts create mode 100644 app/schemas/unit-position.schema.ts create mode 100644 app/services/unit-position.service.ts diff --git a/app/components/app/unit-position/entry-form.vue b/app/components/app/unit-position/entry-form.vue index da4782c0..b6ab8609 100644 --- a/app/components/app/unit-position/entry-form.vue +++ b/app/components/app/unit-position/entry-form.vue @@ -7,18 +7,18 @@ import Label from '~/components/pub/my-ui/doc-entry/label.vue' import Combobox from '~/components/pub/my-ui/combobox/combobox.vue' // Types -import type { DivisionPositionFormData } from '~/schemas/division-position.schema' +import type { UnitPositionFormData } from '~/schemas/unit-position.schema' // Helpers import type z from 'zod' import { toTypedSchema } from '@vee-validate/zod' import { useForm } from 'vee-validate' import { genBase } from '~/models/_base' -import { genDivisionPosition } from '~/models/division-position' +import { genUnitPosition } from '~/models/unit-position' interface Props { schema: z.ZodSchema - divisionId: number + units: any[] employees: any[] values: any isLoading?: boolean @@ -26,21 +26,21 @@ interface Props { } const props = defineProps() - const isLoading = props.isLoading !== undefined ? props.isLoading : false const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false const emit = defineEmits<{ - submit: [values: DivisionPositionFormData, resetForm: () => void] + submit: [values: UnitPositionFormData, resetForm: () => void] cancel: [resetForm: () => void] }>() const { defineField, errors, meta } = useForm({ validationSchema: toTypedSchema(props.schema), - initialValues: genDivisionPosition() as Partial, + initialValues: genUnitPosition() as Partial, }) const [code, codeAttrs] = defineField('code') const [name, nameAttrs] = defineField('name') +const [unit, unitAttrs] = defineField('unit_id') const [employee, employeeAttrs] = defineField('employee_id') const [headStatus, headStatusAttrs] = defineField('headStatus') @@ -62,6 +62,7 @@ const headStatusStr = computed({ if (props.values) { if (props.values.code !== undefined) code.value = props.values.code if (props.values.name !== undefined) name.value = props.values.name + if (props.values.unit_id !== undefined) unit.value = props.values.unit_id ? Number(props.values.unit_id) : null if (props.values.employee_id !== undefined) employee.value = props.values.employee_id ? Number(props.values.employee_id) : null if (props.values.headStatus !== undefined) headStatus.value = !!props.values.headStatus @@ -70,20 +71,18 @@ if (props.values) { const resetForm = () => { code.value = '' name.value = '' + unit.value = null employee.value = null headStatus.value = false } // Form submission handler function onSubmitForm() { - const formData: DivisionPositionFormData = { + const formData: UnitPositionFormData = { ...genBase(), name: name.value || '', code: code.value || '', - - // readonly based on detail division - division_id: props.divisionId, - + unit_id: unit.value || null, employee_id: employee.value || null, headStatus: headStatus.value !== undefined ? headStatus.value : undefined, } @@ -98,7 +97,7 @@ function onCancelForm() {