import { Button } from "@minmon/ui/components/button"; import { useMutation, useQuery } from "@tanstack/react-query"; import { createFileRoute, Link } from "@tanstack/react-router"; import { toast } from "sonner"; import { ConfirmDeleteIconButton, PageSection, QueryStateCard, ResourceListCard } from "@/components/dashboard-ui"; import { queryClient, trpc, trpcClient } from "@/utils/trpc"; export const Route = createFileRoute("/dashboard/notes")({ component: RouteComponent, }); function RouteComponent() { const notes = useQuery(trpc.notes.list.queryOptions()); const servers = useQuery(trpc.servers.list.queryOptions()); const removeNote = useMutation({ mutationFn: async (id: string) => trpcClient.notes.delete.mutate({ id }), onSuccess: async () => { toast.success("Note deleted"); await queryClient.invalidateQueries(); }, onError: (error) => toast.error(error.message), }); if (notes.isLoading || servers.isLoading) { return ; } if (notes.isError || servers.isError || !notes.data || !servers.data) { return ; } const serverMap = new Map(servers.data.map((item) => [item.id, item.name])); return ( } > (
{item.title} {item.content}
), }, { key: "server", header: "Server", render: (item: (typeof notes.data)[number]) => serverMap.get(item.serverId) || item.serverId, }, { key: "category", header: "Category", render: (item: (typeof notes.data)[number]) => item.category || "-", }, { key: "updatedAt", header: "Updated", render: (item: (typeof notes.data)[number]) => new Date(item.updatedAt).toLocaleString(), }, { key: "actions", header: "Actions", className: "w-16", render: (item: (typeof notes.data)[number]) => ( removeNote.mutate(item.id)} /> ), }, ]} items={notes.data} emptyTitle="No notes yet" emptyDescription="Add a note to document maintenance, incidents, or general server information." />
); }