Skip to content

Commit

Permalink
Corrige une erreur de typage qui fait échouer le build
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-rutkowski committed Oct 7, 2024
1 parent 7b26686 commit accdf65
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/panier/components/Landing/useFilteredCollectivites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ import { makeSearchString } from '@tet/api';
import useSWR from 'swr';
import { supabase } from '../../src/clientAPI';

type Collectivite = {
collectivite_id: number;
nom: string;
departement_code?: number;
engagee?: boolean;
};

/** Donne la liste des collectivités dont le nom inclus la chaîne recherchée */
export const useFilteredCollectivites = (search: string, limit = 10) => {
const key = `site_labellisation-filtered-${search}`;
return useSWR(key, async () => {
const query = supabase
.from('site_labellisation')
.select('collectivite_id, nom, departement_code, engagee')
.order('nom')
.limit(limit);
.order('nom');

const processedSearch = makeSearchString(search, 'nom');
if (processedSearch) {
query.or(processedSearch);
}

const { error, data } = await query;
query.limit(limit);

const { error, data } = await query.returns<Collectivite[]>();

if (error) {
throw new Error(key);
Expand Down

0 comments on commit accdf65

Please sign in to comment.