first commit
This commit is contained in:
28
apps/frontend/lib/address-catalog.ts
Normal file
28
apps/frontend/lib/address-catalog.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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');
|
||||
}
|
||||
Reference in New Issue
Block a user