From 70378a69e9b05d8ce2b92d2e48a71f0f7478b755 Mon Sep 17 00:00:00 2001 From: riefive Date: Fri, 19 Sep 2025 15:23:09 +0700 Subject: [PATCH] feat(material): modify handlers and service of material --- app/components/app/equipment/entry-form.vue | 19 --- app/components/content/equipment/list.vue | 135 ++++++-------------- app/handlers/material.handler.ts | 80 ++++++++++++ app/models/equipment-material.ts | 6 - app/models/material.ts | 6 + app/models/uom.ts | 4 + app/schemas/material.ts | 4 +- app/services/material.service.ts | 87 +++++++++++++ app/services/source-material.service.ts | 9 -- app/services/source-uom.service.ts | 9 -- app/services/uom.service.ts | 27 ++++ 11 files changed, 244 insertions(+), 142 deletions(-) create mode 100644 app/handlers/material.handler.ts delete mode 100644 app/models/equipment-material.ts create mode 100644 app/models/material.ts create mode 100644 app/models/uom.ts create mode 100644 app/services/material.service.ts delete mode 100644 app/services/source-material.service.ts delete mode 100644 app/services/source-uom.service.ts create mode 100644 app/services/uom.service.ts diff --git a/app/components/app/equipment/entry-form.vue b/app/components/app/equipment/entry-form.vue index 759f011d..0bcb6e5f 100644 --- a/app/components/app/equipment/entry-form.vue +++ b/app/components/app/equipment/entry-form.vue @@ -45,19 +45,16 @@ const resetForm = () => { stock.value = 0 } -// Form submission handler function onSubmitForm(values: any) { const formData: MaterialFormData = { name: values.name || '', code: values.code || '', uom_code: values.uom_code || '', - item_id: values.item_id || '', stock: values.stock || 0, } emit('submit', formData, resetForm) } -// Form cancel handler function onCancelForm() { emit('cancel', resetForm) } @@ -107,22 +104,6 @@ function onCancelForm() { {{ errors.uom_code }} -
- - (0) -const recAction = ref('') -const recItem = ref(null) +// Services +import { getSourceMaterials, getSourceMaterialDetail } from '~/services/material.service' +import { getSourceUoms } from '~/services/uom.service' const uoms = [ { value: 'uom-1', label: 'Satuan 1' }, @@ -28,7 +34,14 @@ const items = [ { value: 'item-3', label: 'Item 3' }, ] -// Menggunakan composable untuk pagination +const getEquipmentDetail = async (id: number | string) => { + const result = await getSourceMaterialDetail(id) + if (result.success) { + recItem.value = result.data + isFormEntryDialogOpen.value = true + } +} + const { data, isLoading, @@ -38,7 +51,7 @@ const { handleSearch, fetchData: getEquipmentList, } = usePaginatedList({ - fetchFn: getSourceMaterials, + fetchFn: getSourceMaterials as any, entityName: 'equipment', }) @@ -78,96 +91,14 @@ provide('table_data_loader', isLoading) watch(recId, () => { switch (recAction.value) { case ActionEvents.showEdit: - // TODO: Handle edit action - // isFormEntryDialogOpen.value = true + getEquipmentDetail(recId.value) break case ActionEvents.showConfirmDelete: - // Trigger confirmation modal open isRecordConfirmationOpen.value = true break } }) -const handleDeleteRow = async (record: any) => { - try { - // TODO : hit backend request untuk delete - console.log('Deleting record:', record) - // Simulate API call - // const response = await xfetch(`/api/v1/division/${record.id}`, { - // method: 'DELETE' - // }) - - // Refresh data setelah berhasil delete - await getEquipmentList() - - // 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 - } -} - -const onCancelForm = (resetForm: () => void) => { - isFormEntryDialogOpen.value = false - setTimeout(() => { - resetForm() - }, 500) -} - -const onSubmitForm = async (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/division', { - // method: 'POST', - // body: JSON.stringify(values) - // }) - - // If successful, mark as success and close dialog - isFormEntryDialogOpen.value = false - isSuccess = true - - // Refresh data after successful submission - await getEquipmentList() - - // TODO: Show success message - console.log('Division 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) - } - } -} - -// Handle confirmation result -const handleConfirmDelete = (record: any, action: string) => { - console.log('Confirmed action:', action, 'for record:', record) - handleDeleteRow(record) -} - -const handleCancelConfirmation = () => { - // Reset record state when cancelled - recId.value = 0 - recAction.value = '' - recItem.value = null -} - onMounted(async () => { await getSourceUoms() }) @@ -181,13 +112,23 @@ onMounted(async () => {
- + - +