Skip to content

Commit

Permalink
fix(productions): clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jun 12, 2024
1 parent 4e7c068 commit 81cf035
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ContributorRequests: React.FC<{
}> = ({ data, setDataList, coloredName, dataList }) => {
const [copiedId, setCopiedId] = useState<string | null>(null);
const [selectedIds, setSelectedIds] = useState<string[]>([]);
const [, setIsSelected] = useState(false);

useEffect(() => {
setSelectedIds(dataList.map((item) => item.publi_id));
Expand Down Expand Up @@ -72,7 +71,6 @@ const ContributorRequests: React.FC<{
idRef={data.id}
coloredName={coloredName}
setSelectedId={setSelectedIds}
setIsSelected={setIsSelected}
/>
</Col>
<Col style={{ flex: 1 }}>
Expand Down
40 changes: 15 additions & 25 deletions src/pages/api-operation-page/link-publications/name-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ 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,
setDataList,
idRef,
coloredName,
setSelectedId,
setIsSelected,
}) {
const { fullName, firstName, lastName } = NameFromScanr(productionId);
const [selectedOption, setSelectedOption] = useState(null);

const customStyles = {
option: (provided, state) => ({
...provided,
Expand All @@ -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,
Expand Down

0 comments on commit 81cf035

Please sign in to comment.