feat(subspecialist): finishing integrate specialist
This commit is contained in:
@@ -30,7 +30,7 @@ export const funcParsed: RecStrFuncUnknown = {
|
|||||||
},
|
},
|
||||||
unit: (rec: unknown): unknown => {
|
unit: (rec: unknown): unknown => {
|
||||||
const recX = rec as SmallDetailDto
|
const recX = rec as SmallDetailDto
|
||||||
return `${recX.unit_id}`
|
return recX.unit_id || '-'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,213 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { FormErrors } from '~/types/error'
|
||||||
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
|
import Combobox from '~/components/pub/custom-ui/form/combobox.vue'
|
||||||
|
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'
|
||||||
|
|
||||||
|
interface SubSpecialistFormData {
|
||||||
|
name: string
|
||||||
|
code: string
|
||||||
|
installationId: string
|
||||||
|
unitId: string
|
||||||
|
specialistId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
schema: any
|
||||||
|
initialValues?: Partial<SubSpecialistFormData>
|
||||||
|
errors?: FormErrors
|
||||||
|
installation: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
unit: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
specialist: {
|
||||||
|
msg: {
|
||||||
|
placeholder: string
|
||||||
|
search: string
|
||||||
|
empty: string
|
||||||
|
}
|
||||||
|
items: {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
code: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'submit': [values: SubSpecialistFormData, resetForm: () => void]
|
||||||
|
'cancel': [resetForm: () => void]
|
||||||
|
'installationChanged': [id: string]
|
||||||
|
'unitChanged': [id: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const formSchema = toTypedSchema(props.schema)
|
||||||
|
|
||||||
|
// Form submission handler
|
||||||
|
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) {
|
||||||
|
const formData: SubSpecialistFormData = {
|
||||||
|
name: values.name || '',
|
||||||
|
code: values.code || '',
|
||||||
|
installationId: values.installationId || '',
|
||||||
|
unitId: values.unitId || '',
|
||||||
|
specialistId: values.specialistId || '',
|
||||||
|
}
|
||||||
|
emit('submit', formData, resetForm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form cancel handler
|
||||||
|
function onCancelForm({ resetForm }: { resetForm: () => void }) {
|
||||||
|
emit('cancel', resetForm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watch for installation changes
|
||||||
|
function onInstallationChanged(installationId: string, setFieldValue: any) {
|
||||||
|
setFieldValue('unitId', '', false)
|
||||||
|
setFieldValue('specialistId', '', false)
|
||||||
|
emit('installationChanged', installationId || '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUnitChanged(unitId: string, setFieldValue: any) {
|
||||||
|
setFieldValue('specialistId', '', false)
|
||||||
|
emit('unitChanged', unitId || '')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Form
|
||||||
|
v-slot="{
|
||||||
|
handleSubmit,
|
||||||
|
resetForm,
|
||||||
|
values,
|
||||||
|
setFieldValue,
|
||||||
|
}" 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 spesialisasi" 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 spesialisasi" autocomplete="off"
|
||||||
|
v-bind="componentField"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="installationId">Instalasi</Label>
|
||||||
|
<Field id="installationId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="installationId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="installationId" v-bind="componentField" :items="installation.items"
|
||||||
|
:placeholder="installation.msg.placeholder" :search-placeholder="installation.msg.search"
|
||||||
|
:empty-message="installation.msg.empty"
|
||||||
|
@update:model-value="(value) => onInstallationChanged(value, setFieldValue)"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="unitId">Unit</Label>
|
||||||
|
<Field id="unitId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="unitId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="unitId" :disabled="!values.installationId" v-bind="componentField" :items="unit.items"
|
||||||
|
:placeholder="unit.msg.placeholder" :search-placeholder="unit.msg.search"
|
||||||
|
:empty-message="unit.msg.empty"
|
||||||
|
@update:model-value="(value) => onUnitChanged(value, setFieldValue)"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
|
</Field>
|
||||||
|
</FieldGroup>
|
||||||
|
|
||||||
|
<FieldGroup>
|
||||||
|
<Label label-for="specialistId">Specialist</Label>
|
||||||
|
<Field id="specialistId" :errors="errors">
|
||||||
|
<FormField v-slot="{ componentField }" name="specialistId">
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<Combobox
|
||||||
|
id="specialistId" :disabled="!values.unitId" v-bind="componentField" :items="specialist.items"
|
||||||
|
:placeholder="specialist.msg.placeholder" :search-placeholder="specialist.msg.search"
|
||||||
|
:empty-message="specialist.msg.empty"
|
||||||
|
/>
|
||||||
|
</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>
|
||||||
@@ -1,213 +1,128 @@
|
|||||||
<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 Combobox from '~/components/pub/custom-ui/form/combobox.vue'
|
import Cell from '~/components/pub/custom-ui/doc-entry/cell.vue'
|
||||||
import FieldGroup from '~/components/pub/custom-ui/form/field-group.vue'
|
import Field from '~/components/pub/custom-ui/doc-entry/field.vue'
|
||||||
import Field from '~/components/pub/custom-ui/form/field.vue'
|
import Label from '~/components/pub/custom-ui/doc-entry/label.vue'
|
||||||
import Label from '~/components/pub/custom-ui/form/label.vue'
|
// import Combobox from '~/components/pub/custom-ui/form/combobox.vue'
|
||||||
|
|
||||||
interface SubSpecialistFormData {
|
// Types
|
||||||
name: string
|
import type { SubspecialistFormData } from '~/schemas/subspecialist.schema.ts'
|
||||||
code: string
|
|
||||||
installationId: string
|
// Helpers
|
||||||
unitId: string
|
import type z from 'zod'
|
||||||
specialistId: string
|
import { toTypedSchema } from '@vee-validate/zod'
|
||||||
|
import { useForm } from 'vee-validate'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
schema: z.ZodSchema<any>
|
||||||
|
specialists: any[]
|
||||||
|
values: any
|
||||||
|
isLoading?: boolean
|
||||||
|
isReadonly?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<Props>()
|
||||||
schema: any
|
const isLoading = props.isLoading !== undefined ? props.isLoading : false
|
||||||
initialValues?: Partial<SubSpecialistFormData>
|
const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false
|
||||||
errors?: FormErrors
|
|
||||||
installation: {
|
|
||||||
msg: {
|
|
||||||
placeholder: string
|
|
||||||
search: string
|
|
||||||
empty: string
|
|
||||||
}
|
|
||||||
items: {
|
|
||||||
value: string
|
|
||||||
label: string
|
|
||||||
code: string
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
unit: {
|
|
||||||
msg: {
|
|
||||||
placeholder: string
|
|
||||||
search: string
|
|
||||||
empty: string
|
|
||||||
}
|
|
||||||
items: {
|
|
||||||
value: string
|
|
||||||
label: string
|
|
||||||
code: string
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
specialist: {
|
|
||||||
msg: {
|
|
||||||
placeholder: string
|
|
||||||
search: string
|
|
||||||
empty: string
|
|
||||||
}
|
|
||||||
items: {
|
|
||||||
value: string
|
|
||||||
label: string
|
|
||||||
code: string
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
'submit': [values: SubSpecialistFormData, resetForm: () => void]
|
submit: [values: SubspecialistFormData, resetForm: () => void]
|
||||||
'cancel': [resetForm: () => void]
|
cancel: [resetForm: () => void]
|
||||||
'installationChanged': [id: string]
|
|
||||||
'unitChanged': [id: string]
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const formSchema = toTypedSchema(props.schema)
|
const { defineField, errors, meta } = useForm({
|
||||||
|
validationSchema: toTypedSchema(props.schema),
|
||||||
|
initialValues: {
|
||||||
|
code: '',
|
||||||
|
name: '',
|
||||||
|
specialist_id: 0,
|
||||||
|
} as Partial<SubspecialistFormData>,
|
||||||
|
})
|
||||||
|
|
||||||
|
const [code, codeAttrs] = defineField('code')
|
||||||
|
const [name, nameAttrs] = defineField('name')
|
||||||
|
const [specialist, specialistAttrs] = defineField('specialist_id')
|
||||||
|
|
||||||
|
// 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.specialist_id !== undefined) specialist.value = props.values.specialist_id
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
code.value = ''
|
||||||
|
name.value = ''
|
||||||
|
specialist.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
// Form submission handler
|
// Form submission handler
|
||||||
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) {
|
function onSubmitForm(values: any) {
|
||||||
const formData: SubSpecialistFormData = {
|
const formData: SubspecialistFormData = {
|
||||||
name: values.name || '',
|
name: name.value || '',
|
||||||
code: values.code || '',
|
code: code.value || '',
|
||||||
installationId: values.installationId || '',
|
specialist_id: specialist.value || '',
|
||||||
unitId: values.unitId || '',
|
|
||||||
specialistId: values.specialistId || '',
|
|
||||||
}
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch for installation changes
|
|
||||||
function onInstallationChanged(installationId: string, setFieldValue: any) {
|
|
||||||
setFieldValue('unitId', '', false)
|
|
||||||
setFieldValue('specialistId', '', false)
|
|
||||||
emit('installationChanged', installationId || '')
|
|
||||||
}
|
|
||||||
|
|
||||||
function onUnitChanged(unitId: string, setFieldValue: any) {
|
|
||||||
setFieldValue('specialistId', '', false)
|
|
||||||
emit('unitChanged', unitId || '')
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Form
|
<form id="form-specialist" @submit.prevent>
|
||||||
v-slot="{
|
<Block labelSize="thin" class="!mb-2.5 !pt-0 xl:!mb-3" :colCount="1">
|
||||||
handleSubmit,
|
<Cell>
|
||||||
resetForm,
|
<Label height="compact">Kode</Label>
|
||||||
values,
|
<Field :errMessage="errors.code">
|
||||||
setFieldValue,
|
<Input id="code" v-model="code" v-bind="codeAttrs" :disabled="isLoading || isReadonly" />
|
||||||
}" as="" keep-values :validation-schema="formSchema"
|
</Field>
|
||||||
:initial-values="initialValues"
|
</Cell>
|
||||||
>
|
<Cell>
|
||||||
<form id="entry-form" @submit="handleSubmit($event, (values) => onSubmitForm(values, { resetForm }))">
|
<Label height="compact">Nama</Label>
|
||||||
<div class="mb-5 border-b border-b-slate-300 pb-3 text-lg xl:text-xl">
|
<Field :errMessage="errors.name">
|
||||||
<div class="flex flex-col justify-between">
|
<Input id="name" v-model="name" v-bind="nameAttrs" :disabled="isLoading || isReadonly" />
|
||||||
<FieldGroup>
|
</Field>
|
||||||
<Label label-for="name">Nama</Label>
|
</Cell>
|
||||||
<Field id="name" :errors="errors">
|
<Cell>
|
||||||
<FormField v-slot="{ componentField }" name="name">
|
<Label height="compact">Spesialis</Label>
|
||||||
<FormItem>
|
<Field :errMessage="errors.specialist">
|
||||||
<FormControl>
|
<!-- <Combobox
|
||||||
<Input
|
id="specialis"
|
||||||
id="name" type="text" placeholder="Masukkan nama spesialisasi" autocomplete="off"
|
placeholder="Pilih spesialis"
|
||||||
v-bind="componentField"
|
search-placeholder="Cari spesialis"
|
||||||
/>
|
empty-message="Spesialis tidak ditemukan"
|
||||||
</FormControl>
|
v-model="specialist"
|
||||||
<FormMessage />
|
v-bind="specialistAttrs"
|
||||||
</FormItem>
|
:items="specialists"
|
||||||
</FormField>
|
:disabled="isLoading || isReadonly"
|
||||||
</Field>
|
/> -->
|
||||||
</FieldGroup>
|
<Select
|
||||||
|
id="specialist"
|
||||||
<FieldGroup>
|
icon-name="i-lucide-chevron-down"
|
||||||
<Label label-for="code">Kode</Label>
|
placeholder="Pilih spesialis"
|
||||||
<Field id="code" :errors="errors">
|
v-model="specialist"
|
||||||
<FormField v-slot="{ componentField }" name="code">
|
v-bind="specialistAttrs"
|
||||||
<FormItem>
|
:items="specialists"
|
||||||
<FormControl>
|
:disabled="isLoading || isReadonly"
|
||||||
<Input
|
/>
|
||||||
id="code" type="text" placeholder="Masukkan kode spesialisasi" autocomplete="off"
|
</Field>
|
||||||
v-bind="componentField"
|
</Cell>
|
||||||
/>
|
</Block>
|
||||||
</FormControl>
|
<div class="my-2 flex justify-end gap-2 py-2">
|
||||||
<FormMessage />
|
<Button type="button" variant="secondary" class="w-[120px]" @click="onCancelForm"> Kembali </Button>
|
||||||
</FormItem>
|
<Button
|
||||||
</FormField>
|
v-if="!isReadonly"
|
||||||
</Field>
|
type="button"
|
||||||
</FieldGroup>
|
class="w-[120px]"
|
||||||
|
:disabled="isLoading || !meta.valid"
|
||||||
<FieldGroup>
|
@click="onSubmitForm"
|
||||||
<Label label-for="installationId">Instalasi</Label>
|
>
|
||||||
<Field id="installationId" :errors="errors">
|
Simpan
|
||||||
<FormField v-slot="{ componentField }" name="installationId">
|
</Button>
|
||||||
<FormItem>
|
</div>
|
||||||
<FormControl>
|
</form>
|
||||||
<Combobox
|
|
||||||
id="installationId" v-bind="componentField" :items="installation.items"
|
|
||||||
:placeholder="installation.msg.placeholder" :search-placeholder="installation.msg.search"
|
|
||||||
:empty-message="installation.msg.empty"
|
|
||||||
@update:model-value="(value) => onInstallationChanged(value, setFieldValue)"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
</FormField>
|
|
||||||
</Field>
|
|
||||||
</FieldGroup>
|
|
||||||
|
|
||||||
<FieldGroup>
|
|
||||||
<Label label-for="unitId">Unit</Label>
|
|
||||||
<Field id="unitId" :errors="errors">
|
|
||||||
<FormField v-slot="{ componentField }" name="unitId">
|
|
||||||
<FormItem>
|
|
||||||
<FormControl>
|
|
||||||
<Combobox
|
|
||||||
id="unitId" :disabled="!values.installationId" v-bind="componentField" :items="unit.items"
|
|
||||||
:placeholder="unit.msg.placeholder" :search-placeholder="unit.msg.search"
|
|
||||||
:empty-message="unit.msg.empty"
|
|
||||||
@update:model-value="(value) => onUnitChanged(value, setFieldValue)"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
</FormField>
|
|
||||||
</Field>
|
|
||||||
</FieldGroup>
|
|
||||||
|
|
||||||
<FieldGroup>
|
|
||||||
<Label label-for="specialistId">Specialist</Label>
|
|
||||||
<Field id="specialistId" :errors="errors">
|
|
||||||
<FormField v-slot="{ componentField }" name="specialistId">
|
|
||||||
<FormItem>
|
|
||||||
<FormControl>
|
|
||||||
<Combobox
|
|
||||||
id="specialistId" :disabled="!values.unitId" v-bind="componentField" :items="specialist.items"
|
|
||||||
:placeholder="specialist.msg.placeholder" :search-placeholder="specialist.msg.search"
|
|
||||||
:empty-message="specialist.msg.empty"
|
|
||||||
/>
|
|
||||||
</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>
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ import { defineAsyncComponent } from 'vue'
|
|||||||
|
|
||||||
type SmallDetailDto = any
|
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-dud.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: 'Specialis' }, { label: '' }]]
|
||||||
[{ label: 'Id' }, { label: 'Nama' }, { label: 'Kode' }, { label: 'Specialist' }, { label: '' }],
|
|
||||||
]
|
export const keys = ['code', 'name', 'specialist', 'action']
|
||||||
export const keys = ['id', 'name', 'cellphone', 'religion_code', 'action']
|
|
||||||
|
|
||||||
export const delKeyNames: KeyLabel[] = [
|
export const delKeyNames: KeyLabel[] = [
|
||||||
{ key: 'code', label: 'Kode' },
|
{ key: 'code', label: 'Kode' },
|
||||||
@@ -27,15 +26,11 @@ 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()
|
||||||
},
|
|
||||||
unit: (rec: unknown): unknown => {
|
|
||||||
const recX = rec as SmallDetailDto
|
|
||||||
return recX.unit?.name || '-'
|
|
||||||
},
|
},
|
||||||
specialist: (rec: unknown): unknown => {
|
specialist: (rec: unknown): unknown => {
|
||||||
const recX = rec as SmallDetailDto
|
const recX = rec as SmallDetailDto
|
||||||
return recX.specialist?.name || '-'
|
return recX.specialist_id || '-'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,9 +40,6 @@ export const funcComponent: RecStrFuncComponent = {
|
|||||||
idx,
|
idx,
|
||||||
rec: rec as object,
|
rec: rec as object,
|
||||||
component: action,
|
component: action,
|
||||||
props: {
|
|
||||||
size: 'sm',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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,239 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { HeaderPrep } from '~/components/pub/custom-ui/data/types'
|
||||||
|
import AppSubspecialistEntryForm from '~/components/app/subspecialist/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 { usePaginatedList } from '~/composables/usePaginatedList'
|
||||||
|
import { createFilteredUnitConf, installationConf, schemaConf, specialistConf, unitConf } 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)
|
||||||
|
|
||||||
|
// State untuk tracking installation, unit, dan specialist yang dipilih di form
|
||||||
|
const selectedInstallationId = ref<string>('')
|
||||||
|
const selectedUnitId = ref<string>('')
|
||||||
|
|
||||||
|
// Computed untuk filtered unit berdasarkan installation yang dipilih
|
||||||
|
const filteredUnitConf = computed(() => {
|
||||||
|
if (!selectedInstallationId.value) {
|
||||||
|
return { ...unitConf, items: [] }
|
||||||
|
}
|
||||||
|
return createFilteredUnitConf(selectedInstallationId.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
paginationMeta,
|
||||||
|
searchInput,
|
||||||
|
handlePageChange,
|
||||||
|
handleSearch,
|
||||||
|
fetchData: getSubSpecialistList,
|
||||||
|
} = usePaginatedList({
|
||||||
|
fetchFn: fetchSubSpecialistData,
|
||||||
|
entityName: 'subspecialist',
|
||||||
|
})
|
||||||
|
|
||||||
|
const headerPrep: HeaderPrep = {
|
||||||
|
title: 'Sub Specialist',
|
||||||
|
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 Sub Specialist',
|
||||||
|
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 fetchSubSpecialistData(params: any) {
|
||||||
|
const endpoint = transform('/api/v1/patient', params)
|
||||||
|
return await xfetch(endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
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/subspecialist/${record.id}`, {
|
||||||
|
// method: 'DELETE'
|
||||||
|
// })
|
||||||
|
|
||||||
|
// Refresh data setelah berhasil delete
|
||||||
|
await getSubSpecialistList()
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 region
|
||||||
|
|
||||||
|
// #region Form event handlers
|
||||||
|
|
||||||
|
function onCancelForm(resetForm: () => void) {
|
||||||
|
isFormEntryDialogOpen.value = false
|
||||||
|
selectedInstallationId.value = ''
|
||||||
|
selectedUnitId.value = ''
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
resetForm()
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInstallationChanged(installationId: string) {
|
||||||
|
selectedInstallationId.value = installationId
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUnitChanged(unitId: string) {
|
||||||
|
selectedUnitId.value = unitId
|
||||||
|
}
|
||||||
|
|
||||||
|
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/subspecialist', {
|
||||||
|
// method: 'POST',
|
||||||
|
// body: JSON.stringify(values)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// If successful, mark as success and close dialog
|
||||||
|
isFormEntryDialogOpen.value = false
|
||||||
|
isSuccess = true
|
||||||
|
|
||||||
|
// Reset selection ketika form berhasil submit
|
||||||
|
selectedInstallationId.value = ''
|
||||||
|
selectedUnitId.value = ''
|
||||||
|
|
||||||
|
// Refresh data after successful submission
|
||||||
|
await getSubSpecialistList()
|
||||||
|
|
||||||
|
// TODO: Show success message
|
||||||
|
console.log('Sub Specialist 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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// #endregion
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Header v-model="searchInput" :prep="headerPrep" @search="handleSearch" />
|
||||||
|
<AppSubspecialistList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
|
||||||
|
<Dialog v-model:open="isFormEntryDialogOpen" :title="headerPrep.addNav?.label!" size="lg" prevent-outside>
|
||||||
|
<AppSubspecialistEntryFormPrev
|
||||||
|
:installation="installationConf"
|
||||||
|
:unit="filteredUnitConf"
|
||||||
|
:specialist="specialistConf"
|
||||||
|
:schema="schemaConf"
|
||||||
|
:initial-values="{ name: '', code: '', installationId: '', unitId: '', specialistId: '' }"
|
||||||
|
@submit="onSubmitForm"
|
||||||
|
@cancel="onCancelForm"
|
||||||
|
@installation-changed="onInstallationChanged"
|
||||||
|
@unit-changed="onUnitChanged"
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<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?.name"><strong>Nama:</strong> {{ record.name }}</p>
|
||||||
|
<p v-if="record?.code"><strong>Kode:</strong> {{ record.code }}</p>
|
||||||
|
<p v-if="record?.specialist"><strong>Specialist:</strong> {{ record.specialist?.name }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</RecordConfirmation>
|
||||||
|
</template>
|
||||||
@@ -1,34 +1,41 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { HeaderPrep } from '~/components/pub/custom-ui/data/types'
|
// Components
|
||||||
import AppSubspecialistEntryForm from '~/components/app/subspecialist/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 AppSubSpecialistList from '~/components/app/subspecialist/list.vue'
|
||||||
import Header from '~/components/pub/custom-ui/nav-header/header.vue'
|
import AppSubSpecialistEntryForm from '~/components/app/subspecialist/entry-form.vue'
|
||||||
|
|
||||||
|
// Helpers
|
||||||
import { usePaginatedList } from '~/composables/usePaginatedList'
|
import { usePaginatedList } from '~/composables/usePaginatedList'
|
||||||
import { createFilteredUnitConf, installationConf, schemaConf, specialistConf, unitConf } from './entry'
|
import { toast } from '~/components/pub/ui/toast'
|
||||||
|
|
||||||
// #region State & Computed
|
// Types
|
||||||
// Dialog state
|
import { ActionEvents, type HeaderPrep } from '~/components/pub/custom-ui/data/types'
|
||||||
const isFormEntryDialogOpen = ref(false)
|
import { SubspecialistSchema, type SubspecialistFormData } from '~/schemas/subspecialist.schema'
|
||||||
const isRecordConfirmationOpen = ref(false)
|
import type { Specialist } from '~/models/specialist'
|
||||||
|
|
||||||
// Table action rowId provider
|
// Handlers
|
||||||
const recId = ref<number>(0)
|
import {
|
||||||
const recAction = ref<string>('')
|
recId,
|
||||||
const recItem = ref<any>(null)
|
recAction,
|
||||||
|
recItem,
|
||||||
|
isReadonly,
|
||||||
|
isProcessing,
|
||||||
|
isFormEntryDialogOpen,
|
||||||
|
isRecordConfirmationOpen,
|
||||||
|
handleActionSave,
|
||||||
|
handleActionEdit,
|
||||||
|
handleActionRemove,
|
||||||
|
handleCancelForm,
|
||||||
|
} from '~/handlers/subspecialist.handler'
|
||||||
|
|
||||||
// State untuk tracking installation, unit, dan specialist yang dipilih di form
|
// Services
|
||||||
const selectedInstallationId = ref<string>('')
|
import { getSubspecialists, getSubspecialistDetail } from '~/services/subspecialist.service'
|
||||||
const selectedUnitId = ref<string>('')
|
import { getSpecialists } from '~/services/specialist.service'
|
||||||
|
|
||||||
// Computed untuk filtered unit berdasarkan installation yang dipilih
|
const specialists = ref<{ value: string; label: string }[]>([])
|
||||||
const filteredUnitConf = computed(() => {
|
const title = ref('')
|
||||||
if (!selectedInstallationId.value) {
|
|
||||||
return { ...unitConf, items: [] }
|
|
||||||
}
|
|
||||||
return createFilteredUnitConf(selectedInstallationId.value)
|
|
||||||
})
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
@@ -39,33 +46,35 @@ const {
|
|||||||
handleSearch,
|
handleSearch,
|
||||||
fetchData: getSubSpecialistList,
|
fetchData: getSubSpecialistList,
|
||||||
} = usePaginatedList({
|
} = usePaginatedList({
|
||||||
fetchFn: fetchSubSpecialistData,
|
fetchFn: async ({ page, search }) => {
|
||||||
|
const result = await getSubspecialists({ search, page })
|
||||||
|
return { success: result.success || false, body: result.body || {} }
|
||||||
|
},
|
||||||
entityName: 'subspecialist',
|
entityName: 'subspecialist',
|
||||||
})
|
})
|
||||||
|
|
||||||
const headerPrep: HeaderPrep = {
|
const headerPrep: HeaderPrep = {
|
||||||
title: 'Sub Specialist',
|
title: 'SubSpecialist',
|
||||||
icon: 'i-lucide-box',
|
icon: 'i-lucide-box',
|
||||||
refSearchNav: {
|
refSearchNav: {
|
||||||
placeholder: 'Cari (min. 3 karakter)...',
|
placeholder: 'Cari (min. 3 karakter)...',
|
||||||
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 Sub Specialist',
|
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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -74,165 +83,100 @@ 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 getCurrentSubSpecialistDetail = async (id: number | string) => {
|
||||||
async function fetchSubSpecialistData(params: any) {
|
const result = await getSubspecialistDetail(id)
|
||||||
const endpoint = transform('/api/v1/patient', params)
|
if (result.success) {
|
||||||
return await xfetch(endpoint)
|
const currentValue = result.body?.data || {}
|
||||||
}
|
recItem.value = currentValue
|
||||||
|
isFormEntryDialogOpen.value = true
|
||||||
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/subspecialist/${record.id}`, {
|
|
||||||
// method: 'DELETE'
|
|
||||||
// })
|
|
||||||
|
|
||||||
// Refresh data setelah berhasil delete
|
|
||||||
await getSubSpecialistList()
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle confirmation result
|
const getSpecialistsList = async () => {
|
||||||
function handleConfirmDelete(record: any, action: string) {
|
const result = await getSpecialists()
|
||||||
console.log('Confirmed action:', action, 'for record:', record)
|
if (result.success) {
|
||||||
handleDeleteRow(record)
|
const currentSpecialists = result.body?.data || []
|
||||||
}
|
specialists.value = currentSpecialists.map((item: Specialist) => ({
|
||||||
|
value: item.id ? Number(item.id) : item.code,
|
||||||
function handleCancelConfirmation() {
|
label: item.name,
|
||||||
// Reset record state when cancelled
|
}))
|
||||||
recId.value = 0
|
|
||||||
recAction.value = ''
|
|
||||||
recItem.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// #endregion region
|
|
||||||
|
|
||||||
// #region Form event handlers
|
|
||||||
|
|
||||||
function onCancelForm(resetForm: () => void) {
|
|
||||||
isFormEntryDialogOpen.value = false
|
|
||||||
selectedInstallationId.value = ''
|
|
||||||
selectedUnitId.value = ''
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
resetForm()
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onInstallationChanged(installationId: string) {
|
|
||||||
selectedInstallationId.value = installationId
|
|
||||||
}
|
|
||||||
|
|
||||||
function onUnitChanged(unitId: string) {
|
|
||||||
selectedUnitId.value = unitId
|
|
||||||
}
|
|
||||||
|
|
||||||
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/subspecialist', {
|
|
||||||
// method: 'POST',
|
|
||||||
// body: JSON.stringify(values)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// If successful, mark as success and close dialog
|
|
||||||
isFormEntryDialogOpen.value = false
|
|
||||||
isSuccess = true
|
|
||||||
|
|
||||||
// Reset selection ketika form berhasil submit
|
|
||||||
selectedInstallationId.value = ''
|
|
||||||
selectedUnitId.value = ''
|
|
||||||
|
|
||||||
// Refresh data after successful submission
|
|
||||||
await getSubSpecialistList()
|
|
||||||
|
|
||||||
// TODO: Show success message
|
|
||||||
console.log('Sub Specialist 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 when recId or recAction changes
|
||||||
|
watch([recId, recAction], () => {
|
||||||
// Watch for row actions
|
|
||||||
watch(recId, () => {
|
|
||||||
switch (recAction.value) {
|
switch (recAction.value) {
|
||||||
|
case ActionEvents.showDetail:
|
||||||
|
getCurrentSubSpecialistDetail(recId.value)
|
||||||
|
title.value = 'Detail Sub Spesialis'
|
||||||
|
isReadonly.value = true
|
||||||
|
break
|
||||||
case ActionEvents.showEdit:
|
case ActionEvents.showEdit:
|
||||||
// TODO: Handle edit action
|
getCurrentSubSpecialistDetail(recId.value)
|
||||||
// isFormEntryDialogOpen.value = true
|
title.value = 'Edit Sub Spesialis'
|
||||||
|
isReadonly.value = false
|
||||||
break
|
break
|
||||||
case ActionEvents.showConfirmDelete:
|
case ActionEvents.showConfirmDelete:
|
||||||
// Trigger confirmation modal open
|
|
||||||
isRecordConfirmationOpen.value = true
|
isRecordConfirmationOpen.value = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// #endregion
|
onMounted(async () => {
|
||||||
|
await getSpecialistsList()
|
||||||
|
await getSubSpecialistList()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Header v-model="searchInput" :prep="headerPrep" @search="handleSearch" />
|
<Header
|
||||||
<AppSubspecialistList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
v-model="searchInput"
|
||||||
|
:prep="headerPrep"
|
||||||
|
:ref-search-nav="headerPrep.refSearchNav"
|
||||||
|
@search="handleSearch"
|
||||||
|
class="mb-4 xl:mb-5"
|
||||||
|
/>
|
||||||
|
<AppSubSpecialistList :data="data" :pagination-meta="paginationMeta" @page-change="handlePageChange" />
|
||||||
|
|
||||||
<Dialog v-model:open="isFormEntryDialogOpen" :title="headerPrep.addNav?.label!" size="lg" prevent-outside>
|
<Dialog
|
||||||
<AppSubspecialistEntryForm
|
v-model:open="isFormEntryDialogOpen"
|
||||||
:installation="installationConf"
|
:title="!!recItem ? title : 'Tambah Sub Spesialis'"
|
||||||
:unit="filteredUnitConf"
|
size="lg"
|
||||||
:specialist="specialistConf"
|
prevent-outside
|
||||||
:schema="schemaConf"
|
>
|
||||||
:initial-values="{ name: '', code: '', installationId: '', unitId: '', specialistId: '' }"
|
<AppSubSpecialistEntryForm
|
||||||
@submit="onSubmitForm"
|
:schema="SubspecialistSchema"
|
||||||
@cancel="onCancelForm"
|
:specialists="specialists"
|
||||||
@installation-changed="onInstallationChanged"
|
:values="recItem"
|
||||||
@unit-changed="onUnitChanged"
|
:is-loading="isProcessing"
|
||||||
|
:is-readonly="isReadonly"
|
||||||
|
@submit="
|
||||||
|
(values: SubspecialistFormData | Record<string, any>, resetForm: () => void) => {
|
||||||
|
if (recId > 0) {
|
||||||
|
handleActionEdit(recId, values, getSubSpecialistList, resetForm, toast)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
handleActionSave(values, getSubSpecialistList, resetForm, toast)
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@cancel="handleCancelForm"
|
||||||
/>
|
/>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<!-- Record Confirmation Modal -->
|
||||||
<RecordConfirmation
|
<RecordConfirmation
|
||||||
v-model:open="isRecordConfirmationOpen"
|
v-model:open="isRecordConfirmationOpen"
|
||||||
action="delete"
|
action="delete"
|
||||||
:record="recItem"
|
:record="recItem"
|
||||||
@confirm="handleConfirmDelete"
|
@confirm="() => handleActionRemove(recId, getSubSpecialistList, toast)"
|
||||||
@cancel="handleCancelConfirmation"
|
@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?.name"><strong>Nama:</strong> {{ record.name }}</p>
|
<p v-if="record?.name"><strong>Nama:</strong> {{ record.name }}</p>
|
||||||
<p v-if="record?.code"><strong>Kode:</strong> {{ record.code }}</p>
|
<p v-if="record?.code"><strong>Kode:</strong> {{ record.code }}</p>
|
||||||
<p v-if="record?.specialist"><strong>Specialist:</strong> {{ record.specialist?.name }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</RecordConfirmation>
|
</RecordConfirmation>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export interface Specialist {
|
export interface Specialist {
|
||||||
|
id?: number
|
||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
unit_id: number | string
|
unit_id: number | string
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface Subspecialist {
|
export interface Subspecialist {
|
||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
unit_id: number
|
specialist_id: number | string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
import type { Subspecialist } from '~/models/subspecialist'
|
||||||
|
|
||||||
|
const SubspecialistSchema = z.object({
|
||||||
|
code: z.string({ required_error: 'Kode harus diisi' }).min(1, 'Kode minimum 1 karakter'),
|
||||||
|
name: z.string({ required_error: 'Nama harus diisi' }).min(1, 'Nama minimum 1 karakter'),
|
||||||
|
specialist_id: z.number().positive('Spesialis harus diisi'),
|
||||||
|
})
|
||||||
|
|
||||||
|
type SubspecialistFormData = z.infer<typeof SubspecialistSchema> & Subspecialist
|
||||||
|
|
||||||
|
export { SubspecialistSchema }
|
||||||
|
export type { SubspecialistFormData }
|
||||||
Reference in New Issue
Block a user