diff --git a/app/components/app/material/entry-form.vue b/app/components/app/equipment/entry-form.vue similarity index 75% rename from app/components/app/material/entry-form.vue rename to app/components/app/equipment/entry-form.vue index d670f60c..03882cea 100644 --- a/app/components/app/material/entry-form.vue +++ b/app/components/app/equipment/entry-form.vue @@ -5,20 +5,18 @@ import { useForm } from 'vee-validate' // types import type z from 'zod' import type { MaterialFormData } from '~/schemas/material' -// components -import Label from '~/components/pub/custom-ui/form/label.vue' interface Props { - isLoading: boolean schema: z.ZodSchema uoms: any[] items: any[] } +const isLoading = ref(false) const props = defineProps() const emit = defineEmits<{ - back: [] - submit: [data: any] + submit: [values: MaterialFormData, resetForm: () => void] + cancel: [resetForm: () => void] }>() const { handleSubmit, defineField, errors } = useForm({ @@ -38,19 +36,36 @@ const [uom, uomAttrs] = defineField('uom_code') const [item, itemAttrs] = defineField('item_id') const [stock, stockAttrs] = defineField('stock') -const onSubmit = handleSubmit(async (values) => { - try { - emit('submit', values) - } catch (error) { - console.error('Submission failed:', error) +const resetForm = () => { + code.value = '' + name.value = '' + uom.value = '' + item.value = '' + 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) +}