diff --git a/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx b/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx index 476065957..2a3f2f43a 100644 --- a/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx +++ b/apps/dokploy/components/dashboard/application/advanced/import/show-import.tsx @@ -28,10 +28,11 @@ 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 { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; +import { AlertBlock } from "@/components/shared/alert-block"; const ImportSchema = z.object({ base64: z.string(), @@ -68,10 +69,13 @@ export const ShowImport = ({ composeId }: Props) => { } | null>(null); const utils = api.useUtils(); - const { mutateAsync: processTemplate } = + const { mutateAsync: processTemplate, isLoading: isLoadingTemplate } = api.compose.processTemplate.useMutation(); - const { mutateAsync: updateCompose, isLoading } = - api.compose.update.useMutation(); + const { + mutateAsync: importTemplate, + isLoading: isImporting, + isSuccess: isImportSuccess, + } = api.compose.import.useMutation(); const form = useForm({ defaultValues: { @@ -80,21 +84,32 @@ export const ShowImport = ({ composeId }: Props) => { resolver: zodResolver(ImportSchema), }); + useEffect(() => { + form.reset({ + base64: "", + }); + }, [isImportSuccess]); + 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 base64 = form.getValues("base64"); + if (!base64) { + toast.error("Please enter a base64 template"); + return; + } + + try { + await importTemplate({ + composeId, + base64, }); + toast.success("Template imported successfully"); + await utils.compose.one.invalidate({ + composeId, + }); + setShowModal(false); + } catch (_error) { + toast.error("Error importing template"); + } }; const handleLoadTemplate = async () => { @@ -129,11 +144,13 @@ export const ShowImport = ({ composeId }: Props) => { Import - - Import your Docker Compose configuration - + Import your Template configuration + + Warning: Importing a template will remove all existing environment + variables, mounts, and domains from this service. +
{ name="base64" render={({ field }) => ( - Docker Compose (Base64) + Configuration (Base64)