fix(preview): gon should not crash on preview pages

This commit is contained in:
Paul Chavard 2022-07-07 11:39:03 +02:00
parent b9945696f3
commit 1c8efea465
10 changed files with 113 additions and 40 deletions

View file

@ -1,18 +1,7 @@
import { QueryClient, QueryFunction } from 'react-query';
import { httpRequest, isNumeric } from '@utils';
import { httpRequest, isNumeric, getConfig } from '@utils';
import { matchSorter } from 'match-sorter';
type Gon = {
gon: {
autocomplete?: {
api_geo_url?: string;
api_adresse_url?: string;
api_education_url?: string;
};
};
};
declare const window: Window & typeof globalThis & Gon;
const API_EDUCATION_QUERY_LIMIT = 5;
const API_GEO_QUERY_LIMIT = 5;
const API_ADRESSE_QUERY_LIMIT = 5;
@ -26,8 +15,9 @@ const API_ADRESSE_QUERY_LIMIT = 5;
// NB: 60 is arbitrary, we may add more if needed.
const API_GEO_COMMUNES_QUERY_LIMIT = 60;
const { api_geo_url, api_adresse_url, api_education_url } =
window.gon.autocomplete || {};
const {
autocomplete: { api_geo_url, api_adresse_url, api_education_url }
} = getConfig();
type QueryKey = readonly [
scope: string,