Skip to content

Commit

Permalink
fix(email): instant update state to display new sent mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed May 22, 2024
1 parent 2c3df2a commit b05dc3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/api/send-mail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { Button, Col, Container, Row, TextArea } from "@dataesr/dsfr-plus";
import { Contribution } from "../../types";
import { postHeaders } from "../../config/api";
import { toast } from "react-toastify";
function EmailSender({ contribution }: { contribution: Contribution }) {

function EmailSender({
contribution,
setResponseScanR,
}: {
contribution: Contribution;
setResponseScanR: any;
}) {
const [, setEmailSent] = useState(false);
const [userResponse, setUserResponse] = useState("");
const basePath = window.location.pathname.includes("contact")
Expand Down Expand Up @@ -60,7 +67,7 @@ function EmailSender({ contribution }: { contribution: Contribution }) {
if (!responseScanR.ok) {
throw new Error(`HTTP error! status: ${responseScanR.status}`);
}

setResponseScanR(dataForScanR);
setEmailSent(true);
toast.success("Mail envoyé!");
};
Expand Down
11 changes: 6 additions & 5 deletions src/pages/contribution-page/staff-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import { Col, Text } from "@dataesr/dsfr-plus";
import EmailSender from "../../api/send-mail";
import type { Contribution } from "../../types";
import { useLocation } from "react-router-dom";
import { useState } from "react";

const StaffActions = ({ data }: { data: Contribution }) => {
const location = useLocation();
const [responseScanR, setResponseScanR] = useState(null);
const contributorClassName = location.pathname.includes("contributionpage")
? "staffSide"
: "staffSideContact";

return (
<>
{data?.comment && (
<Col className={contributorClassName}>
<Text size="sm">
Réponse apportée par {data?.responseFrom || data.team[0]} le{" "}
{new Date(data?.modified_at).toLocaleDateString()}{" "}
Réponse apportée par {responseScanR?.responseFrom || data.team[0]}{" "}
le {new Date(data?.modified_at).toLocaleDateString()}{" "}
</Text>
<Text>{data?.comment}</Text>
<Text>{responseScanR?.comment || data.comment}</Text>
</Col>
)}
<EmailSender contribution={data} />
<EmailSender contribution={data} setResponseScanR={setResponseScanR} />
</>
);
};
Expand Down

0 comments on commit b05dc3c

Please sign in to comment.