fix(commune): do not display foreign departement when selecting commune

This commit is contained in:
Paul Chavard 2021-11-25 13:28:40 +03:00
parent 58474beba5
commit 7d189575af
2 changed files with 14 additions and 2 deletions

View file

@ -91,6 +91,7 @@ function ComboCommunesSearch(params) {
inputId={!departementCode ? inputId : null}
aria-describedby={departementDescribedBy}
placeholder={placeholderDepartement}
addForeignDepartement={false}
required={params.mandatory}
onChange={(value, result) => {
setDepartementCode(result?.code);

View file

@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { QueryClientProvider } from 'react-query';
import { matchSorter } from 'match-sorter';
@ -16,14 +17,19 @@ function expandResultsWithForeignDepartement(term, results) {
];
}
export function ComboDepartementsSearch(params) {
export function ComboDepartementsSearch({
addForeignDepartement = true,
...params
}) {
return (
<ComboSearch
{...params}
scope="departements"
minimumInputLength={1}
transformResult={({ code, nom }) => [code, `${code} - ${nom}`]}
transformResults={expandResultsWithForeignDepartement}
transformResults={
addForeignDepartement ? expandResultsWithForeignDepartement : undefined
}
/>
);
}
@ -39,4 +45,9 @@ function ComboDepartementsSearchDefault(params) {
);
}
ComboDepartementsSearch.propTypes = {
...ComboSearch.propTypes,
addForeignDepartement: PropTypes.bool
};
export default ComboDepartementsSearchDefault;