From 81cf03566f374beb08cbc4e7f8009f4d35956fa3 Mon Sep 17 00:00:00 2001 From: Mihoub Date: Wed, 12 Jun 2024 10:28:54 +0200 Subject: [PATCH] fix(productions): clean code --- .../contributor-requests.tsx | 2 - .../link-publications/name-selector.tsx | 40 +++++++------------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/pages/api-operation-page/link-publications/contributor-requests.tsx b/src/pages/api-operation-page/link-publications/contributor-requests.tsx index 5b3c378..d28e071 100644 --- a/src/pages/api-operation-page/link-publications/contributor-requests.tsx +++ b/src/pages/api-operation-page/link-publications/contributor-requests.tsx @@ -17,7 +17,6 @@ const ContributorRequests: React.FC<{ }> = ({ data, setDataList, coloredName, dataList }) => { const [copiedId, setCopiedId] = useState(null); const [selectedIds, setSelectedIds] = useState([]); - const [, setIsSelected] = useState(false); useEffect(() => { setSelectedIds(dataList.map((item) => item.publi_id)); @@ -72,7 +71,6 @@ const ContributorRequests: React.FC<{ idRef={data.id} coloredName={coloredName} setSelectedId={setSelectedIds} - setIsSelected={setIsSelected} /> diff --git a/src/pages/api-operation-page/link-publications/name-selector.tsx b/src/pages/api-operation-page/link-publications/name-selector.tsx index f213c8a..948b55d 100644 --- a/src/pages/api-operation-page/link-publications/name-selector.tsx +++ b/src/pages/api-operation-page/link-publications/name-selector.tsx @@ -3,7 +3,6 @@ import "react-toastify/dist/ReactToastify.css"; import NameFromScanr from "../../../api/contribution-api/getNames"; import { levenshteinDistance } from "../utils/compare"; import { Col, Row } from "@dataesr/dsfr-plus"; -import { useEffect, useState } from "react"; export default function SelectWithNames({ productionId, @@ -11,10 +10,9 @@ export default function SelectWithNames({ idRef, coloredName, setSelectedId, - setIsSelected, }) { const { fullName, firstName, lastName } = NameFromScanr(productionId); - const [selectedOption, setSelectedOption] = useState(null); + const customStyles = { option: (provided, state) => ({ ...provided, @@ -24,30 +22,22 @@ export default function SelectWithNames({ const threshold = 7; - const handleChange = (option) => { - setSelectedOption(option); - }; + const handleChange = (option: { value: any }) => { + const selectedIndex = fullName.indexOf(option.value); - useEffect(() => { - const optionToValidate = - selectedOption || options.find((option) => option.label === coloredName); + setDataList((prevState) => [ + ...prevState, + { + fullName: option.value, + person_id: idRef, + publi_id: productionId, + first_name: firstName[selectedIndex], + last_name: lastName[selectedIndex], + }, + ]); - if (optionToValidate) { - const selectedIndex = fullName.indexOf(optionToValidate.value); - setDataList((prevState) => [ - ...prevState, - { - fullName: optionToValidate.value, - person_id: idRef, - publi_id: productionId, - first_name: firstName[selectedIndex], - last_name: lastName[selectedIndex], - }, - ]); - setSelectedId((prevIds) => [...prevIds, productionId]); - setIsSelected(true); - } - }, [selectedOption]); + setSelectedId((prevIds) => [...prevIds, productionId]); + }; const options = fullName.map((name, index) => ({ value: name,