-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreviews.js
44 lines (39 loc) · 1.2 KB
/
reviews.js
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
import { useState } from 'react';
export default function ReviewPage() {
const [reviewText, setReviewText] = useState('');
const [productId, setProductId] = useState('1'); // Default product ID is set to '1'
const handleSubmit = async (event) => {
event.preventDefault();
const response = await fetch('/api/reviews', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reviewText, productId }), // Send the selected product ID
});
if (response.ok) {
window.location.href = '/thank-you';
}
};
return (
<form onSubmit={handleSubmit}>
<textarea
value={reviewText}
onChange={(e) => setReviewText(e.target.value)}
placeholder="Enter your review"
required
/>
<br />
<label>
Product ID:
<select value={productId} onChange={(e) => setProductId(e.target.value)} style={{ marginLeft: '10px' }}>
{Array.from({ length: 10 }, (_, i) => (
<option key={i + 1} value={i + 1}>
{i + 1}
</option>
))}
</select>
</label>
<br />
<button type="submit">Submit Review</button>
</form>
);
}