From 51214226583621362bff4816db6d1531efff36a7 Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Thu, 9 Oct 2025 13:46:40 +0700 Subject: [PATCH] adjust: improve regency select based on new useRegencies composable to explicit pull all data with no limitation, because it has a province code --- .../person-address/_common/select-postal.vue | 29 +-- .../person-address/_common/select-regency.vue | 2 +- .../person-address/entry-form-relative.vue | 188 ++++++++++++------ .../app/person-address/entry-form.vue | 27 +-- .../app/person-contact/entry-form.vue | 1 + app/components/content/patient/entry.vue | 100 ++++++++-- app/composables/usePostalCodes.ts | 169 ++++++++++++++++ app/models/person-address.ts | 4 +- app/models/postal-code.ts | 14 ++ app/schemas/person-address-relative.schema.ts | 62 ++++-- app/schemas/person-address.schema.ts | 3 +- app/services/postal-code.service.ts | 17 ++ 12 files changed, 485 insertions(+), 131 deletions(-) create mode 100644 app/composables/usePostalCodes.ts create mode 100644 app/models/postal-code.ts create mode 100644 app/services/postal-code.service.ts diff --git a/app/components/app/person-address/_common/select-postal.vue b/app/components/app/person-address/_common/select-postal.vue index 84df7b33..66eb3c5e 100644 --- a/app/components/app/person-address/_common/select-postal.vue +++ b/app/components/app/person-address/_common/select-postal.vue @@ -8,6 +8,7 @@ import { cn } from '~/lib/utils' const props = defineProps<{ fieldName: string + villageCode?: string isDisabled?: boolean placeholder?: string errors?: FormErrors @@ -26,17 +27,19 @@ const { fieldGroupClass, } = props -const postalCodeOptions = [ - { label: '65120', value: '65120' }, - { label: '65121', value: '65121' }, - { label: '65123', value: '65123' }, - { label: '65124', value: '65124' }, - { label: '65125', value: '65125' }, - { label: '65126', value: '65126' }, - { label: '65127', value: '65127' }, - { label: '65128', value: '65128' }, - { label: '65129', value: '65129' }, -] +const villageCodeRef = toRef(props, 'villageCode') +const { postalCodeOptions, isLoading, error } = usePostalCodes(villageCodeRef) + +const dynamicPlaceholder = computed(() => { + if (!props.villageCode) return 'Pilih kelurahan terlebih dahulu' + if (isLoading.value) return 'Memuat kode pos...' + if (error.value) return 'Gagal memuat data' + return placeholder +}) + +const isFieldDisabled = computed(() => { + return props.isDisabled || !props.villageCode || isLoading.value || !!error.value +})