-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
532 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { postHeaders } from "../../config/api"; | ||
import { buildURL } from "../utils/buildURL"; | ||
|
||
const ContributionData = ({ | ||
location, | ||
sort, | ||
status, | ||
query, | ||
page, | ||
searchInMessage, | ||
}) => { | ||
const fetchContributions = async () => { | ||
const url = buildURL(location, sort, status, query, page, searchInMessage); | ||
const response = await fetch(url, { | ||
headers: postHeaders, | ||
}); | ||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
return response.json(); | ||
}; | ||
|
||
const { data, isLoading, isError, refetch } = useQuery( | ||
[location, sort, status, query, page, searchInMessage], | ||
fetchContributions | ||
); | ||
|
||
return { data, isLoading, isError, refetch }; | ||
}; | ||
|
||
export default ContributionData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ import { toast } from "react-toastify"; | |
|
||
function EmailSender({ | ||
contribution, | ||
setResponseScanR, | ||
refetch, | ||
}: { | ||
contribution: Contribution | Contribute_Production; | ||
setResponseScanR: any; | ||
refetch; | ||
}) { | ||
const [, setEmailSent] = useState(false); | ||
const [userResponse, setUserResponse] = useState(""); | ||
|
@@ -38,15 +38,22 @@ function EmailSender({ | |
to: [ | ||
{ | ||
email: "[email protected]", | ||
name: "Mihoub mihoub", | ||
name: "Mihoub Debache", | ||
}, | ||
], | ||
subject: `Réponse à votre contribution`, | ||
htmlContent: userResponse, | ||
htmlContent: ` | ||
<h1>Réponse à votre contribution</h1> | ||
<p>Bonjour,</p> | ||
<p>En réponse à votre contribution :</p> | ||
<blockquote>${contribution.message}</blockquote> | ||
<p>Voici notre réponse :</p> | ||
<p>${userResponse}</p> | ||
`, | ||
}; | ||
|
||
const responseBrevo = await fetch("/email/", { | ||
// const responseBrevo = await fetch("https://api.brevo.com/v3/smtp/email", { | ||
console.log(contribution); | ||
// const responseBrevo = await fetch("/email/", { | ||
const responseBrevo = await fetch("https://api.brevo.com/v3/smtp/email", { | ||
method: "POST", | ||
headers: { | ||
"api-key": import.meta.env.VITE_BREVO_API_AUTHORIZATION, | ||
|
@@ -64,22 +71,23 @@ function EmailSender({ | |
responseFrom: selectedProfile, | ||
}; | ||
|
||
const responseScanR = await fetch(`/api/${basePath}/${contribution._id}`, { | ||
// const responseScanR = await fetch( | ||
// `https://scanr-api.dataesr.ovh/${basePath}/${contribution._id}`, | ||
// { | ||
method: "PATCH", | ||
headers: postHeaders, | ||
body: JSON.stringify(dataForScanR), | ||
}); | ||
// const responseScanR = await fetch(`/api/${basePath}/${contribution._id}`, { | ||
const responseScanR = await fetch( | ||
`https://scanr-api.dataesr.ovh/${basePath}/${contribution._id}`, | ||
{ | ||
method: "PATCH", | ||
headers: postHeaders, | ||
body: JSON.stringify(dataForScanR), | ||
} | ||
); | ||
|
||
if (!responseScanR.ok) { | ||
throw new Error(`HTTP error! status: ${responseScanR.status}`); | ||
} | ||
setResponseScanR(dataForScanR); | ||
setEmailSent(true); | ||
toast.success("Mail envoyé!"); | ||
refetch(); | ||
setUserResponse(""); | ||
toast.success("Mail envoyé!"); | ||
}; | ||
|
||
return ( | ||
|
Oops, something went wrong.