-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |