feat(installation): integrate api installation

This commit is contained in:
riefive
2025-10-04 08:30:16 +07:00
parent ce785f2092
commit e78342829e
8 changed files with 534 additions and 268 deletions

No files matched your search

@@ -0,0 +1,125 @@
<script setup lang="ts">
import type { FormErrors } from '~/types/error'
import { toTypedSchema } from '@vee-validate/zod'
import FieldGroup from '~/components/pub/custom-ui/form/field-group.vue'
import Field from '~/components/pub/custom-ui/form/field.vue'
import Label from '~/components/pub/custom-ui/form/label.vue'
import Select from '~/components/pub/custom-ui/form/select.vue'
import { Form } from '~/components/pub/ui/form'
interface InstallationFormData {
name: string
code: string
encounterClassCode: string
}
const props = defineProps<{
installation: {
msg: {
placeholder: string
}
items: {
value: string
label: string
code: string
}[]
}
schema: any
initialValues?: Partial<InstallationFormData>
errors?: FormErrors
}>()
const emit = defineEmits<{
'submit': [values: InstallationFormData, resetForm: () => void]
'cancel': [resetForm: () => void]
}>()
const formSchema = toTypedSchema(props.schema)
// Form submission handler
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) {
const formData: InstallationFormData = {
name: values.name || '',
code: values.code || '',
encounterClassCode: values.encounterClassCode || '',
}
emit('submit', formData, resetForm)
}
// Form cancel handler
function onCancelForm({ resetForm }: { resetForm: () => void }) {
emit('cancel', resetForm)
}
</script>
<template>
<Form
v-slot="{ handleSubmit, resetForm }" as="" keep-values :validation-schema="formSchema"
:initial-values="initialValues"
>
<form id="entry-form" @submit="handleSubmit($event, (values) => onSubmitForm(values, { resetForm }))">
<div class="mb-5 border-b border-b-slate-300 pb-3 text-lg xl:text-xl">
<div class="flex flex-col justify-between">
<FieldGroup>
<Label label-for="name">Nama</Label>
<Field id="name" :errors="errors">
<FormField v-slot="{ componentField }" name="name">
<FormItem>
<FormControl>
<Input
id="name" type="text" placeholder="Masukkan nama instalasi" autocomplete="off"
v-bind="componentField"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</Field>
</FieldGroup>
<FieldGroup>
<Label label-for="code">Kode</Label>
<Field id="code" :errors="errors">
<FormField v-slot="{ componentField }" name="code">
<FormItem>
<FormControl>
<Input id="code" type="text" placeholder="Masukkan kode instalasi" autocomplete="off" v-bind="componentField" />
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</Field>
</FieldGroup>
<FieldGroup>
<Label label-for="parentId">Encounter Class</Label>
<Field id="encounterClassCode" :errors="errors">
<FormField v-slot="{ componentField }" name="encounterClassCode">
<FormItem>
<FormControl>
<Select
v-bind="componentField"
:items="installation.items"
:placeholder="installation.msg.placeholder"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</Field>
</FieldGroup>
</div>
</div>
<div class="flex justify-end gap-2 mt-4">
<Button type="button" variant="outline" @click="onCancelForm({ resetForm })">
Batal
</Button>
<Button type="submit">
Simpan
</Button>
</div>
</form>
</Form>
</template>
+81 -104
View File
@@ -1,125 +1,102 @@
<script setup lang="ts"> <script setup lang="ts">
import type { FormErrors } from '~/types/error' // Components
import { toTypedSchema } from '@vee-validate/zod' import Block from '~/components/pub/custom-ui/doc-entry/block.vue'
import FieldGroup from '~/components/pub/custom-ui/form/field-group.vue' import Cell from '~/components/pub/custom-ui/doc-entry/cell.vue'
import Field from '~/components/pub/custom-ui/form/field.vue' import Field from '~/components/pub/custom-ui/doc-entry/field.vue'
import Label from '~/components/pub/custom-ui/form/label.vue' import Label from '~/components/pub/custom-ui/doc-entry/label.vue'
import Select from '~/components/pub/custom-ui/form/select.vue'
import { Form } from '~/components/pub/ui/form'
interface InstallationFormData { // Types
name: string import type { InstallationFormData } from '~/schemas/installation.schema.ts'
code: string
encounterClassCode: string // Helpers
import type z from 'zod'
import { toTypedSchema } from '@vee-validate/zod'
import { useForm } from 'vee-validate'
interface Props {
schema: z.ZodSchema<any>
values: any
isLoading?: boolean
isReadonly?: boolean
} }
const props = defineProps<{ const props = defineProps<Props>()
installation: { const isLoading = props.isLoading !== undefined ? props.isLoading : false
msg: { const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false
placeholder: string
}
items: {
value: string
label: string
code: string
}[]
}
schema: any
initialValues?: Partial<InstallationFormData>
errors?: FormErrors
}>()
const emit = defineEmits<{ const emit = defineEmits<{
'submit': [values: InstallationFormData, resetForm: () => void] submit: [values: InstallationFormData, resetForm: () => void]
'cancel': [resetForm: () => void] cancel: [resetForm: () => void]
}>() }>()
const formSchema = toTypedSchema(props.schema) const { defineField, errors, meta } = useForm({
validationSchema: toTypedSchema(props.schema),
initialValues: {
code: '',
name: '',
encounterClass_code: '',
} as Partial<InstallationFormData>,
})
const [code, codeAttrs] = defineField('code')
const [name, nameAttrs] = defineField('name')
const [encounterClassCode, encounterClassCodeAttrs] = defineField('encounterClass_code')
// Fill fields from props.values if provided
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.encounterClass_code !== undefined) encounterClassCode.value = props.values.encounterClass_code
}
const resetForm = () => {
code.value = ''
name.value = ''
encounterClassCode.value = ''
}
// Form submission handler // Form submission handler
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) { function onSubmitForm(values: any) {
const formData: InstallationFormData = { const formData: InstallationFormData = {
name: values.name || '', name: name.value || '',
code: values.code || '', code: code.value || '',
encounterClassCode: values.encounterClassCode || '', encounterClass_code: encounterClassCode.value || '',
} }
emit('submit', formData, resetForm) emit('submit', formData, resetForm)
} }
// Form cancel handler // Form cancel handler
function onCancelForm({ resetForm }: { resetForm: () => void }) { function onCancelForm() {
emit('cancel', resetForm) emit('cancel', resetForm)
} }
</script> </script>
<template> <template>
<Form <form id="form-unit" @submit.prevent>
v-slot="{ handleSubmit, resetForm }" as="" keep-values :validation-schema="formSchema" <Block labelSize="thin" class="!mb-2.5 !pt-0 xl:!mb-3" :colCount="1">
:initial-values="initialValues" <Cell>
> <Label height="compact">Kode</Label>
<form id="entry-form" @submit="handleSubmit($event, (values) => onSubmitForm(values, { resetForm }))"> <Field :errMessage="errors.code">
<div class="mb-5 border-b border-b-slate-300 pb-3 text-lg xl:text-xl"> <Input id="code" v-model="code" v-bind="codeAttrs" :disabled="isLoading || isReadonly" />
<div class="flex flex-col justify-between"> </Field>
<FieldGroup> </Cell>
<Label label-for="name">Nama</Label> <Cell>
<Field id="name" :errors="errors"> <Label height="compact">Nama</Label>
<FormField v-slot="{ componentField }" name="name"> <Field :errMessage="errors.name">
<FormItem> <Input id="name" v-model="name" v-bind="nameAttrs" :disabled="isLoading || isReadonly" />
<FormControl> </Field>
<Input </Cell>
id="name" type="text" placeholder="Masukkan nama instalasi" autocomplete="off" </Block>
v-bind="componentField" <div class="my-2 flex justify-end gap-2 py-2">
/> <Button type="button" variant="secondary" class="w-[120px]" @click="onCancelForm"> Kembali </Button>
</FormControl> <Button
<FormMessage /> v-if="!isReadonly"
</FormItem> type="button"
</FormField> class="w-[120px]"
</Field> :disabled="isLoading || !meta.valid"
</FieldGroup> @click="onSubmitForm"
>
<FieldGroup> Simpan
<Label label-for="code">Kode</Label> </Button>
<Field id="code" :errors="errors"> </div>
<FormField v-slot="{ componentField }" name="code"> </form>
<FormItem>
<FormControl>
<Input id="code" type="text" placeholder="Masukkan kode instalasi" autocomplete="off" v-bind="componentField" />
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</Field>
</FieldGroup>
<FieldGroup>
<Label label-for="parentId">Encounter Class</Label>
<Field id="encounterClassCode" :errors="errors">
<FormField v-slot="{ componentField }" name="encounterClassCode">
<FormItem>
<FormControl>
<Select
v-bind="componentField"
:items="installation.items"
:placeholder="installation.msg.placeholder"
/>
</FormControl>
<FormMessage />
</FormItem>
</FormField>
</Field>
</FieldGroup>
</div>
</div>
<div class="flex justify-end gap-2 mt-4">
<Button type="button" variant="outline" @click="onCancelForm({ resetForm })">
Batal
</Button>
<Button type="submit">
Simpan
</Button>
</div>
</form>
</Form>
</template> </template>
+4 -21
View File
@@ -12,13 +12,11 @@ type SmallDetailDto = any
const action = defineAsyncComponent(() => import('~/components/pub/custom-ui/data/dropdown-action-ud.vue')) const action = defineAsyncComponent(() => import('~/components/pub/custom-ui/data/dropdown-action-ud.vue'))
export const cols: Col[] = [{ width: 100 }, {}, {}, {}, { width: 50 }] export const cols: Col[] = [{}, {}, {}, { width: 50 }]
export const header: Th[][] = [ export const header: Th[][] = [[{ label: 'Kode' }, { label: 'Nama' }, { label: 'Encounter Class' }, { label: '' }]]
[{ label: 'Id' }, { label: 'Nama' }, { label: 'Kode' }, { label: 'Encounter Class' }, { label: '' }],
]
export const keys = ['id', 'name', 'cellphone', 'religion_code', 'action'] export const keys = ['code', 'name', 'encounterClass_code', 'action']
export const delKeyNames: KeyLabel[] = [ export const delKeyNames: KeyLabel[] = [
{ key: 'code', label: 'Kode' }, { key: 'code', label: 'Kode' },
@@ -28,22 +26,7 @@ export const delKeyNames: KeyLabel[] = [
export const funcParsed: RecStrFuncUnknown = { export const funcParsed: RecStrFuncUnknown = {
name: (rec: unknown): unknown => { name: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto const recX = rec as SmallDetailDto
return `${recX.firstName} ${recX.lastName || ''}`.trim() return `${recX.name}`.trim()
},
identity_number: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto
if (recX.identity_number?.substring(0, 5) === 'BLANK') {
return '(TANPA NIK)'
}
return recX.identity_number
},
inPatient_itemPrice: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto
return Number(recX.inPatient_itemPrice.price).toLocaleString('id-ID')
},
outPatient_itemPrice: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto
return Number(recX.outPatient_itemPrice.price).toLocaleString('id-ID')
}, },
} }
+8 -3
View File
@@ -22,10 +22,15 @@ function handlePageChange(page: number) {
<template> <template>
<div class="space-y-4"> <div class="space-y-4">
<PubBaseDataTable <PubBaseDataTable
:rows="data" :cols="cols" :header="header" :keys="keys" :func-parsed="funcParsed" :rows="data"
:func-html="funcHtml" :func-component="funcComponent" :skeleton-size="paginationMeta?.pageSize" :cols="cols"
:header="header"
:keys="keys"
:func-parsed="funcParsed"
:func-html="funcHtml"
:func-component="funcComponent"
:skeleton-size="paginationMeta?.pageSize"
/> />
<PaginationView :pagination-meta="paginationMeta" @page-change="handlePageChange" /> <PaginationView :pagination-meta="paginationMeta" @page-change="handlePageChange" />
</div> </div>
</template> </template>
@@ -0,0 +1,206 @@
<script setup lang="ts">
import type { HeaderPrep } from '~/components/pub/custom-ui/data/types'
import AppInstallationEntryForm from '~/components/app/installation/entry-form.vue'
import Dialog from '~/components/pub/base/modal/dialog.vue'
import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue'
import { ActionEvents } from '~/components/pub/custom-ui/data/types'
import Header from '~/components/pub/custom-ui/nav-header/header.vue'
import { transform, usePaginatedList } from '~/composables/usePaginatedList'
import { installationConf, schemaConf } from './entry'
// #region State & Computed
// Dialog state
const isFormEntryDialogOpen = ref(false)
const isRecordConfirmationOpen = ref(false)
// Table action rowId provider
const recId = ref<number>(0)
const recAction = ref<string>('')
const recItem = ref<any>(null)
// Fungsi untuk fetch data installation
async function fetchInstallationData(params: any) {
// Prepare query parameters for pagination and search
const endpoint = transform('/api/v1/patient', params)
return await xfetch(endpoint)
}
// Menggunakan composable untuk pagination
const {
data,
isLoading,
paginationMeta,
searchInput,
handlePageChange,
handleSearch,
fetchData: getInstallationList,
} = usePaginatedList({
fetchFn: fetchInstallationData,
entityName: 'installation',
})
const headerPrep: HeaderPrep = {
title: 'Instalasi',
icon: 'i-lucide-box',
refSearchNav: {
placeholder: 'Cari (min. 3 karakter)...',
minLength: 3,
debounceMs: 500,
showValidationFeedback: true,
onInput: (_val: string) => {
// Handle search input - this will be triggered by the header component
},
onClick: () => {
// Handle search button click if needed
},
onClear: () => {
// Handle search clear
},
},
addNav: {
label: 'Tambah Instalasi',
icon: 'i-lucide-send',
onClick: () => {
isFormEntryDialogOpen.value = true
},
},
}
provide('rec_id', recId)
provide('rec_action', recAction)
provide('rec_item', recItem)
provide('table_data_loader', isLoading)
// #endregion
// #region Functions
async function handleDeleteRow(record: any) {
try {
// TODO : hit backend request untuk delete
console.log('Deleting record:', record)
// Simulate API call
// const response = await xfetch(`/api/v1/Installation/${record.id}`, {
// method: 'DELETE'
// })
// Refresh data setelah berhasil delete
await getInstallationList()
// 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
}
}
// #endregion region
// #region Form event handlers
function onCancelForm(resetForm: () => void) {
isFormEntryDialogOpen.value = false
setTimeout(() => {
resetForm()
}, 500)
}
async function onSubmitForm(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/Installation', {
// 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 getInstallationList()
// TODO: Show success message
console.log('Installation 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)
}
}
}
// #endregion
// #region Watchers
// Watch for row actions
watch(recId, () => {
switch (recAction.value) {
case ActionEvents.showEdit:
// TODO: Handle edit action
// isFormEntryDialogOpen.value = true
break
case ActionEvents.showConfirmDelete:
// Trigger confirmation modal open
isRecordConfirmationOpen.value = true
break
}
})
// Handle confirmation result
function handleConfirmDelete(record: any, action: string) {
console.log('Confirmed action:', action, 'for record:', record)
handleDeleteRow(record)
}
function handleCancelConfirmation() {
// Reset record state when cancelled
recId.value = 0
recAction.value = ''
recItem.value = null
}
// #endregion
</script>
<template>
<Header v-model="searchInput" :prep="headerPrep" @search="handleSearch" />
<AppInstallationList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
<Dialog v-model:open="isFormEntryDialogOpen" title="Tambah Instalasi" size="lg" prevent-outside>
<AppInstallationEntryFormPrev :installation="installationConf" :schema="schemaConf"
:initial-values="{ name: '', code: '', encounterClassCode: '' }" @submit="onSubmitForm"
@cancel="onCancelForm" />
</Dialog>
<!-- Record Confirmation Modal -->
<RecordConfirmation v-model:open="isRecordConfirmationOpen" action="delete" :record="recItem"
@confirm="handleConfirmDelete" @cancel="handleCancelConfirmation">
<template #default="{ record }">
<div class="text-sm">
<p><strong>ID:</strong> {{ record?.id }}</p>
<p v-if="record?.firstName"><strong>Nama:</strong> {{ record.firstName }}</p>
<p v-if="record?.code"><strong>Kode:</strong> {{ record.cellphone }}</p>
</div>
</template>
</RecordConfirmation>
</template>
<style scoped>
/* component style */
</style>
+99 -138
View File
@@ -1,31 +1,39 @@
<script setup lang="ts"> <script setup lang="ts">
import type { HeaderPrep } from '~/components/pub/custom-ui/data/types' // Components
import AppInstallationEntryForm from '~/components/app/installation/entry-form.vue'
import Dialog from '~/components/pub/base/modal/dialog.vue' import Dialog from '~/components/pub/base/modal/dialog.vue'
import Header from '~/components/pub/custom-ui/nav-header/prep.vue'
import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue' import RecordConfirmation from '~/components/pub/custom-ui/confirmation/record-confirmation.vue'
import { ActionEvents } from '~/components/pub/custom-ui/data/types' import AppInstallationList from '~/components/app/installation/list.vue'
import Header from '~/components/pub/custom-ui/nav-header/header.vue' import AppInstallationEntryForm from '~/components/app/installation/entry-form.vue'
import { transform, usePaginatedList } from '~/composables/usePaginatedList'
import { installationConf, schemaConf } from './entry'
// #region State & Computed // Helpers
// Dialog state import { usePaginatedList } from '~/composables/usePaginatedList'
const isFormEntryDialogOpen = ref(false) import { toast } from '~/components/pub/ui/toast'
const isRecordConfirmationOpen = ref(false)
// Table action rowId provider // Types
const recId = ref<number>(0) import { ActionEvents, type HeaderPrep } from '~/components/pub/custom-ui/data/types'
const recAction = ref<string>('') import { InstallationSchema, type InstallationFormData } from '~/schemas/installation.schema'
const recItem = ref<any>(null)
// Fungsi untuk fetch data installation // Handlers
async function fetchInstallationData(params: any) { import {
// Prepare query parameters for pagination and search recId,
const endpoint = transform('/api/v1/patient', params) recAction,
return await xfetch(endpoint) recItem,
} isReadonly,
isProcessing,
isFormEntryDialogOpen,
isRecordConfirmationOpen,
handleActionSave,
handleActionEdit,
handleActionRemove,
handleCancelForm,
} from '~/handlers/installation.handler'
// Services
import { getInstallations, getInstallationDetail } from '~/services/installation.service'
const title = ref('')
// Menggunakan composable untuk pagination
const { const {
data, data,
isLoading, isLoading,
@@ -35,7 +43,10 @@ const {
handleSearch, handleSearch,
fetchData: getInstallationList, fetchData: getInstallationList,
} = usePaginatedList({ } = usePaginatedList({
fetchFn: fetchInstallationData, fetchFn: async ({ page, search }) => {
const result = await getInstallations({ search, page })
return { success: result.success || false, body: result.body || {} }
},
entityName: 'installation', entityName: 'installation',
}) })
@@ -47,21 +58,20 @@ const headerPrep: HeaderPrep = {
minLength: 3, minLength: 3,
debounceMs: 500, debounceMs: 500,
showValidationFeedback: true, showValidationFeedback: true,
onInput: (_val: string) => { onInput: (value: string) => {
// Handle search input - this will be triggered by the header component searchInput.value = value
},
onClick: () => {
// Handle search button click if needed
},
onClear: () => {
// Handle search clear
}, },
onClick: () => {},
onClear: () => {},
}, },
addNav: { addNav: {
label: 'Tambah Instalasi', label: 'Tambah',
icon: 'i-lucide-send', icon: 'i-lucide-plus',
onClick: () => { onClick: () => {
recItem.value = null
recId.value = 0
isFormEntryDialogOpen.value = true isFormEntryDialogOpen.value = true
isReadonly.value = false
}, },
}, },
} }
@@ -70,137 +80,88 @@ provide('rec_id', recId)
provide('rec_action', recAction) provide('rec_action', recAction)
provide('rec_item', recItem) provide('rec_item', recItem)
provide('table_data_loader', isLoading) provide('table_data_loader', isLoading)
// #endregion
// #region Functions const getCurrentInstallationDetail = async (id: number | string) => {
const result = await getInstallationDetail(id)
async function handleDeleteRow(record: any) { if (result.success) {
try { const currentValue = result.body?.data || {}
// TODO : hit backend request untuk delete recItem.value = currentValue
console.log('Deleting record:', record) isFormEntryDialogOpen.value = true
// Simulate API call
// const response = await xfetch(`/api/v1/Installation/${record.id}`, {
// method: 'DELETE'
// })
// Refresh data setelah berhasil delete
await getInstallationList()
// 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
} }
} }
// #endregion region // Watch for row actions when recId or recAction changes
watch([recId, recAction], () => {
// #region Form event handlers
function onCancelForm(resetForm: () => void) {
isFormEntryDialogOpen.value = false
setTimeout(() => {
resetForm()
}, 500)
}
async function onSubmitForm(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/Installation', {
// 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 getInstallationList()
// TODO: Show success message
console.log('Installation 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)
}
}
}
// #endregion
// #region Watchers
// Watch for row actions
watch(recId, () => {
switch (recAction.value) { switch (recAction.value) {
case ActionEvents.showDetail:
getCurrentInstallationDetail(recId.value)
title.value = 'Detail Instalasi'
isReadonly.value = true
break
case ActionEvents.showEdit: case ActionEvents.showEdit:
// TODO: Handle edit action getCurrentInstallationDetail(recId.value)
// isFormEntryDialogOpen.value = true title.value = 'Edit Instalasi'
isReadonly.value = false
break break
case ActionEvents.showConfirmDelete: case ActionEvents.showConfirmDelete:
// Trigger confirmation modal open
isRecordConfirmationOpen.value = true isRecordConfirmationOpen.value = true
break break
} }
}) })
// Handle confirmation result onMounted(async () => {
function handleConfirmDelete(record: any, action: string) { await getInstallationList()
console.log('Confirmed action:', action, 'for record:', record) })
handleDeleteRow(record)
}
function handleCancelConfirmation() {
// Reset record state when cancelled
recId.value = 0
recAction.value = ''
recItem.value = null
}
// #endregion
</script> </script>
<template> <template>
<Header v-model="searchInput" :prep="headerPrep" @search="handleSearch" /> <Header
v-model="searchInput"
:prep="headerPrep"
:ref-search-nav="headerPrep.refSearchNav"
@search="handleSearch"
class="mb-4 xl:mb-5"
/>
<AppInstallationList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" /> <AppInstallationList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
<Dialog v-model:open="isFormEntryDialogOpen" title="Tambah Instalasi" size="lg" prevent-outside> <Dialog
<AppInstallationEntryForm :installation="installationConf" :schema="schemaConf" v-model:open="isFormEntryDialogOpen"
:initial-values="{ name: '', code: '', encounterClassCode: '' }" @submit="onSubmitForm" :title="!!recItem ? title : 'Tambah Instalasi'"
@cancel="onCancelForm" /> size="lg"
prevent-outside
>
<AppInstallationEntryForm
:schema="InstallationSchema"
:values="recItem"
:is-loading="isProcessing"
:is-readonly="isReadonly"
@submit="
(values: InstallationFormData | Record<string, any>, resetForm: () => void) => {
if (recId > 0) {
handleActionEdit(recId, values, getInstallationList, resetForm, toast)
return
}
handleActionSave(values, getInstallationList, resetForm, toast)
}
"
@cancel="handleCancelForm"
/>
</Dialog> </Dialog>
<!-- Record Confirmation Modal --> <!-- Record Confirmation Modal -->
<RecordConfirmation v-model:open="isRecordConfirmationOpen" action="delete" :record="recItem" <RecordConfirmation
@confirm="handleConfirmDelete" @cancel="handleCancelConfirmation"> v-model:open="isRecordConfirmationOpen"
action="delete"
:record="recItem"
@confirm="() => handleActionRemove(recId, getInstallationList, toast)"
@cancel=""
>
<template #default="{ record }"> <template #default="{ record }">
<div class="text-sm"> <div class="text-sm">
<p><strong>ID:</strong> {{ record?.id }}</p> <p><strong>ID:</strong> {{ record?.id }}</p>
<p v-if="record?.firstName"><strong>Nama:</strong> {{ record.firstName }}</p> <p v-if="record?.name"><strong>Nama:</strong> {{ record.name }}</p>
<p v-if="record?.code"><strong>Kode:</strong> {{ record.cellphone }}</p> <p v-if="record?.code"><strong>Kode:</strong> {{ record.code }}</p>
</div> </div>
</template> </template>
</RecordConfirmation> </RecordConfirmation>
</template> </template>
<style scoped>
/* component style */
</style>
+1 -1
View File
@@ -1,5 +1,5 @@
export interface Installation { export interface Installation {
code: string code: string
name: string name: string
encounterClass_code: string encounterClass_code?: string | null
} }
+9
View File
@@ -0,0 +1,9 @@
import { z } from 'zod'
export const InstallationSchema = z.object({
code: z.string().min(1, 'Kode wajib diisi'),
name: z.string().min(1, 'Nama wajib diisi'),
encounterClass_code: z.string().min(1, 'Encounter Class wajib diisi').optional(),
})
export type InstallationFormData = z.infer<typeof InstallationSchema>