Skip to content

Commit

Permalink
Add feedback form
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jul 1, 2024
1 parent cc2c47e commit 97831ec
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions apps/dashboard/src/components/feedback-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";

import { sendFeebackAction } from "@/actions/send-feedback-action";
import { Button } from "@midday/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@midday/ui/popover";
import { Textarea } from "@midday/ui/textarea";
import { Loader2 } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import { useState } from "react";

export function FeedbackForm() {
const [value, setValue] = useState("");

const action = useAction(sendFeebackAction, {
onSuccess: () => {
setValue("");
},
});

return (
<Popover>
<PopoverTrigger asChild className="hidden md:block">
<Button variant="outline">Feedback</Button>
</PopoverTrigger>
<PopoverContent className="w-[320px]" sideOffset={10}>
<form className="space-y-4">
<Textarea
name="feedback"
value={value}
required
autoFocus
placeholder="Ideas to improve this page or issues you are experiencing."
className="resize-none h-[120px]"
onChange={(evt) => setValue(evt.target.value)}
/>

<div className="mt-1 flex items-center justify-end">
<Button
type="button"
onClick={() => action.execute({ feedback: value })}
disabled={value.length === 0 || action.status === "executing"}
>
{action.status === "executing" ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
"Send"
)}
</Button>
</div>
</form>
</PopoverContent>
</Popover>
);
}

0 comments on commit 97831ec

Please sign in to comment.