Files
IdP/apps/frontend/lib/address-catalog.ts
2026-06-24 14:37:15 +03:00

29 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type AddressLabel = 'HOME' | 'WORK' | 'OTHER';
export const ADDRESS_LABELS: Record<AddressLabel, { title: string; shortTitle: string }> = {
HOME: { title: 'Дом', shortTitle: 'Дом' },
WORK: { title: 'Работа', shortTitle: 'Работа' },
OTHER: { title: 'Другой адрес', shortTitle: 'Другие' }
};
export function formatAddressLine(address: {
fullAddress?: string | null;
city?: string;
street?: string;
house?: string;
apartment?: string | null;
}) {
if (address.fullAddress?.trim()) return address.fullAddress.trim();
const parts = [`г. ${address.city}`, `${address.street}, ${address.house}`];
if (address.apartment?.trim()) parts.push(`кв. ${address.apartment.trim()}`);
return parts.filter(Boolean).join(', ');
}
export function getPrimaryAddress(addresses: { label: string }[], label: AddressLabel) {
return addresses.find((item) => item.label === label) ?? null;
}
export function getOtherAddresses<T extends { label: string }>(addresses: T[]) {
return addresses.filter((item) => item.label === 'OTHER');
}