Spaces:
Running
Running
File size: 3,781 Bytes
803d869 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | import React, { useState } from "react";
import api from "../../api";
const ReviewSection = () => {
const [formData, setFormData] = useState({
name: "",
email: "",
subject: "",
message: "",
});
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
setError("");
try {
await api.submitReview(formData);
alert("Review submitted successfully!");
setFormData({ name: "", email: "", subject: "", message: "" }); // Reset form
} catch (err) {
setError(err.message || "Failed to submit review.");
} finally {
setLoading(false);
}
};
return (
<section id="contact1">
<div className="container11">
<div className="section-header">
<h2>Review</h2>
</div>
<div className="form">
{error && <div className="alert alert-danger">{error}</div>}
<form
onSubmit={handleSubmit}
className="contactForm"
method="post"
role="form"
>
<div className="form-row">
<div className="form-group col-md-6">
<input
className="form-control"
id="name"
name="name"
placeholder="Your Name"
type="text"
value={formData.name}
onChange={(e) =>
setFormData({ ...formData, name: e.target.value })
}
disabled={loading}
/>
<div className="validation"></div>
</div>
<div className="form-group col-md-6">
<input
className="form-control"
id="email"
name="email"
placeholder="Your Email"
type="email"
value={formData.email}
onChange={(e) =>
setFormData({ ...formData, email: e.target.value })
}
disabled={loading}
/>
<div className="validation"></div>
</div>
</div>
<div className="form-group">
<input
className="form-control"
id="subject"
name="subject"
placeholder="Subject"
type="text"
value={formData.subject}
onChange={(e) =>
setFormData({ ...formData, subject: e.target.value })
}
disabled={loading}
/>
<div className="validation"></div>
</div>
<div className="form-group">
<textarea
className="form-control"
name="message"
placeholder="Message"
rows="5"
value={formData.message}
onChange={(e) =>
setFormData({ ...formData, message: e.target.value })
}
disabled={loading}
/>
<div className="validation"></div>
</div>
<div className="text-center">
<button
type="submit"
disabled={loading}
className="submit-button"
>
{loading ? "Submitting..." : "Submit"}
</button>
</div>
</form>
</div>
</div>
</section>
);
};
export default ReviewSection;
|