diff --git a/clients/ping-api-clients.ts b/clients/ping-api-clients.ts index 953948966..8ecb27e43 100644 --- a/clients/ping-api-clients.ts +++ b/clients/ping-api-clients.ts @@ -1,6 +1,5 @@ import { verifyIdRna } from '../utils/helpers/id-rna'; import { verifySiren } from '../utils/helpers/siren-and-siret'; -import { HttpServerError } from './exceptions'; import { fetchAssociation } from './rna'; import { fetchRNCSImmatriculation } from './rncs'; import { fetchRnmImmatriculation } from './rnm'; diff --git a/clients/sirene-ouverte/recherche.ts b/clients/sirene-ouverte/recherche.ts index 79fb0d875..b40e02f56 100644 --- a/clients/sirene-ouverte/recherche.ts +++ b/clients/sirene-ouverte/recherche.ts @@ -1,6 +1,5 @@ -import { IEtablissement } from '../../models'; -import constants from '../../models/constants'; import { ISearchResults } from '../../models/search'; +import constants from '../../models/constants'; import { formatAdresse, parseIntWithDefaultValue, @@ -9,6 +8,7 @@ import { libelleFromCodeNaf } from '../../utils/labels'; import { httpGet } from '../../utils/network'; import { HttpNotFound } from '../exceptions'; import routes from '../routes'; +import SearchFilterParams from '../../models/search-filter-params'; interface ISireneOuverteUniteLegaleResultat { siren: string; @@ -57,7 +57,8 @@ export interface ISireneOuverteSearchResults { */ const getResults = async ( searchTerms: string, - page: number + page: number, + searchFilterParams?: SearchFilterParams ): Promise => { const encodedTerms = encodeURI(searchTerms); @@ -65,7 +66,10 @@ const getResults = async ( process.env.ALTERNATIVE_SEARCH_ROUTE || routes.sireneOuverte.rechercheUniteLegale; - const url = `${route}?per_page=10&page=${page}&q=${encodedTerms}`; + let url = `${route}?per_page=10&page=${page}&q=${encodedTerms}${ + searchFilterParams?.toURI() || '' + }`; + const response = await httpGet(url, { timeout: constants.timeout.long }); const results = (response.data || []) as any; diff --git a/components/alerts/association-adress.tsx b/components-ui/alerts/association-adress.tsx similarity index 94% rename from components/alerts/association-adress.tsx rename to components-ui/alerts/association-adress.tsx index 1ca369d34..2ad399cf6 100644 --- a/components/alerts/association-adress.tsx +++ b/components-ui/alerts/association-adress.tsx @@ -1,5 +1,5 @@ import { IUniteLegale } from '../../models'; -import { INSEE, MI } from '../administrations'; +import { INSEE, MI } from '../../components/administrations'; import Warning from './warning'; const AssociationAdressAlert: React.FC<{ uniteLegale: IUniteLegale }> = ({ diff --git a/components/alerts/association-creation-not-found-alert.tsx b/components-ui/alerts/association-creation-not-found-alert.tsx similarity index 100% rename from components/alerts/association-creation-not-found-alert.tsx rename to components-ui/alerts/association-creation-not-found-alert.tsx diff --git a/components/alerts/immatriculation-not-found-alert.tsx b/components-ui/alerts/immatriculation-not-found-alert.tsx similarity index 100% rename from components/alerts/immatriculation-not-found-alert.tsx rename to components-ui/alerts/immatriculation-not-found-alert.tsx diff --git a/components/alerts/info.tsx b/components-ui/alerts/info.tsx similarity index 100% rename from components/alerts/info.tsx rename to components-ui/alerts/info.tsx diff --git a/components/alerts/inpi-partially-down.tsx b/components-ui/alerts/inpi-partially-down.tsx similarity index 89% rename from components/alerts/inpi-partially-down.tsx rename to components-ui/alerts/inpi-partially-down.tsx index f1f42b697..90227d1a2 100644 --- a/components/alerts/inpi-partially-down.tsx +++ b/components-ui/alerts/inpi-partially-down.tsx @@ -1,4 +1,4 @@ -import { INPI } from '../administrations'; +import { INPI } from '../../components/administrations'; import Warning from './warning'; const InpiPartiallyDownWarning: React.FC<{ missing?: string }> = ({ diff --git a/components/alerts/multiple-siren.tsx b/components-ui/alerts/multiple-siren.tsx similarity index 92% rename from components/alerts/multiple-siren.tsx rename to components-ui/alerts/multiple-siren.tsx index 43f26ca4c..371c87511 100644 --- a/components/alerts/multiple-siren.tsx +++ b/components-ui/alerts/multiple-siren.tsx @@ -1,6 +1,6 @@ import { IUniteLegale } from '../../models'; import { formatIntFr } from '../../utils/helpers/formatting'; -import { INSEE } from '../administrations'; +import { INSEE } from '../../components/administrations'; import Warning from './warning'; const MultipleSirenAlert: React.FC<{ uniteLegale: IUniteLegale }> = ({ diff --git a/components/alerts/warning.tsx b/components-ui/alerts/warning.tsx similarity index 100% rename from components/alerts/warning.tsx rename to components-ui/alerts/warning.tsx diff --git a/components/button/index.tsx b/components-ui/button/index.tsx similarity index 100% rename from components/button/index.tsx rename to components-ui/button/index.tsx diff --git a/components/horizontal-separator/index.tsx b/components-ui/horizontal-separator/index.tsx similarity index 100% rename from components/horizontal-separator/index.tsx rename to components-ui/horizontal-separator/index.tsx diff --git a/components/icon/index.tsx b/components-ui/icon/index.tsx similarity index 100% rename from components/icon/index.tsx rename to components-ui/icon/index.tsx diff --git a/components/information-tooltip/data-source-tooltip.tsx b/components-ui/information-tooltip/data-source-tooltip.tsx similarity index 100% rename from components/information-tooltip/data-source-tooltip.tsx rename to components-ui/information-tooltip/data-source-tooltip.tsx diff --git a/components/information-tooltip/index.tsx b/components-ui/information-tooltip/index.tsx similarity index 100% rename from components/information-tooltip/index.tsx rename to components-ui/information-tooltip/index.tsx diff --git a/components/is-active-tag/index.tsx b/components-ui/is-active-tag/index.tsx similarity index 100% rename from components/is-active-tag/index.tsx rename to components-ui/is-active-tag/index.tsx diff --git a/components/print-break-page/index.tsx b/components-ui/print-break-page/index.tsx similarity index 100% rename from components/print-break-page/index.tsx rename to components-ui/print-break-page/index.tsx diff --git a/components/print-visibility/index.tsx b/components-ui/print-visibility/index.tsx similarity index 100% rename from components/print-visibility/index.tsx rename to components-ui/print-visibility/index.tsx diff --git a/components/question/index.tsx b/components-ui/question/index.tsx similarity index 100% rename from components/question/index.tsx rename to components-ui/question/index.tsx diff --git a/components-ui/select/index.tsx b/components-ui/select/index.tsx new file mode 100644 index 000000000..7070e7a2c --- /dev/null +++ b/components-ui/select/index.tsx @@ -0,0 +1,38 @@ +import React from 'react'; + +const Select: React.FC<{ + placeholder?: string; + label?: string; + name?: string; + options: { value: string; label: string }[]; + defaultValue?: string; +}> = ({ + label, + options, + placeholder = 'Selectionnez une option', + name = '', + defaultValue = null, +}) => ( +
+ {label && ( + + )} + +
+); + +export default Select; diff --git a/components-ui/select/select-section-naf.tsx b/components-ui/select/select-section-naf.tsx new file mode 100644 index 000000000..a45d6cf7b --- /dev/null +++ b/components-ui/select/select-section-naf.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import Select from '.'; +import { codesSectionNaf } from '../../utils/labels/codes-section-NAF'; + +const SelectCodeSectionNaf: React.FC<{ + placeholder?: string; + label?: string; + name?: string; + maxWidth?: number; + defaultValue?: string; +}> = ({ label, placeholder, name, defaultValue = undefined }) => ( + +
+ +
+ + + + + + + ); +}; + +export default HeaderSearch; diff --git a/components/header/index.tsx b/components/header/index.tsx index 1fa733967..b036bd9d6 100644 --- a/components/header/index.tsx +++ b/components/header/index.tsx @@ -1,97 +1,5 @@ import React from 'react'; -import SearchBar from '../search-bar'; - -const HeaderSmall = ({ currentSearchTerm = '', map = false }) => ( - <> -
-
-
-
- -
-
- -
-
-
-
-
-
- - - -); +import HeaderSearch from './header-search'; const Header = () => ( <> @@ -139,4 +47,4 @@ const Header = () => ( ); -export { Header, HeaderSmall }; +export { Header, HeaderSearch }; diff --git a/components/immatriculations/index.tsx b/components/immatriculations/index.tsx index da9f52786..3d175d55d 100644 --- a/components/immatriculations/index.tsx +++ b/components/immatriculations/index.tsx @@ -5,8 +5,8 @@ import { } from '../../models/api-not-responding'; import { IImmatriculation } from '../../models/immatriculation'; import { IJustificatifs } from '../../models/justificatifs'; -import AssociationCreationNotFoundAlert from '../alerts/association-creation-not-found-alert'; -import ImmatriculationNotFound from '../alerts/immatriculation-not-found-alert'; +import AssociationCreationNotFoundAlert from '../../components-ui/alerts/association-creation-not-found-alert'; +import ImmatriculationNotFound from '../../components-ui/alerts/immatriculation-not-found-alert'; import AvisSituationSection from './insee'; import ImmatriculationJOAFE from './joafe'; import ImmatriculationRNCS from './rncs'; diff --git a/components/immatriculations/insee.tsx b/components/immatriculations/insee.tsx index 986aeaa9d..ef58b05a8 100644 --- a/components/immatriculations/insee.tsx +++ b/components/immatriculations/insee.tsx @@ -4,10 +4,10 @@ import { EAdministration } from '../../models/administration'; import { formatSiret } from '../../utils/helpers/siren-and-siret'; import { FullTable } from '../table/full'; import { Section } from '../section'; -import { Tag } from '../tag'; -import IsActiveTag from '../is-active-tag'; +import { Tag } from '../../components-ui/tag'; +import IsActiveTag from '../../components-ui/is-active-tag'; import AvisSituationLink from '../avis-situation-link'; -import ButtonLink from '../button'; +import ButtonLink from '../../components-ui/button'; import { INSEE } from '../administrations'; interface IProps { diff --git a/components/immatriculations/joafe.tsx b/components/immatriculations/joafe.tsx index 6ee1ea4aa..822d99a6c 100644 --- a/components/immatriculations/joafe.tsx +++ b/components/immatriculations/joafe.tsx @@ -7,12 +7,12 @@ import { } from '../../models/api-not-responding'; import { formatDate, formatIntFr } from '../../utils/helpers/formatting'; import AdministrationNotResponding from '../administration-not-responding'; -import BreakPageForPrint from '../print-break-page'; -import ButtonLink from '../button'; -import { download } from '../icon'; +import BreakPageForPrint from '../../components-ui/print-break-page'; +import ButtonLink from '../../components-ui/button'; +import { download } from '../../components-ui/icon'; import { Section } from '../section'; import { TwoColumnTable } from '../table/simple'; -import { PrintNever } from '../print-visibility'; +import { PrintNever } from '../../components-ui/print-visibility'; import { IImmatriculationJOAFE } from '../../models/immatriculation/joafe'; interface IProps { diff --git a/components/immatriculations/rncs.tsx b/components/immatriculations/rncs.tsx index 2bea0e46b..846ae20eb 100644 --- a/components/immatriculations/rncs.tsx +++ b/components/immatriculations/rncs.tsx @@ -8,16 +8,16 @@ import { import { formatDate, formatIntFr } from '../../utils/helpers/formatting'; import AdministrationNotResponding from '../administration-not-responding'; import { INPI } from '../administrations'; -import BreakPageForPrint from '../print-break-page'; -import ButtonLink from '../button'; +import BreakPageForPrint from '../../components-ui/print-break-page'; +import ButtonLink from '../../components-ui/button'; import ButtonInpiPdf from '../button-inpi-pdf'; import { Section } from '../section'; import { TwoColumnTable } from '../table/simple'; -import { PrintNever } from '../print-visibility'; -import { Closed, Open } from '../icon'; -import InpiPartiallyDownWarning from '../alerts/inpi-partially-down'; +import { PrintNever } from '../../components-ui/print-visibility'; +import { Closed, Open } from '../../components-ui/icon'; +import InpiPartiallyDownWarning from '../../components-ui/alerts/inpi-partially-down'; import { IImmatriculationRNCS } from '../../models/immatriculation/rncs'; -import Info from '../alerts/info'; +import Info from '../../components-ui/alerts/info'; interface IProps { immatriculation: IImmatriculationRNCS | IAPINotRespondingError; diff --git a/components/immatriculations/rnm.tsx b/components/immatriculations/rnm.tsx index 34313a13c..c23e2804e 100644 --- a/components/immatriculations/rnm.tsx +++ b/components/immatriculations/rnm.tsx @@ -11,12 +11,12 @@ import { formatIntFr, } from '../../utils/helpers/formatting'; import AdministrationNotResponding from '../administration-not-responding'; -import BreakPageForPrint from '../print-break-page'; -import ButtonLink from '../button'; -import { Closed, download, Open } from '../icon'; +import BreakPageForPrint from '../../components-ui/print-break-page'; +import ButtonLink from '../../components-ui/button'; +import { Closed, download, Open } from '../../components-ui/icon'; import { Section } from '../section'; import { TwoColumnTable } from '../table/simple'; -import { PrintNever } from '../print-visibility'; +import { PrintNever } from '../../components-ui/print-visibility'; import { IImmatriculationRNM } from '../../models/immatriculation/rnm'; interface IProps { diff --git a/components/modal/we-need-you.tsx b/components/modal/we-need-you.tsx index 929f4e444..55c978acc 100644 --- a/components/modal/we-need-you.tsx +++ b/components/modal/we-need-you.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import ButtonLink from '../button'; +import ButtonLink from '../../components-ui/button'; export const WeNeedYouModal: React.FC<{}> = () => ( <> diff --git a/components/non-diffusible/index.tsx b/components/non-diffusible/index.tsx index e7cbaaf1c..62ec02090 100644 --- a/components/non-diffusible/index.tsx +++ b/components/non-diffusible/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { INSEE } from '../administrations'; -import ButtonLink from '../button'; +import ButtonLink from '../../components-ui/button'; import { Section } from '../section'; const NonDiffusible = () => ( diff --git a/components/results-header/index.tsx b/components/results-header/index.tsx index d535a47f9..42a6a7a95 100644 --- a/components/results-header/index.tsx +++ b/components/results-header/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { pin } from '../icon'; +import { pin } from '../../components-ui/icon'; const MapOrListSwitch = ({ isMap = false, searchTerm = '' }) => ( <> diff --git a/components/results-list/index.tsx b/components/results-list/index.tsx index 762194847..22b673bf8 100644 --- a/components/results-list/index.tsx +++ b/components/results-list/index.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { ISearchResult, ISearchResults } from '../../models/search'; import { capitalize } from '../../utils/helpers/formatting'; import { SearchFeedback } from '../search-feedback'; -import { Tag } from '../tag'; +import { Tag } from '../../components-ui/tag'; interface IProps { results: ISearchResult[]; diff --git a/components/search-bar/advanced-search-fields.tsx b/components/search-bar/advanced-search-fields.tsx new file mode 100644 index 000000000..27e791cc7 --- /dev/null +++ b/components/search-bar/advanced-search-fields.tsx @@ -0,0 +1,77 @@ +import React from 'react'; +import ButtonLink from '../../components-ui/button'; +import SelectCodeSectionNaf from '../../components-ui/select/select-section-naf'; +import { IParams } from '../../models/search-filter-params'; + +const AdvancedSearchFields: React.FC<{ + searchFilterParams?: IParams; +}> = ({ searchFilterParams }) => { + const { code_postal, section_activite_principale } = searchFilterParams || {}; + + return ( + <> +
+
+ + +
+
+ +
+ + Rechercher + +
+
+ + + ); +}; + +export default AdvancedSearchFields; diff --git a/components/search-bar/index.tsx b/components/search-bar/index.tsx index 8bdc6977d..85de36909 100644 --- a/components/search-bar/index.tsx +++ b/components/search-bar/index.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import SearchField from './search-field'; const SearchBar = ({ placeholder = 'Rechercher un nom, un SIRET ou un SIREN', @@ -7,45 +8,22 @@ const SearchBar = ({ autoFocus = false, }) => { return ( - <> -
-
- - - -
-
+
+ - + ); }; +export { SearchField }; + export default SearchBar; diff --git a/components/search-bar/search-field.tsx b/components/search-bar/search-field.tsx new file mode 100644 index 000000000..975ba22bd --- /dev/null +++ b/components/search-bar/search-field.tsx @@ -0,0 +1,35 @@ +import React from 'react'; + +const SearchField = ({ + placeholder = 'Rechercher un nom, un SIRET ou un SIREN', + defaultValue = '', + autoFocus = false, +}) => ( +
+ + + + +
+); + +export default SearchField; diff --git a/components/section/index.tsx b/components/section/index.tsx index f0b7ee2d5..382871e93 100644 --- a/components/section/index.tsx +++ b/components/section/index.tsx @@ -5,9 +5,9 @@ import { } from '../../models/administration'; import { isTwoMonthOld } from '../../utils/helpers/checks'; import { formatDate, formatDateLong } from '../../utils/helpers/formatting'; +import Warning from '../../components-ui/alerts/warning'; +import DataSourceTooltip from '../../components-ui/information-tooltip/data-source-tooltip'; import { cma, inpi, insee, dila } from '../administrations/logos'; -import Warning from '../alerts/warning'; -import DataSourceTooltip from '../information-tooltip/data-source-tooltip'; interface IAdministrationsLogos { [key: string]: JSX.Element; diff --git a/components/table/simple.tsx b/components/table/simple.tsx index 1810f73a0..410c10e15 100644 --- a/components/table/simple.tsx +++ b/components/table/simple.tsx @@ -1,5 +1,5 @@ import React, { PropsWithChildren } from 'react'; -import { copy, copied } from '../icon'; +import { copy, copied } from '../../components-ui/icon'; interface ISectionProps { body: any[][]; diff --git a/components/title-etablissement-section/index.tsx b/components/title-etablissement-section/index.tsx index fc26067de..2189464e2 100644 --- a/components/title-etablissement-section/index.tsx +++ b/components/title-etablissement-section/index.tsx @@ -2,9 +2,9 @@ import React from 'react'; import { IEtablissement, IUniteLegale } from '../../models'; import { formatSiret } from '../../utils/helpers/siren-and-siret'; import { INSEE } from '../administrations'; -import Warning from '../alerts/warning'; -import IsActiveTag from '../is-active-tag'; -import { Tag } from '../tag'; +import Warning from '../../components-ui/alerts/warning'; +import IsActiveTag from '../../components-ui/is-active-tag'; +import { Tag } from '../../components-ui/tag'; const TitleEtablissement: React.FC<{ uniteLegale: IUniteLegale; diff --git a/components/title-section/index.tsx b/components/title-section/index.tsx index f4a1d13ae..aba78bf20 100644 --- a/components/title-section/index.tsx +++ b/components/title-section/index.tsx @@ -1,14 +1,14 @@ import React from 'react'; import { formatIntFr } from '../../utils/helpers/formatting'; -import { Tag } from '../tag'; -import IsActiveTag from '../is-active-tag'; +import { Tag } from '../../components-ui/tag'; +import IsActiveTag from '../../components-ui/is-active-tag'; import { UnitLegaleDescription } from '../unite-legale-description'; import { IUniteLegale } from '../../models'; -import SocialMedia from '../social-media'; -import { PrintNever } from '../print-visibility'; -import MultipleSirenAlert from '../alerts/multiple-siren'; -import AssociationAdressAlert from '../alerts/association-adress'; +import SocialMedia from '../../components-ui/social-media'; +import { PrintNever } from '../../components-ui/print-visibility'; +import MultipleSirenAlert from '../../components-ui/alerts/multiple-siren'; +import AssociationAdressAlert from '../../components-ui/alerts/association-adress'; export enum FICHE { INFORMATION = 'informations générales', diff --git a/components/unite-legale-section/index.tsx b/components/unite-legale-section/index.tsx index d1b0e56ea..e676e83f1 100644 --- a/components/unite-legale-section/index.tsx +++ b/components/unite-legale-section/index.tsx @@ -3,8 +3,8 @@ import { IUniteLegale } from '../../models'; import { EAdministration } from '../../models/administration'; import { formatDate, formatIntFr } from '../../utils/helpers/formatting'; import { formatSiret } from '../../utils/helpers/siren-and-siret'; -import BreakPageForPrint from '../print-break-page'; -import HorizontalSeparator from '../horizontal-separator'; +import BreakPageForPrint from '../../components-ui/print-break-page'; +import HorizontalSeparator from '../../components-ui/horizontal-separator'; import { Section } from '../section'; import { TwoColumnTable } from '../table/simple'; diff --git a/components/useful-shortcuts/index.tsx b/components/useful-shortcuts/index.tsx index 34b0976b5..38fba7ca5 100644 --- a/components/useful-shortcuts/index.tsx +++ b/components/useful-shortcuts/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; +import HorizontalSeparator from '../../components-ui/horizontal-separator'; +import { PrintNever } from '../../components-ui/print-visibility'; import { IUniteLegale } from '../../models'; -import HorizontalSeparator from '../horizontal-separator'; -import { PrintNever } from '../print-visibility'; const ShortcutsSection: React.FC<{ shortcuts: { label: string; url: string; external?: boolean }[]; diff --git a/layouts/page.tsx b/layouts/page.tsx index 0ef6c4777..7ead7e4d6 100644 --- a/layouts/page.tsx +++ b/layouts/page.tsx @@ -1,16 +1,18 @@ import React from 'react'; import Footer from '../components/footer'; -import { Header, HeaderSmall } from '../components/header'; +import { Header, HeaderSearch } from '../components/header'; import Meta from '../components/meta'; -import { Question } from '../components/question'; +import { Question } from '../components-ui/question'; import { NPSBanner } from '../components/banner/nps'; import { WeNeedYouModal } from '../components/modal/we-need-you'; import DownloadManager from '../components/download-manager'; import { MigrationBanner } from '../components/banner/entreprise-data'; +import { IParams } from '../models/search-filter-params'; interface IProps { small?: boolean; currentSearchTerm?: string; + searchFilterParams?: IParams; map?: boolean; title: string; description?: string; @@ -22,6 +24,7 @@ const Page: React.FC = ({ small, children, currentSearchTerm = '', + searchFilterParams, map = false, title, description, @@ -38,7 +41,11 @@ const Page: React.FC = ({ {small ? : } {small ? ( - + ) : (
)} diff --git a/models/search-filter-params.ts b/models/search-filter-params.ts new file mode 100644 index 000000000..4c9e52204 --- /dev/null +++ b/models/search-filter-params.ts @@ -0,0 +1,43 @@ +import { ParsedUrlQuery } from 'querystring'; + +export interface IParams { + section_activite_principale: string; + code_postal: string; +} + +class SearchFilterParams { + private params: IParams; + + constructor(query: ParsedUrlQuery | IParams = {}) { + const section_activite_principale = (query.section_activite_principale || + '') as string; + const code_postal = (query.code_postal || '') as string; + + this.params = { + section_activite_principale, + code_postal, + }; + } + + public toJSON() { + return this.params || {}; + } + + toURI() { + return Object.keys(this.params).reduce((uri, key) => { + //@ts-ignore + const value = this.params[key]; + + if (!!value) { + uri += `&${key}=${value}`; + } + return uri; + }, ''); + } + + hasParam() { + return Object.values(this.params).some((v) => v !== ''); + } +} + +export default SearchFilterParams; diff --git a/models/search.ts b/models/search.ts index f1efafe42..382d68dd8 100644 --- a/models/search.ts +++ b/models/search.ts @@ -6,6 +6,7 @@ import { isLikelyASiretOrSiren } from '../utils/helpers/siren-and-siret'; import logErrorInSentry from '../utils/sentry'; import { EAdministration } from './administration'; import { APINotRespondingFactory } from './api-not-responding'; +import SearchFilterParams from './search-filter-params'; export interface ISearchResult { siren: string; @@ -28,7 +29,11 @@ export interface ISearchResults { results: ISearchResult[]; } -const search = async (searchTerm: string, page: number) => { +const search = async ( + searchTerm: string, + page: number, + searchFilterParams: SearchFilterParams +) => { try { const cleanedTerm = cleanSearchTerm(searchTerm); @@ -40,8 +45,7 @@ const search = async (searchTerm: string, page: number) => { const escapedSearchTerm = escapeTerm(searchTerm); - const results = await getResults(escapedSearchTerm, page); - return results; + return await getResults(escapedSearchTerm, page, searchFilterParams); } catch (e: any) { if (e instanceof HttpNotFound) { return { diff --git a/pages/dirigeants/[slug].tsx b/pages/dirigeants/[slug].tsx index 3751fec46..2b221e13a 100644 --- a/pages/dirigeants/[slug].tsx +++ b/pages/dirigeants/[slug].tsx @@ -13,7 +13,7 @@ import DirigeantsEntrepriseIndividuelleSection from '../../components/dirigeants import DirigeantsSection from '../../components/dirigeants-section/rncs-dirigeants'; import BeneficiairesSection from '../../components/dirigeants-section/beneficiaires'; import DirigeantSummary from '../../components/dirigeants-section/summary'; -import BreakPageForPrint from '../../components/print-break-page'; +import BreakPageForPrint from '../../components-ui/print-break-page'; const DirigeantsPage: React.FC = ({ uniteLegale, diff --git a/pages/erreur/acces-refuse.tsx b/pages/erreur/acces-refuse.tsx index 421057266..2d017dce6 100644 --- a/pages/erreur/acces-refuse.tsx +++ b/pages/erreur/acces-refuse.tsx @@ -1,6 +1,6 @@ import { GetServerSideProps } from 'next'; import React from 'react'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import Page from '../../layouts'; const Forbidden: React.FC = () => { diff --git a/pages/erreur/fichier-introuvable.tsx b/pages/erreur/fichier-introuvable.tsx index 0ef19ea2e..6224a3b2e 100644 --- a/pages/erreur/fichier-introuvable.tsx +++ b/pages/erreur/fichier-introuvable.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { GetServerSideProps } from 'next'; import Page from '../../layouts'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import constants from '../../models/constants'; const SirenOrSiretNotFoundPage = () => { diff --git a/pages/erreur/introuvable.tsx b/pages/erreur/introuvable.tsx index 87589c5a6..d6364093d 100644 --- a/pages/erreur/introuvable.tsx +++ b/pages/erreur/introuvable.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { GetServerSideProps } from 'next'; import Page from '../../layouts'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; const SirenOrSiretNotFoundPage = () => { return ( diff --git a/pages/erreur/invalide.tsx b/pages/erreur/invalide.tsx index e8de693e6..933698a75 100644 --- a/pages/erreur/invalide.tsx +++ b/pages/erreur/invalide.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { GetServerSideProps } from 'next'; import Page from '../../layouts'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import constants from '../../models/constants'; const SirenOrSiretInvalidPage = () => { diff --git a/pages/erreur/trop-de-demandes.tsx b/pages/erreur/trop-de-demandes.tsx index ab032c85f..4e3ace8b0 100644 --- a/pages/erreur/trop-de-demandes.tsx +++ b/pages/erreur/trop-de-demandes.tsx @@ -1,6 +1,6 @@ import { GetServerSideProps } from 'next'; import React from 'react'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import Page from '../../layouts'; const TooManyRequest: React.FC = () => { diff --git a/pages/faq.tsx b/pages/faq.tsx index 33b9a45ec..66b096ae3 100644 --- a/pages/faq.tsx +++ b/pages/faq.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import constants from '../models/constants'; -import ButtonLink from '../components/button'; +import ButtonLink from '../components-ui/button'; import { DILA, INPI, INSEE, METI, CMA } from '../components/administrations'; import Page from '../layouts'; diff --git a/pages/formulaire/index.tsx b/pages/formulaire/index.tsx index 65eccd102..e763141c7 100644 --- a/pages/formulaire/index.tsx +++ b/pages/formulaire/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import { Header } from '../../components/header'; import randomId from '../../utils/helpers/randomId'; diff --git a/pages/formulaire/merci.tsx b/pages/formulaire/merci.tsx index 4cd801300..4a248e914 100644 --- a/pages/formulaire/merci.tsx +++ b/pages/formulaire/merci.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import ButtonLink from '../../components/button'; +import ButtonLink from '../../components-ui/button'; import { Header } from '../../components/header'; const Thanks: React.FC<{}> = () => { diff --git a/pages/partager/index.tsx b/pages/partager/index.tsx index 9b752bd5b..3bf7c2b72 100644 --- a/pages/partager/index.tsx +++ b/pages/partager/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; import Page from '../../layouts'; -import { qrCode } from '../../components/icon'; +import { qrCode } from '../../components-ui/icon'; const Partager: React.FC = () => { return ( diff --git a/pages/rechercher/carte.tsx b/pages/rechercher/carte.tsx index 2f69e6e2b..b7c4b73c5 100644 --- a/pages/rechercher/carte.tsx +++ b/pages/rechercher/carte.tsx @@ -16,16 +16,23 @@ import HiddenH1 from '../../components/a11y-components/hidden-h1'; import StructuredDataSearchAction from '../../components/structured-data/search'; import { isAPINotResponding } from '../../models/api-not-responding'; import { SearchErrorExplanations } from '../../components/error-explanations'; +import SearchFilterParams, { IParams } from '../../models/search-filter-params'; interface IProps { searchTerm: string; results: ISearchResults; + searchFilterParams: IParams; } -const MapSearchResultPage: React.FC = ({ results, searchTerm }) => ( +const MapSearchResultPage: React.FC = ({ + results, + searchTerm, + searchFilterParams, +}) => ( = ({ results, searchTerm }) => ( export const getServerSideProps: GetServerSideProps = async (context) => { // get params from query string - const searchTermParam = (context.query.terme || '') as string; + const searchTerm = (context.query.terme || '') as string; const pageParam = (context.query.page || '') as string; - const page = parseIntWithDefaultValue(pageParam, 1); + const searchFilterParams = new SearchFilterParams(context.query); try { - const results = (await search(searchTermParam, page)) || {}; + const results = (await search(searchTerm, page, searchFilterParams)) || {}; return { props: { results, - searchTerm: searchTermParam, + searchTerm, + searchFilterParams: searchFilterParams.toJSON(), }, }; } catch (e: any) { diff --git a/pages/rechercher/index.tsx b/pages/rechercher/index.tsx index 06686b521..fab0a1476 100644 --- a/pages/rechercher/index.tsx +++ b/pages/rechercher/index.tsx @@ -17,16 +17,23 @@ import HiddenH1 from '../../components/a11y-components/hidden-h1'; import StructuredDataSearchAction from '../../components/structured-data/search'; import { isAPINotResponding } from '../../models/api-not-responding'; import { SearchErrorExplanations } from '../../components/error-explanations'; +import SearchFilterParams, { IParams } from '../../models/search-filter-params'; interface IProps { searchTerm: string; results: ISearchResults; + searchFilterParams: IParams; } -const SearchResultPage: React.FC = ({ results, searchTerm }) => ( +const SearchResultPage: React.FC = ({ + results, + searchTerm, + searchFilterParams, +}) => ( @@ -97,16 +104,18 @@ const SearchResultPage: React.FC = ({ results, searchTerm }) => ( export const getServerSideProps: GetServerSideProps = async (context) => { // get params from query string - const searchTermParam = (context.query.terme || '') as string; + const searchTerm = (context.query.terme || '') as string; const pageParam = (context.query.page || '') as string; const page = parseIntWithDefaultValue(pageParam, 1); + const searchFilterParams = new SearchFilterParams(context.query); try { - const results = (await search(searchTermParam, page)) || {}; + const results = (await search(searchTerm, page, searchFilterParams)) || {}; return { props: { results, - searchTerm: searchTermParam, + searchTerm, + searchFilterParams: searchFilterParams.toJSON(), }, }; } catch (e: any) { diff --git a/utils/labels/codes-section-NAF.ts b/utils/labels/codes-section-NAF.ts new file mode 100644 index 000000000..b02a3a1fe --- /dev/null +++ b/utils/labels/codes-section-NAF.ts @@ -0,0 +1,23 @@ +export const codesSectionNaf = { + A: 'Agriculture, sylviculture et pêche', + B: 'Industries extractives', + C: 'Industrie manufacturière', + D: 'Électricité, gaz, vapeur et air conditionné', + E: 'Eau, assainissement, gestion des déchets et dépollution', + F: 'Construction', + G: "Commerce; réparation d'automobiles et de motocycles", + H: 'Transports et entreposage', + I: 'Hébergement et restauration', + J: 'Information et communication', + K: "Activités financières et d'assurance", + L: 'Activités immobilières', + M: 'Activités spécialisées, scientifiques et techniques', + N: 'Activités de services administratifs et de soutien', + O: 'Administration publique', + P: 'Enseignement', + Q: 'Santé humaine et action sociale', + R: 'Arts, spectacles et activités récréatives', + S: 'Autres activités de services', + T: "Activités des ménages en tant qu'employeurs", + U: 'Activités extra-territoriales', +}; diff --git a/utils/labels/index.ts b/utils/labels/index.ts index fd70a6620..d7893999d 100644 --- a/utils/labels/index.ts +++ b/utils/labels/index.ts @@ -10,6 +10,12 @@ export const libelleFromCodeNaf = (codeNaf = '', addCode = true) => { return addCode && codeNaf ? `${codeNaf} - ${label}` : label; }; +export const libelleFromCodeSectionNaf = (codeSectionNaf = '') => { + //@ts-ignore + const label = codeSectionNaf[codeSectionNaf] || 'Activité inconnue'; + return label; +}; + export const libelleFromCodeEffectif = ( codeEffectif: string, anneeEffectif?: string,