import { listsControllerCreateListMutation, listsControllerGetUserListsQueryKey, } from "@opnshelf/api"; import { usePostHog } from "@posthog/react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { ListPlus } from "lucide-react"; import { useId, useState } from "react"; import { useTheme } from "@/components/theme-provider"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { M3Button } from "@/components/ui/m3-button"; import { M3TextField } from "@/components/ui/m3-text-field"; import { cn } from "@/lib/utils"; type CreateListDialogProps = { triggerClassName?: string; }; export function CreateListDialog({ triggerClassName }: CreateListDialogProps) { const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [isDescriptionFocused, setIsDescriptionFocused] = useState(false); const queryClient = useQueryClient(); const id = useId(); const { seedColor } = useTheme(); const posthog = usePostHog(); const createListMutation = useMutation({ mutationKey: ["lists", "create"], ...listsControllerCreateListMutation(), onSuccess: (data) => { queryClient.invalidateQueries({ queryKey: listsControllerGetUserListsQueryKey(), }); posthog.capture("list_created", { list_name: name.trim(), has_description: !!description.trim(), list_id: (data as { id?: string })?.id, }); setOpen(false); setName(""); setDescription(""); }, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) return; createListMutation.mutate({ body: { name: name.trim(), description: description.trim() || undefined, }, }); }; return ( Create List Create New List Create a custom list to organize your movies.
setName(e.target.value)} required maxLength={100} variant="outlined" />