Skip to content

Commit

Permalink
Report page connect with backend post route
Browse files Browse the repository at this point in the history
  • Loading branch information
KovacevicAleksa committed Feb 21, 2025
1 parent 53fe2fd commit e0f7f17
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions frontend/src/routes/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ function Report() {
e.preventDefault();
setError("");
setSuccess("");

try {
const response = await fetch(`${config.api.baseURL}/reports`, {
const response = await fetch("http://localhost:8081/report", {
method: "POST",
headers: {
'Authorization': `Bearer ${localStorage.getItem("token")}`,
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
body: JSON.stringify({
email: formData.email,
reportText: formData.reportText,
category: formData.category,
reportBy: localStorage.getItem("userEmail"),
}),
});

if (!response.ok) {
throw new Error("Failed to submit report");
const errorData = await response.json();
throw new Error(errorData.error || "Failed to submit report");
}

setSuccess("Report submitted successfully");
setFormData(prev => ({ ...prev, reportText: "", category: "Other" }));
} catch (err) {
Expand Down Expand Up @@ -116,7 +122,7 @@ function Report() {
type="email"
id="email"
name="email"
value={formData.email}
// value={}
onChange={handleChange}
required
style={{
Expand Down

0 comments on commit e0f7f17

Please # to comment.