diff --git a/apps/dokploy/components/dashboard/settings/servers/setup-server.tsx b/apps/dokploy/components/dashboard/settings/servers/setup-server.tsx index 13326b64..33d9bb6c 100644 --- a/apps/dokploy/components/dashboard/settings/servers/setup-server.tsx +++ b/apps/dokploy/components/dashboard/settings/servers/setup-server.tsx @@ -145,7 +145,7 @@ export const SetupServer = ({ serverId }: Props) => { Automatic process diff --git a/apps/dokploy/components/dashboard/settings/servers/show-servers.tsx b/apps/dokploy/components/dashboard/settings/servers/show-servers.tsx index 42c042f3..30d52ea2 100644 --- a/apps/dokploy/components/dashboard/settings/servers/show-servers.tsx +++ b/apps/dokploy/components/dashboard/settings/servers/show-servers.tsx @@ -31,8 +31,12 @@ import { SetupServer } from "./setup-server"; import { ShowDockerContainersModal } from "./show-docker-containers-modal"; import { ShowTraefikFileSystemModal } from "./show-traefik-file-system-modal"; import { UpdateServer } from "./update-server"; +import { useRouter } from "next/router"; +import { WelcomeSuscription } from "./welcome-stripe/welcome-suscription"; export const ShowServers = () => { + const router = useRouter(); + const query = router.query; const { data, refetch } = api.server.all.useQuery(); const { mutateAsync } = api.server.remove.useMutation(); const { data: sshKeys } = api.sshKey.all.useQuery(); @@ -42,6 +46,7 @@ export const ShowServers = () => { return (
+ {query?.success && }

Servers

diff --git a/apps/dokploy/components/dashboard/settings/servers/welcome-stripe/create-server.tsx b/apps/dokploy/components/dashboard/settings/servers/welcome-stripe/create-server.tsx new file mode 100644 index 00000000..a44876f8 --- /dev/null +++ b/apps/dokploy/components/dashboard/settings/servers/welcome-stripe/create-server.tsx @@ -0,0 +1,284 @@ +import { AlertBlock } from "@/components/shared/alert-block"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +import { DialogFooter } from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; +import { api } from "@/utils/api"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { PlusIcon } from "lucide-react"; +import Link from "next/link"; +import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; +import { useForm } from "react-hook-form"; +import { toast } from "sonner"; +import { z } from "zod"; + +const Schema = z.object({ + name: z.string().min(1, { + message: "Name is required", + }), + description: z.string().optional(), + ipAddress: z.string().min(1, { + message: "IP Address is required", + }), + port: z.number().optional(), + username: z.string().optional(), + sshKeyId: z.string().min(1, { + message: "SSH Key is required", + }), +}); + +type Schema = z.infer; + +interface Props { + stepper: any; +} + +export const CreateServer = ({ stepper }: Props) => { + const { data: sshKeys } = api.sshKey.all.useQuery(); + const [isOpen, setIsOpen] = useState(false); + const { data: canCreateMoreServers, refetch } = + api.stripe.canCreateMoreServers.useQuery(); + const { mutateAsync, error, isError } = api.server.create.useMutation(); + const cloudSSHKey = sshKeys?.find( + (sshKey) => sshKey.name === "dokploy-cloud-ssh-key", + ); + + const form = useForm({ + defaultValues: { + description: "Dokploy Cloud Server", + name: "My First Server", + ipAddress: "", + port: 22, + username: "root", + sshKeyId: cloudSSHKey?.sshKeyId || "", + }, + resolver: zodResolver(Schema), + }); + + useEffect(() => { + form.reset({ + description: "Dokploy Cloud Server", + name: "My First Server", + ipAddress: "", + port: 22, + username: "root", + sshKeyId: cloudSSHKey?.sshKeyId || "", + }); + }, [form, form.reset, form.formState.isSubmitSuccessful, sshKeys]); + + useEffect(() => { + refetch(); + }, [isOpen]); + + const onSubmit = async (data: Schema) => { + await mutateAsync({ + name: data.name, + description: data.description || "", + ipAddress: data.ipAddress || "", + port: data.port || 22, + username: data.username || "root", + sshKeyId: data.sshKeyId || "", + }) + .then(async (data) => { + toast.success("Server Created"); + stepper.next(); + }) + .catch(() => { + toast.error("Error to create a server"); + }); + }; + return ( + +
+ {!canCreateMoreServers && ( + + You cannot create more servers,{" "} + + Please upgrade your plan + + + )} +
+ + +
+ +
+ ( + + Name + + + + + + + )} + /> +
+ ( + + Description + +