demarches-normaliennes/app/javascript/components/ComboAnnuaireEducationSearch.tsx

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-01-14 17:30:55 +01:00
import React from 'react';
2021-02-16 13:54:16 +01:00
import { QueryClientProvider } from 'react-query';
2021-01-14 17:30:55 +01:00
import ComboSearch, { ComboSearchProps } from './ComboSearch';
2021-02-16 13:54:16 +01:00
import { queryClient } from './shared/queryClient';
2021-01-14 17:30:55 +01:00
type AnnuaireEducationResult = {
fields: {
identifiant_de_l_etablissement: string;
nom_etablissement: string;
nom_commune: string;
};
};
function transformResults(_: unknown, result: unknown) {
const results = result as { records: AnnuaireEducationResult[] };
return results.records as AnnuaireEducationResult[];
}
export default function ComboAnnuaireEducationSearch(
props: ComboSearchProps<AnnuaireEducationResult>
) {
2021-01-14 17:30:55 +01:00
return (
2021-02-16 13:54:16 +01:00
<QueryClientProvider client={queryClient}>
2021-01-14 17:30:55 +01:00
<ComboSearch
{...props}
2021-01-14 17:30:55 +01:00
scope="annuaire-education"
minimumInputLength={3}
transformResults={transformResults}
2021-01-14 17:30:55 +01:00
transformResult={({
fields: {
identifiant_de_l_etablissement: id,
nom_etablissement,
nom_commune
}
}) => [id, `${nom_etablissement}, ${nom_commune} (${id})`]}
/>
2021-02-16 13:54:16 +01:00
</QueryClientProvider>
2021-01-14 17:30:55 +01:00
);
}