frontend admin refakctorálás
This commit is contained in:
@@ -157,39 +157,46 @@ function formatDate(dateStr: string | null | undefined): string {
|
||||
}
|
||||
}
|
||||
|
||||
const formattedAddress = computed(() => {
|
||||
if (!props.garage) return ''
|
||||
const parts = [
|
||||
props.garage.address_zip,
|
||||
props.garage.address_city,
|
||||
props.garage.address_street_name,
|
||||
props.garage.address_street_type,
|
||||
props.garage.address_house_number,
|
||||
/**
|
||||
* Format an address object (address_detail) into a display string.
|
||||
* Falls back to flat fields (address_zip, address_city, etc.) if address_detail is not available.
|
||||
*/
|
||||
function formatAddress(addr: Record<string, any> | null | undefined, flatPrefix: string = 'address'): string {
|
||||
if (!props.garage) return '-'
|
||||
|
||||
// Try address_detail first
|
||||
if (addr && typeof addr === 'object') {
|
||||
const parts = [
|
||||
addr.zip,
|
||||
addr.city,
|
||||
addr.street_name,
|
||||
addr.street_type,
|
||||
addr.house_number,
|
||||
].filter(Boolean)
|
||||
if (parts.length > 0) return parts.join(' ')
|
||||
if (addr.full_address_text) return addr.full_address_text
|
||||
}
|
||||
|
||||
// Fallback to flat fields
|
||||
const flatParts = [
|
||||
props.garage[`${flatPrefix}_zip`],
|
||||
props.garage[`${flatPrefix}_city`],
|
||||
props.garage[`${flatPrefix}_street_name`],
|
||||
props.garage[`${flatPrefix}_street_type`],
|
||||
props.garage[`${flatPrefix}_house_number`],
|
||||
].filter(Boolean)
|
||||
return parts.join(' ') || '-'
|
||||
return flatParts.join(' ') || '-'
|
||||
}
|
||||
|
||||
const formattedAddress = computed(() => {
|
||||
return formatAddress(props.garage?.address_detail, 'address')
|
||||
})
|
||||
|
||||
const formattedBillingAddress = computed(() => {
|
||||
if (!props.garage) return ''
|
||||
const parts = [
|
||||
props.garage.billing_zip,
|
||||
props.garage.billing_city,
|
||||
props.garage.billing_street_name,
|
||||
props.garage.billing_street_type,
|
||||
props.garage.billing_house_number,
|
||||
].filter(Boolean)
|
||||
return parts.join(' ') || ''
|
||||
return formatAddress(props.garage?.billing_address_detail, 'billing')
|
||||
})
|
||||
|
||||
const formattedNotificationAddress = computed(() => {
|
||||
if (!props.garage) return ''
|
||||
const parts = [
|
||||
props.garage.notification_zip,
|
||||
props.garage.notification_city,
|
||||
props.garage.notification_street_name,
|
||||
props.garage.notification_street_type,
|
||||
props.garage.notification_house_number,
|
||||
].filter(Boolean)
|
||||
return parts.join(' ') || ''
|
||||
return formatAddress(props.garage?.notification_address_detail, 'notification')
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user