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 { createServerFn } from "@tanstack/start" import { clerkClient, getAuth } from "@clerk/tanstack-start/server" import { create } from "ronin" export const sendFeedbackFn = createServerFn( "POST", async (data: { content: string }, { request }) => { const auth = await getAuth(request) if (!auth.userId) { throw new Error("User not authenticated") } const user = await clerkClient({ telemetry: { disabled: true }, }).users.getUser(auth.userId) await create.feedback.with({ message: data.content, emailFrom: user.emailAddresses[0].emailAddress, }) }, ) 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
) }