diff --git a/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx b/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx new file mode 100644 index 00000000..47606595 --- /dev/null +++ b/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx @@ -0,0 +1,311 @@ +import { CodeEditor } from "@/components/shared/code-editor"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import { Textarea } from "@/components/ui/textarea"; +import { api } from "@/utils/api"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { Code2, Globe2, HardDrive } from "lucide-react"; +import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { toast } from "sonner"; +import { z } from "zod"; + +const ImportSchema = z.object({ + base64: z.string(), +}); + +type ImportType = z.infer; + +interface Props { + composeId: string; +} + +export const ShowImport = ({ composeId }: Props) => { + const [showModal, setShowModal] = useState(false); + const [showMountContent, setShowMountContent] = useState(false); + const [selectedMount, setSelectedMount] = useState<{ + filePath: string; + content: string; + } | null>(null); + const [templateInfo, setTemplateInfo] = useState<{ + compose: string; + template: { + domains: Array<{ + serviceName: string; + port: number; + path?: string; + host?: string; + }>; + envs: string[]; + mounts: Array<{ + filePath: string; + content: string; + }>; + }; + } | null>(null); + + const utils = api.useUtils(); + const { mutateAsync: processTemplate } = + api.compose.processTemplate.useMutation(); + const { mutateAsync: updateCompose, isLoading } = + api.compose.update.useMutation(); + + const form = useForm({ + defaultValues: { + base64: "", + }, + resolver: zodResolver(ImportSchema), + }); + + const onSubmit = async () => { + await updateCompose({ + composeId, + composeFile: templateInfo?.compose || "", + }) + .then(async () => { + toast.success("Import configuration updated"); + await utils.compose.one.invalidate({ + composeId, + }); + setShowModal(false); + }) + .catch(() => { + toast.error("Error updating the import configuration"); + }); + }; + + const handleLoadTemplate = async () => { + const base64 = form.getValues("base64"); + if (!base64) { + toast.error("Please enter a base64 template"); + return; + } + + try { + const result = await processTemplate({ + composeId, + base64, + }); + setTemplateInfo(result); + setShowModal(true); + } catch (_error) { + toast.error("Error processing template"); + } + }; + + const handleShowMountContent = (mount: { + filePath: string; + content: string; + }) => { + setSelectedMount(mount); + setShowMountContent(true); + }; + + return ( + <> + + + Import + + Import your Docker Compose configuration + + + +
+ + ( + + Docker Compose (Base64) + +