diff --git a/src/pages/api-operation-page/contributor-requests.tsx b/src/pages/api-operation-page/contributor-requests.tsx index 34fdf98..ecb03fa 100644 --- a/src/pages/api-operation-page/contributor-requests.tsx +++ b/src/pages/api-operation-page/contributor-requests.tsx @@ -11,7 +11,8 @@ const ContributorRequests: React.FC<{ productions: Production[]; }; setDataList; -}> = ({ data, setDataList }) => { + coloredName; +}> = ({ data, setDataList, coloredName }) => { const [copiedId, setCopiedId] = useState(null); const copyToClipboard = (text: string) => { @@ -57,13 +58,14 @@ const ContributorRequests: React.FC<{ productionId={production.id} setDataList={setDataList} idRef={data.id} + coloredName={coloredName} /> + + + + + - - - - - ))} diff --git a/src/pages/api-operation-page/export-to-xlsx.tsx b/src/pages/api-operation-page/export-to-xlsx.tsx index 64dc746..635049a 100644 --- a/src/pages/api-operation-page/export-to-xlsx.tsx +++ b/src/pages/api-operation-page/export-to-xlsx.tsx @@ -1,4 +1,4 @@ -import { Button, Text } from "@dataesr/dsfr-plus"; +import { Button, Col, Row, Text, Title } from "@dataesr/dsfr-plus"; import * as XLSX from "xlsx"; import { AiOutlineDelete } from "react-icons/ai"; @@ -22,16 +22,33 @@ const ExcelExportButton = ({ dataList, setDataList }) => { return (
+ + Liste des publications à exporter + diff --git a/src/pages/api-operation-page/index.tsx b/src/pages/api-operation-page/index.tsx index 0b04e8a..e0a2637 100644 --- a/src/pages/api-operation-page/index.tsx +++ b/src/pages/api-operation-page/index.tsx @@ -62,7 +62,6 @@ const ContributionPage: React.FC = () => { setData(fetchedData); }, [fetchedData]); const [dataList, setDataList] = useState([]); - console.log(dataList); const meta = (fetchedData as { meta: any })?.meta; const maxPage = meta ? Math.ceil(meta?.total / 10) : 1; const contrib: Contribute_Production[] = ( @@ -130,7 +129,9 @@ const ContributionPage: React.FC = () => { setDataList={setDataList} /> ))} - + {dataList.length > 0 && ( + + )} copyToClipboard(fetchedData, "Nom copié")} > - {fetchedData ? `${fetchedData}` : "Nom inéxistant sur scanR"} + {fetchedData + ? `${fetchedData} ${data.name}` + : "Nom non-inéxistant sur scanR"} {copySuccess === "Nom copié" && ( - {copySuccess} + Copié ! )} + + {"Nom lié à l'idref "} + {data.name} + + {data.email && ( - + diff --git a/src/pages/api-operation-page/name-selector.tsx b/src/pages/api-operation-page/name-selector.tsx index 460a2b5..2199c2f 100644 --- a/src/pages/api-operation-page/name-selector.tsx +++ b/src/pages/api-operation-page/name-selector.tsx @@ -1,15 +1,29 @@ +import ReactSelect from "react-select"; import NameFromScanr from "../../api/contribution-api/getNames"; +import { levenshteinDistance } from "./utils/compare"; -export default function SelectWithNames({ productionId, setDataList, idRef }) { +export default function SelectWithNames({ + productionId, + setDataList, + idRef, + coloredName, +}) { const { fullName, firstName, lastName } = NameFromScanr(productionId); - const handleChange = (event) => { - const selectedName = event.target.value; - const selectedIndex = fullName.indexOf(selectedName); + const customStyles = { + option: (provided, state) => ({ + ...provided, + color: state.data.isColored ? "#1f8d49" : "black", + }), + }; + + const threshold = 10; + const handleChange = (selectedOption) => { + const selectedIndex = fullName.indexOf(selectedOption.value); setDataList((prevState) => [ ...prevState, { - fullName: selectedName, + fullName: selectedOption.value, person_id: idRef, publi_id: productionId, first_name: firstName[selectedIndex], @@ -18,14 +32,19 @@ export default function SelectWithNames({ productionId, setDataList, idRef }) { ]); }; + const options = fullName.map((name, index) => ({ + value: name, + label: name, + firstName: firstName[index], + isColored: levenshteinDistance(name, coloredName) <= threshold, + })); + return ( - + ); } diff --git a/src/pages/api-operation-page/styles.scss b/src/pages/api-operation-page/styles.scss index 1f15728..2a1c691 100644 --- a/src/pages/api-operation-page/styles.scss +++ b/src/pages/api-operation-page/styles.scss @@ -23,7 +23,7 @@ position: fixed; right: 0; top: 0; - padding: 20px; + padding: 10px; display: flex; justify-content: center; align-items: center; @@ -34,3 +34,8 @@ border-radius: 20px; border: 2px solid black; } +.basket-item { + display: flex; + flex-direction: column; + align-items: center; +} diff --git a/src/pages/api-operation-page/utils/compare.tsx b/src/pages/api-operation-page/utils/compare.tsx new file mode 100644 index 0000000..9e24ff2 --- /dev/null +++ b/src/pages/api-operation-page/utils/compare.tsx @@ -0,0 +1,19 @@ +export const levenshteinDistance = (s, t) => { + if (!s.length) return t.length; + if (!t.length) return s.length; + const arr = []; + for (let i = 0; i <= t.length; i++) { + arr[i] = [i]; + for (let j = 1; j <= s.length; j++) { + arr[i][j] = + i === 0 + ? j + : Math.min( + arr[i - 1][j] + 1, + arr[i][j - 1] + 1, + arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1) + ); + } + } + return arr[t.length][s.length]; +};