"use client"; import { useRef, ElementRef, useState } from "react"; import { useQueryClient } from "@tanstack/react-query"; import { useParams } from "next/navigation"; import { Layout } from "lucide-react"; import { toast } from "sonner"; import { CardWithList } from "@/types"; import { useAction } from "@/hooks/use-action"; import { updateCard } from "@/actions/update-card"; import { FormInput } from "@/components/form/form-input"; import { Skeleton } from "@/components/ui/skeleton"; interface HeaderProps { data: CardWithList; } export const Header = ({ data }: HeaderProps) => { const queryClient = useQueryClient(); const params = useParams(); const { execute } = useAction(updateCard, { onSuccess: (data) => { queryClient.invalidateQueries({ queryKey: ["card", data.id], }); queryClient.invalidateQueries({ queryKey: ["card-logs", data.id], }); toast.success(`Card renamed to "${data.title}"`); setTitle(data.title); }, onError: (error) => { toast.error(error); }, }); const inputRef = useRef>(null); const [title, setTitle] = useState(data.title); const onBlur = () => { inputRef.current?.form?.requestSubmit(); }; const onSubmit = (formData: FormData) => { const title = formData.get("title") as string; const boardId = params.boardId as string; if (title === data.title) return; execute({ id: data.id, title, boardId, }); }; return (

in list {data.list.title}

); }; Header.Skeleton = function HeaderSkelton() { return (
); };