Skip to content

Commit

Permalink
fix(mandate): add possibility to search with acronym of relation type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Nov 5, 2024
1 parent 8229247 commit b6f7d18
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/forms/mandate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export default function MandateForm({ id, resourceType, relatedObjectTypes, data
const relationTypeUrl = (relatedObjectTypes.length > 1)
? `/relation-types?limit=500&filters[for][$in]=${relatedObjectTypes.join('&filters[for][$in]=')}`
: `/relation-types?limit=500&filters[for]=${relatedObjectTypes[0]}`;

const { data: relationTypes } = useFetch(relationTypeUrl);

const [showErrors, setShowErrors] = useState(false);

const [relatedObjectQuery, setRelatedObjectQuery] = useState('');
Expand Down Expand Up @@ -173,14 +171,18 @@ export default function MandateForm({ id, resourceType, relatedObjectTypes, data
return onSave(body, id);
};

const relationTypesOptions = (relationTypes?.data)
const relationTypesOptions = (Array.isArray(relationTypes?.data))
? [
{ label: 'Appartient à la liste', value: null },
...relationTypes.data
.map((element) => ({ label: element.name, value: element.id }))
.sort((a, b) => a.label > b.label),
.map((element) => ({
label: `${element?.name ?? 'Nom inconnu'}${element?.acronym ? ` (${element.acronym})` : ''}`,
value: element?.id ?? null,
}))
.sort((a, b) => a.label.localeCompare(b.label)),
]
: [{ label: 'Appartient à la liste', value: null }];

return (
<form>
<Container fluid>
Expand Down

0 comments on commit b6f7d18

Please sign in to comment.