Files
simrsx-fe/app/models/person-address.ts
T
Khafid Prayoga ea04f33ad1 refactor(address): update address models and forms to use standardized fields
- Add preload relationships to address-related models
- Rename postalCode to postalCode_code for consistency
- Simplify location type handling with hidden fields
- Update validation schemas and form components
- Improve address display in patient preview
2025-10-10 15:36:54 +07:00

47 lines
1015 B
TypeScript

import { type Base, genBase } from './_base'
import type { PostalCode } from './postal-code'
import { toTitleCase } from '~/lib/utils'
export interface PersonAddress extends Base {
person_id: number
locationType: string
address: string
rt?: string
rw?: string
postalCode_code?: string
village_code: string
// preload
postalCode?: PostalCode | null
}
export function genPersonAddress(): PersonAddress {
return {
...genBase(),
person_id: 0,
locationType: '',
address: '',
village_code: '',
}
}
export function formatAddress(builder?: PersonAddress) {
if (!builder) return ''
const village = builder?.postalCode?.village
const district = village?.district
const regency = district?.regency
const province = regency?.province
const parts = [
builder?.address,
village?.name,
district?.name,
toTitleCase(regency?.name || ''),
toTitleCase(province?.name || ''),
builder?.postalCode_code,
].filter(Boolean)
return parts.join(', ')
}