Repository navigation
Expand file tree
/
Copy pathFeedback.tsx
More file actions
80 lines (72 loc) · 2.38 KB
/
Copy pathFeedback.tsx
File metadata and controls
80 lines (72 loc) · 2.38 KB
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
import React, { useState } from "react";
import { ThumbsUp, ThumbsDown } from "react-feather";
import { Banner } from "./Banner";
import "twin.macro";
export const Feedback: React.FC<{ topic: string }> = ({ topic }) => {
const [helpful, setHelpful] = useState(true);
const [success, setSuccess] = useState(false);
const sendFeedback = async event => {
event.preventDefault();
const feedback = event.target.feedback?.value ?? "";
await fetch("/api/feedback", {
body: JSON.stringify({
topic,
feedback,
helpful,
}),
method: "POST",
});
setSuccess(true);
};
return (
<>
{success && (
<Banner tw="mt-32" variant="info">
Thank you for your feedback!
</Banner>
)}
{!success && (
<>
{helpful && (
<div tw="flex flex-row align-items[center] mt-32">
<div tw="font-semibold text-lg mr-4">Was this page helpful?</div>
<button
=> sendFeedback(e)}
tw="mr-2 flex align-items[center] border border-blue-200 rounded-md px-4 py-2 hover:bg-blue-100"
>
<ThumbsUp tw="mr-2 text-blue-700" />
<div tw="font-semibold text-blue-900">Yes</div>
</button>
<button
=> setHelpful(false)}
tw="flex align-items[center] border border-red-200 rounded-md px-4 py-2 hover:background-color[#FBEAEA]"
>
<ThumbsDown tw="mr-2 text-red-500" />
<div tw="font-semibold text-red-700">No</div>
</button>
</div>
)}
{!helpful && (
<form tw="mt-16" >
<textarea
tw="border rounded-md w-full p-2 my-6"
id="feedback"
name="feedback"
rows={3}
required
placeholder="What was missing or inaccurate?"
/>
<button
type="submit"
tw="border border-gray-200 p-2 rounded-md font-semibold text-gray-400 bg-gray-100 mr-8 hover:text-gray-700"
>
Submit Feedback
</button>
<button => setHelpful(true)}>Cancel</button>
</form>
)}
</>
)}
</>
);
};