[WIP] Add postal code search integration to AddressPicker

Implemented `getPostalCodes` function in `local-search` driver and connected it with `AddressPicker.vue`. Introduced UI changes to display postal codes alongside addresses and ensured search requests are abortable.
This commit is contained in:
2025-08-16 00:08:03 +02:00
parent b16e6c4517
commit b1703a4187
2 changed files with 82 additions and 7 deletions

View File

@@ -1,3 +1,5 @@
import { TranslatableString } from "ChillMainAssets/types";
export interface AddressAggregated {
row_number: number;
street: string;
@@ -7,6 +9,15 @@ export interface AddressAggregated {
positions: Record<string, string>;
}
export interface AssociatedPostalCode {
postcode_id: number;
code: string;
label: string;
country_id: number;
country_code: string;
country_name: TranslatableString;
}
/**
* @throws {DOMException} when fetch is aborted, the property name is always equals to 'AbortError'
*/
@@ -14,7 +25,7 @@ export const getAddressesAggregated = async (
search: string,
abortController: AbortController,
): Promise<AddressAggregated[]> => {
const params = new URLSearchParams({ q: search });
const params = new URLSearchParams({ q: search.trim() });
let response = null;
response = await fetch(
@@ -28,3 +39,22 @@ export const getAddressesAggregated = async (
throw new Error(response.statusText);
};
export const getPostalCodes = async (
search: string,
abortController: AbortController,
): Promise<AssociatedPostalCode[]> => {
const params = new URLSearchParams({ q: search.trim() });
let response = null;
response = await fetch(
`/api/1.0/main/address-reference/postal-code/search?${params}`,
{ signal: abortController.signal },
);
if (response.ok) {
return await response.json();
}
throw new Error(response.statusText);
};