Skip to content

Commit

Permalink
fix(email-sender): fix url, add a graph, and tag for productions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed May 27, 2024
1 parent bd9037d commit 3ef75ba
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 43 deletions.
18 changes: 14 additions & 4 deletions src/api/send-mail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("");

Expand Down Expand Up @@ -74,6 +78,7 @@ function EmailSender({
setResponseScanR(dataForScanR);
setEmailSent(true);
toast.success("Mail envoyé!");
setUserResponse("");
};

return (
Expand All @@ -88,7 +93,12 @@ function EmailSender({
/>
</Col>
<Col>
<Button variant="secondary" onClick={sendEmail} size="sm">
<Button
className="fr-mt-1w"
variant="secondary"
onClick={sendEmail}
size="sm"
>
{contribution.comment ? "Renvoyer un mail" : "Répondre"}
</Button>
</Col>
Expand Down
10 changes: 5 additions & 5 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -58,13 +58,13 @@ const EditModal: React.FC<EditModalProps> = ({ 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",
Expand Down
65 changes: 65 additions & 0 deletions src/components/graphs/by-missing-productions.tsx
Original file line number Diff line number Diff line change
@@ -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 <div>Chargement...</div>;
}

if (isError) {
return <div>Une erreur s'est produite</div>;
}

if (!Array.isArray(contributions)) {
return <div>Les données ne sont pas disponibles</div>;
}

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 <HighchartsReact highcharts={Highcharts} options={options} />;
};

export default ContributionsGraphByStatus;
8 changes: 4 additions & 4 deletions src/config/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
10 changes: 10 additions & 0 deletions src/pages/api-operation-page/contribution-production-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ const ContributionProductionItem = ({
>
{data.status}
</Badge>
{data.tag && (
<Badge
size="sm"
color="pink-tuile"
className="fr-mr-1w fr-mb-1w status"
>
{data.tag}
</Badge>
)}

<Badge
size="sm"
color="green-emeraude"
Expand Down
1 change: 0 additions & 1 deletion src/pages/api-operation-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const ContributionPage: React.FC<ContributionPageProps> = () => {
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;
Expand Down
30 changes: 1 addition & 29 deletions src/pages/api-operation-page/message-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,9 @@ const MessagePreview = ({ data }: { data: Contribute_Production }) => {
const handleCloseModal = () => {
setShowModal(false);
};

return (
<Container fluid>
<EditModal
isOpen={showModal}
onClose={handleCloseModal}
data-production={data}
data={{
responseByMail: "",
responseFrom: "",
modified_at: "",
team: undefined,
_id: undefined,
status: "",
tags: undefined,
message: "",
created_at: "",
fonction: undefined,
organisation: undefined,
email: undefined,
name: undefined,
type: "",
id: "",
comment: "",
data: [],
meta: {
total: 0,
},
highlightedQuery: "",
}}
/>
<EditModal isOpen={showModal} onClose={handleCloseModal} data={data} />
<Row className="contributorProductionSideInfo">
{data.id && (
<Text
Expand Down
1 change: 1 addition & 0 deletions src/pages/api-operation-page/staff-production-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import EmailSender from "../../api/send-mail";
import type { Contribute_Production } from "../../types";
import { useState } from "react";
import { Col, Text } from "@dataesr/dsfr-plus";
import "./styles.scss";

const StaffProductionActions = ({ data }: { data: Contribute_Production }) => {
const [responseScanR, setResponseScanR] = useState(null);
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -44,6 +45,11 @@ const Home = () => {
<AdminResponseGraph />
</Col>
</Row>
<Row gutters className="fr-grid-row--center fr-mt-5w">
<Col md="6">
<ContributionsGraphByProductions />
</Col>
</Row>
</Container>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type MessagePreviewProps = {
};

export type Contribute_Production = {
tag: string;
_id: string;
team: any;
modified_at: string | number | Date;
Expand Down

0 comments on commit 3ef75ba

Please sign in to comment.