diff --git a/src/api/send-mail/index.tsx b/src/api/send-mail/index.tsx index 3fd8a8b..bf1229b 100644 --- a/src/api/send-mail/index.tsx +++ b/src/api/send-mail/index.tsx @@ -13,9 +13,13 @@ function EmailSender({ }) { const [, setEmailSent] = useState(false); const [userResponse, setUserResponse] = useState(""); - const basePath = window.location.pathname.includes("contact") - ? "contact" - : "contribute"; + let basePath = "contact"; + + if (window.location.pathname.includes("contribute")) { + basePath = "contribute"; + } else if (window.location.pathname.includes("apioperations")) { + basePath = "contribute_productions"; + } const [selectedProfile, setSelectedProfile] = useState(""); @@ -74,6 +78,7 @@ function EmailSender({ setResponseScanR(dataForScanR); setEmailSent(true); toast.success("Mail envoyé!"); + setUserResponse(""); }; return ( @@ -88,7 +93,12 @@ function EmailSender({ /> - diff --git a/src/components/edit-modal/index.tsx b/src/components/edit-modal/index.tsx index 09a05ac..97f40c4 100644 --- a/src/components/edit-modal/index.tsx +++ b/src/components/edit-modal/index.tsx @@ -9,13 +9,13 @@ import { Button, Row, } from "@dataesr/dsfr-plus"; -import { Contribution } from "../../types"; +import { Contribute_Production, Contribution } from "../../types"; import { postHeaders } from "../../config/api"; import Select from "react-select"; type EditModalProps = { isOpen: boolean; - data: Contribution; + data: Contribution | Contribute_Production; onClose: () => void; }; @@ -58,13 +58,13 @@ const EditModal: React.FC = ({ isOpen, data, onClose }) => { if (window.location.pathname.includes("contribute")) { basePath = "contribute"; - } else if (window.location.pathname.includes("contribute_production")) { - basePath = "contribute_production"; + } else if (window.location.pathname.includes("apioperations")) { + basePath = "contribute_productions"; } - const handleSubmit = async () => { try { const response = await fetch( + // `https://scanr-api.dataesr.ovh/${basePath}/${data._id}`, `${window.location.origin}/api/${basePath}/${data._id}`, { method: "PATCH", diff --git a/src/components/graphs/by-missing-productions.tsx b/src/components/graphs/by-missing-productions.tsx new file mode 100644 index 0000000..f249085 --- /dev/null +++ b/src/components/graphs/by-missing-productions.tsx @@ -0,0 +1,65 @@ +import Highcharts from "highcharts"; +import HighchartsReact from "highcharts-react-official"; +import useGetContributionData from "../../api/contribution-api/useGetObjectContributeData"; +import { Contribute_Production } from "../../types"; +import { productionUrl } from "../../config/api"; + +const ContributionsGraphByStatus = () => { + const { data, isLoading, isError } = useGetContributionData(productionUrl, 0); + const contributions = (data as { data: Contribute_Production[] })?.data; + + if (isLoading) { + return
Chargement...
; + } + + if (isError) { + return
Une erreur s'est produite
; + } + + if (!Array.isArray(contributions)) { + return
Les données ne sont pas disponibles
; + } + + const newCount = contributions.filter( + (contribution) => contribution.status === "new" + ).length; + const ongoingCount = contributions.filter( + (contribution) => contribution.status === "ongoing" + ).length; + const treatedCount = contributions.filter( + (contribution) => contribution.status === "treated" + ).length; + + const chartData = [ + { name: "New", y: newCount }, + { name: "Ongoing", y: ongoingCount }, + { name: "Treated", y: treatedCount }, + ]; + + const options = { + chart: { + type: "column", + }, + title: { + text: "Nombre de demande d'affiliation par statut", + }, + xAxis: { + type: "category", + }, + yAxis: { + title: { + text: "Nombre de contributions", + }, + }, + series: [ + { + name: "Statut", + data: chartData, + }, + ], + }; + + return ; +}; + +export default ContributionsGraphByStatus; diff --git a/src/config/api.ts b/src/config/api.ts index 47220dd..aa151e6 100644 --- a/src/config/api.ts +++ b/src/config/api.ts @@ -3,11 +3,11 @@ export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {}; export const postHeaders = { ...headers, "Content-Type": "application/json" }; export const contributionUrl = "/api/contribute?max_results=2000"; +export const contactUrl = "/api/contact?max_results=2000"; +export const productionUrl = "/api/contribute_productions?max_results=2000"; // export const contributionUrl = // "https://scanr-api.dataesr.ovh/contribute?max_results=2000"; -export const contactUrl = "/api/contact?max_results=2000"; // export const contactUrl = -// "https://scanr-api.dataesr.ovh/contact?max_results=2000"; +// "https://scanr-api.dataesr.ovh/contact?max_results=2000"; // export const productionUrl = -// "https://scanr-api.dataesr.ovh/contribute_production?max_results=2000"; -export const productionUrl = "/api/contribute_production?max_results=2000"; +// "https://scanr-api.dataesr.ovh/contribute_productions?max_results=2000"; diff --git a/src/pages/api-operation-page/contribution-production-card.tsx b/src/pages/api-operation-page/contribution-production-card.tsx index 1de4b98..bf4e7aa 100644 --- a/src/pages/api-operation-page/contribution-production-card.tsx +++ b/src/pages/api-operation-page/contribution-production-card.tsx @@ -28,6 +28,16 @@ const ContributionProductionItem = ({ > {data.status} + {data.tag && ( + + {data.tag} + + )} + = () => { buildURL(sort, status, query, page), reload ); - console.log(data); const meta = (data as { meta: any }).meta; const maxPage = meta ? Math.ceil(meta?.total / 10) : 1; diff --git a/src/pages/api-operation-page/message-preview.tsx b/src/pages/api-operation-page/message-preview.tsx index 512c260..79b5396 100644 --- a/src/pages/api-operation-page/message-preview.tsx +++ b/src/pages/api-operation-page/message-preview.tsx @@ -23,37 +23,9 @@ const MessagePreview = ({ data }: { data: Contribute_Production }) => { const handleCloseModal = () => { setShowModal(false); }; - return ( - + {data.id && ( { const [responseScanR, setResponseScanR] = useState(null); diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 1e2792b..e36aaf7 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -7,6 +7,7 @@ import ContributionsGraphByDomains from "../../components/graphs/by-domains"; import ContributionsGraphByTypes from "../../components/graphs/by-types"; import AdminTreatmentGraph from "../../components/graphs/treatment-by-admin"; import AdminResponseGraph from "../../components/graphs/response-by-admin"; +import ContributionsGraphByProductions from "../../components/graphs/by-missing-productions"; const Home = () => { return ( @@ -44,6 +45,11 @@ const Home = () => { + + + + + ); }; diff --git a/src/types/index.ts b/src/types/index.ts index 3555f00..527e687 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -54,6 +54,7 @@ export type MessagePreviewProps = { }; export type Contribute_Production = { + tag: string; _id: string; team: any; modified_at: string | number | Date;