Skip to content

Commit

Permalink
feat(basket): update prod display, add delete and change name page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jun 12, 2024
1 parent b3f293c commit 4e7c068
Show file tree
Hide file tree
Showing 20 changed files with 383 additions and 194 deletions.
71 changes: 55 additions & 16 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from "react";

import {
Modal,
ModalTitle,
Expand All @@ -12,6 +13,7 @@ import {
import { Contribute_Production, Contribution, Inputs } from "../../types";
import { postHeaders } from "../../config/api";
import Select from "react-select";
import { toast } from "react-toastify";

type EditModalProps = {
isOpen: boolean;
Expand All @@ -20,6 +22,8 @@ type EditModalProps = {
refetch;
};

// const queryClient = useQueryClient();

const EditModal: React.FC<EditModalProps> = ({
isOpen,
data,
Expand All @@ -41,33 +45,37 @@ const EditModal: React.FC<EditModalProps> = ({
const [inputs, setInputs] = useState<Inputs>({
team: [user],
status: "treated",
tag: [],
tags: [],
idRef: "",
comment: "",
});
useEffect(() => {
setInputs({
team: [user],
status: "treated",
tag: [],
tags: [],
idRef: "",
comment: "",
});
}, [data, user]);

const handleStatusChange = (selectedOption) => {
setInputs((prevInputs) => ({
...prevInputs,
status: selectedOption.value,
}));
};

const handleTagChange = (event) => {
const newTag = event.target.value;
setInputs((prevInputs) => ({
...prevInputs,
tag: [...prevInputs.tag, newTag],
}));
setInputs((prevInputs) => {
const { tags } = prevInputs;
if (tags.length > 0) {
tags.pop();
}
return {
...prevInputs,
tags: [...tags, newTag],
};
});
};
const handleCommentChange = (event) => {
const newComment = event.target.value;
Expand All @@ -81,26 +89,57 @@ const EditModal: React.FC<EditModalProps> = ({

const handleSubmit = async () => {
try {
const body: {
status?: string;
tags?: string[];
team?: string[];
idref?: string;
comment?: string;
} = {};

if (inputs.status) {
body.status = inputs.status;
}

if (inputs.tags) {
body.tags = inputs.tags;
}
if (inputs.team) {
body.team = inputs.team;
}

if (inputs.idRef) {
body.idref = inputs.idRef;
}

if (inputs.comment) {
body.comment = inputs.comment;
}

const response = await fetch(url, {
method: "PATCH",
headers: postHeaders,
body: JSON.stringify({
status: inputs.status,
tag: inputs.tag,
idref: inputs.idRef,
comment: inputs.comment,
}),
body: JSON.stringify(body),
});

if (!response.ok) {
console.log("Erreur de réponse", response);
} else {
const responseData = await response.json();
console.log("Données de réponse", responseData);
refetch();
onClose();

if (inputs.tags) {
toast.success("Nouveau tag ajouté!");
} else if (inputs.comment) {
toast.success("Nouveau commentaire ajouté!");
} else if (inputs.idRef) {
toast.success("Nouvelle référence ajoutée!");
}
}
} catch (error) {
console.error(error);
console.error("Erreur lors de la soumission du formulaire", error);
}
};

Expand Down Expand Up @@ -143,7 +182,7 @@ const EditModal: React.FC<EditModalProps> = ({
label="Ajouter un tag"
maxLength={6}
hint="Décrivez en un mot la contribution"
value={inputs.tag}
value={inputs.tags}
onChange={handleTagChange}
/>
</Col>
Expand Down
22 changes: 17 additions & 5 deletions src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Nav,
FastAccess,
Button,
NavItem,
} from "@dataesr/dsfr-plus";
import ProfileModal from "../components/profil-modal";

Expand Down Expand Up @@ -91,12 +92,23 @@ const Header: React.FC = () => {
<Link current={pathname.startsWith("/contact")} href="/contact">
Contributions via formulaire de contact
</Link>
<Link
current={pathname.startsWith("/apioperations")}
href="/apioperations"
<NavItem
current={pathname.split("/").includes("search")}
title={"Opérations sur l'API"}
>
Opérations sur l'API
</Link>
<Link
current={pathname.startsWith("/apioperations")}
href="/apioperations"
>
Lier des publications
</Link>
<Link current={pathname.startsWith("/delete")} href="/delete">
Supprimer des personnes de la base de donnée
</Link>
<Link current={pathname.startsWith("/namechange")} href="/namechange">
Changer le nom d'une personne
</Link>
</NavItem>
</Nav>
</HeaderWrapper>
);
Expand Down
75 changes: 0 additions & 75 deletions src/pages/api-operation-page/contributor-requests.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/pages/api-operation-page/external-links.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import {
Text,
} from "@dataesr/dsfr-plus";
import "./styles.scss";
import { Contribute_Production } from "../../types";
import { Contribute_Production } from "../../../types";
import ContributorProductionInfo from "./contributor-production-info";
import StaffProductionActions from "./staff-production-action";

const ContributionProductionItem = ({
data,
refetch,
setDataList,
dataList,
}: {
data: Contribute_Production;
refetch;
setDataList;
dataList;
}) => {
const renderAccordion = () => (
<Container fluid className="accordion">
Expand Down Expand Up @@ -72,6 +74,7 @@ const ContributionProductionItem = ({
data={data}
refetch={refetch}
setDataList={setDataList}
dataList={dataList}
/>
<StaffProductionActions data={data} refetch={refetch} />
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { Contribute_Production } from "../../types";
import { Contribute_Production } from "../../../types";
import MessagePreview from "./message-preview";

const ContributorProductionInfo = ({
data,
refetch,
setDataList,
dataList,
}: {
data: Contribute_Production;
refetch;
setDataList;
dataList;
}) => {
return (
<MessagePreview data={data} refetch={refetch} setDataList={setDataList} />
<MessagePreview
dataList={dataList}
data={data}
refetch={refetch}
setDataList={setDataList}
/>
);
};

Expand Down
Loading

0 comments on commit 4e7c068

Please sign in to comment.