| "use client"; |
|
|
| import { useState } from "react"; |
| import { Button } from "@/components/ui/button"; |
| import { |
| Dialog, |
| DialogContent, |
| DialogDescription, |
| DialogFooter, |
| DialogHeader, |
| DialogTitle, |
| DialogTrigger, |
| } from "@/components/ui/dialog"; |
| import { Textarea } from "@/components/ui/textarea"; |
| import { Label } from "@/components/ui/label"; |
| import { |
| Select, |
| SelectContent, |
| SelectItem, |
| SelectTrigger, |
| SelectValue, |
| } from "@/components/ui/select"; |
| import { MessageSquarePlus } from "lucide-react"; |
| import { toast } from "sonner"; |
|
|
| export function FeedbackButton() { |
| const [open, setOpen] = useState(false); |
| const [message, setMessage] = useState(""); |
| const [type, setType] = useState("general"); |
| const [isSubmitting, setIsSubmitting] = useState(false); |
|
|
| async function handleSubmit(e: React.FormEvent) { |
| e.preventDefault(); |
| if (!message.trim()) return; |
|
|
| setIsSubmitting(true); |
| try { |
| const res = await fetch("/api/feedback", { |
| method: "POST", |
| headers: { "Content-Type": "application/json" }, |
| body: JSON.stringify({ message, type }), |
| }); |
|
|
| if (!res.ok) throw new Error("Failed to submit"); |
|
|
| toast.success("Feedback submitted successfully!"); |
| setOpen(false); |
| setMessage(""); |
| setType("general"); |
| } catch { |
| toast.error("Failed to submit feedback"); |
| } finally { |
| setIsSubmitting(false); |
| } |
| } |
|
|
| return ( |
| <Dialog open={open} onOpenChange={setOpen}> |
| <DialogTrigger asChild> |
| <Button |
| variant="outline" |
| size="icon" |
| className="fixed bottom-4 right-4 h-12 w-12 rounded-full shadow-lg z-50 bg-background border-primary/20 hover:border-primary" |
| > |
| <MessageSquarePlus className="h-6 w-6 text-primary" /> |
| <span className="sr-only">Send Feedback</span> |
| </Button> |
| </DialogTrigger> |
| <DialogContent className="sm:max-w-[425px]"> |
| <DialogHeader> |
| <DialogTitle>Send Feedback</DialogTitle> |
| <DialogDescription> |
| Help us improve AutoLoop. Report a bug or request a feature. |
| </DialogDescription> |
| </DialogHeader> |
| <form onSubmit={handleSubmit} className="grid gap-4 py-4"> |
| <div className="grid gap-2"> |
| <Label htmlFor="type">Type</Label> |
| <Select value={type} onValueChange={setType}> |
| <SelectTrigger> |
| <SelectValue placeholder="Select type" /> |
| </SelectTrigger> |
| <SelectContent> |
| <SelectItem value="general">General</SelectItem> |
| <SelectItem value="bug">Bug Report</SelectItem> |
| <SelectItem value="feature">Feature Request</SelectItem> |
| </SelectContent> |
| </Select> |
| </div> |
| <div className="grid gap-2"> |
| <Label htmlFor="message">Message</Label> |
| <Textarea |
| id="message" |
| value={message} |
| onChange={(e) => setMessage(e.target.value)} |
| placeholder="Tell us what's on your mind..." |
| className="min-h-[100px]" |
| required |
| /> |
| </div> |
| <DialogFooter> |
| <Button type="submit" disabled={isSubmitting}> |
| {isSubmitting ? "Sending..." : "Send Feedback"} |
| </Button> |
| </DialogFooter> |
| </form> |
| </DialogContent> |
| </Dialog> |
| ); |
| } |
|
|