"use client"; import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { LayoutTemplate } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/primitives"; import { toast } from "@/components/ui/toast"; import { api } from "@/lib/client/api"; import { cn } from "@/lib/utils"; export function TemplateChooser({ dbId, onDone, onSkip, embedded }: { dbId: string; onDone: () => void; onSkip?: () => void; embedded?: boolean }) { const { data } = useQuery<{ id: string; name: string; icon: string; description: string; properties: string[] }[]>({ queryKey: ["db-templates"], queryFn: () => api("/api/databases/templates") }); const [busy, setBusy] = useState(null); const apply = async (t: string) => { setBusy(t); try { await api(`/api/databases/${dbId}/apply-template`, { method: "POST", json: { template: t } }); toast("Template applied", { tone: "success" }); onDone(); } catch (e: any) { toast("Could not apply template", { description: e?.message, tone: "danger" }); } finally { setBusy(null); } }; return (
Start from a template
{!data ? :
{data.map((t) => ( ))}
} {onSkip &&
or
}
); }