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 { Label } from "@/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import { api } from "@/utils/api"; import { BookText, CheckIcon, ChevronsUpDown, Github, Globe, HelpCircle, LayoutGrid, List, 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 [open, setOpen] = useState(false); const [viewMode, setViewMode] = useState<"detailed" | "icon">("detailed"); const [selectedTags, setSelectedTags] = useState([]); const { data } = api.compose.templates.useQuery(); const { data: isCloud } = api.settings.isCloud.useQuery(); const { data: servers } = api.server.withSSHKey.useQuery(); const { data: tags, isLoading: isLoadingTags } = api.compose.getTags.useQuery(); const utils = api.useUtils(); const [serverId, setServerId] = useState(undefined); 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()) || template.description.toLowerCase().includes(query.toLowerCase()); return matchesTags && matchesQuery; }) || []; return ( e.preventDefault()} > Template
Create from Template Create an open source application from a template
setQuery(e.target.value)} className="w-full sm:w-[200px]" value={query} /> {isLoadingTags && ( Loading Tags.... )} No tags found. {tags?.map((tag) => ( { if (selectedTags.includes(tag)) { setSelectedTags( selectedTags.filter((t) => t !== tag), ); return; } setSelectedTags([...selectedTags, tag]); }} > {tag} ))}
{selectedTags.length > 0 && (
{selectedTags.map((tag) => ( setSelectedTags(selectedTags.filter((t) => t !== tag)) } > {tag} × ))}
)}
{isError && ( {error?.message} )} {templates.length === 0 ? (
No templates found
) : (
{templates?.map((template, index) => (
{template.version} {/* Template Header */}
{template.name}
{template.name} {viewMode === "detailed" && template.tags.length > 0 && (
{template.tags.map((tag) => ( {tag} ))}
)}
{/* Template Content */} {viewMode === "detailed" && (
{template.description}
)} {/* Create Button */}
{viewMode === "detailed" && (
{template.links.website && ( )} {template.links.docs && ( )}
)} Are you absolutely sure? This will create an application from the{" "} {template.name} template and add it to your project.
If ot server is selected, the application will be deployed on the server where the user is logged in.
Cancel { const promise = mutateAsync({ projectId, serverId: serverId || undefined, id: template.id, }); toast.promise(promise, { loading: "Setting up...", success: (_data) => { utils.project.one.invalidate({ projectId, }); setOpen(false); return `${template.name} template created successfully`; }, error: (_err) => { return `An error ocurred deploying ${template.name} template`; }, }); }} > Confirm
))}
)}
); };