Affine les types (et répare les checks)

pull/1928/head
Alexandre Valsamou-Stanislawski 2021-12-08 17:01:05 +01:00 committed by Johan Girod
parent 626c4a07da
commit df768a3cff
2 changed files with 9 additions and 7 deletions

View File

@ -52,11 +52,13 @@ type FabriqueSocialSearchPayload = {
const makeSearchUrl = (query: string) =>
`https://search-recherche-entreprises.fabrique.social.gouv.fr/api/v1/search?query=${query}&open=false&convention=false&employer=false&ranked=false&limit=10`
async function searchFullText(text: string): Promise<Array<{
export type Entreprise = {
siren: string
address?: string
denomination?: string
}> | null> {
}
async function searchFullText(text: string): Promise<Array<Entreprise> | null> {
const response = await fetch(makeSearchUrl(text))
if (!response.ok) {

View File

@ -1,16 +1,16 @@
import { Etablissement, searchDenominationOrSiren } from 'API/fabrique-social'
import { Entreprise, searchDenominationOrSiren } from 'API/fabrique-social'
import { useEffect, useState } from 'react'
import { useDebounce } from './useDebounce'
export default function useSearchCompany(
value: string
): [boolean, Array<Etablissement>] {
const [result, setResult] = useState<Array<Etablissement>>([])
const [searchPending, setSearchPending] = useState(!!value)
): [boolean, Array<Entreprise>] {
const [result, setResult] = useState<Array<Entreprise>>([])
const [searchPending, setSearchPending] = useState(Boolean(value))
const debouncedValue = useDebounce(value, 300)
useEffect(() => {
setSearchPending(!!value)
setSearchPending(Boolean(value))
if (!value) {
setResult([])