import * as React from "react" import { Button, buttonVariants } from "@/components/ui/button" import { Dialog, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DialogPortal, DialogOverlay, DialogPrimitive, } from "@/components/ui/dialog" import { LaIcon } from "@/components/custom/la-icon" import { MinimalTiptapEditor } from "@shared/minimal-tiptap" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { useRef, useState } from "react" import { cn } from "@/lib/utils" import { z } from "zod" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import { toast } from "sonner" import { Spinner } from "@/components/custom/spinner" import { Editor } from "@tiptap/react" import { sendFeedbackFn } from "~/actions" const formSchema = z.object({ content: z.string().min(1, { message: "Feedback cannot be empty", }), }) export function Feedback() { const [open, setOpen] = useState(false) const editorRef = useRef(null) const [isPending, setIsPending] = useState(false) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { content: "", }, }) const handleCreate = React.useCallback( ({ editor }: { editor: Editor }) => { if (form.getValues("content") && editor.isEmpty) { editor.commands.setContent(form.getValues("content")) } editorRef.current = editor }, [form], ) async function onSubmit(values: z.infer) { try { setIsPending(true) await sendFeedbackFn(values) form.reset({ content: "" }) editorRef.current?.commands.clearContent() setOpen(false) toast.success("Feedback sent") } catch (error) { toast.error("Failed to send feedback") } finally { setIsPending(false) } } return (
Share feedback Your feedback helps us improve. Please share your thoughts, ideas, and suggestions ( Content )} /> Cancel
) }