import { AlertBlock } from "@/components/shared/alert-block"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, } from "@/components/ui/command"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; import { Input } from "@/components/ui/input"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { api } from "@/utils/api"; import { ScrollArea } from "@radix-ui/react-scroll-area"; import { CheckIcon, ChevronsUpDown, Code, Github, Globe, PuzzleIcon, SearchIcon, } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; import { toast } from "sonner"; interface Props { projectId: string; } export const AddTemplate = ({ projectId }: Props) => { const [query, setQuery] = useState(""); const { data } = api.compose.templates.useQuery(); const [selectedTags, setSelectedTags] = useState([]); const { data: tags, isLoading: isLoadingTags } = api.compose.getTags.useQuery(); const utils = api.useUtils(); const { mutateAsync, isLoading, error, isError } = api.compose.deployTemplate.useMutation(); const templates = data?.filter((template) => { const matchesTags = selectedTags.length === 0 || template.tags.some((tag) => selectedTags.includes(tag)); const matchesQuery = query === "" || template.name.toLowerCase().includes(query.toLowerCase()); return matchesTags && matchesQuery; }) || []; return ( e.preventDefault()} > Templates
Create Template Deploy a open source template to your project {isError && {error?.message}}
setQuery(e.target.value)} className="w-full" value={query} /> {isLoadingTags && ( Loading Tags.... )} No tags found. {tags?.map((tag) => { return ( { if (selectedTags.includes(tag)) { setSelectedTags( selectedTags.filter((t) => t !== tag), ); return; } setSelectedTags([...selectedTags, tag]); }} > {tag} ); })}
{templates.length === 0 ? (
No templates found
) : (
{templates?.map((template, index) => (
{template.name} {template.version}
{template.links.website && ( )} {template.links.docs && ( )}
{template.tags.map((tag) => ( {tag} ))}
Are you absolutely sure? This will deploy {template.name} template to your project. Cancel { await mutateAsync({ projectId, id: template.id, }) .then(async () => { toast.success( `${template.name} template created succesfully`, ); utils.project.one.invalidate({ projectId, }); }) .catch(() => { toast.error( `Error to delete ${template.name} template`, ); }); }} > Confirm

{template.description}

))}
)}
); };