mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-29 06:48:45 +00:00
feat(ux): add conditional server selection functionality to application forms
This commit is contained in:
@@ -1,256 +1,260 @@
|
|||||||
import { AlertBlock } from "@/components/shared/alert-block";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
||||||
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 {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipProvider,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip";
|
|
||||||
import { slugify } from "@/lib/slug";
|
|
||||||
import { api } from "@/utils/api";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Folder, HelpCircle } from "lucide-react";
|
import { Folder, HelpCircle } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||||
|
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 {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
import { slugify } from "@/lib/slug";
|
||||||
|
import { api } from "@/utils/api";
|
||||||
|
|
||||||
const AddTemplateSchema = z.object({
|
const AddTemplateSchema = z.object({
|
||||||
name: z.string().min(1, {
|
name: z.string().min(1, {
|
||||||
message: "Name is required",
|
message: "Name is required",
|
||||||
}),
|
}),
|
||||||
appName: z
|
appName: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, {
|
.min(1, {
|
||||||
message: "App name is required",
|
message: "App name is required",
|
||||||
})
|
})
|
||||||
.regex(/^[a-z](?!.*--)([a-z0-9-]*[a-z])?$/, {
|
.regex(/^[a-z](?!.*--)([a-z0-9-]*[a-z])?$/, {
|
||||||
message:
|
message:
|
||||||
"App name supports lowercase letters, numbers, '-' and can only start and end letters, and does not support continuous '-'",
|
"App name supports lowercase letters, numbers, '-' and can only start and end letters, and does not support continuous '-'",
|
||||||
}),
|
}),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AddTemplate = z.infer<typeof AddTemplateSchema>;
|
type AddTemplate = z.infer<typeof AddTemplateSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
projectName?: string;
|
projectName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddApplication = ({ projectId, projectName }: Props) => {
|
export const AddApplication = ({ projectId, projectName }: Props) => {
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const { data: isCloud } = api.settings.isCloud.useQuery();
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const slug = slugify(projectName);
|
const slug = slugify(projectName);
|
||||||
const { data: servers } = api.server.withSSHKey.useQuery();
|
const { data: servers } = api.server.withSSHKey.useQuery();
|
||||||
|
|
||||||
const { mutateAsync, isLoading, error, isError } =
|
const hasServers = servers && servers.length > 0;
|
||||||
api.application.create.useMutation();
|
|
||||||
|
|
||||||
const form = useForm<AddTemplate>({
|
const { mutateAsync, isLoading, error, isError } =
|
||||||
defaultValues: {
|
api.application.create.useMutation();
|
||||||
name: "",
|
|
||||||
appName: `${slug}-`,
|
|
||||||
description: "",
|
|
||||||
},
|
|
||||||
resolver: zodResolver(AddTemplateSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = async (data: AddTemplate) => {
|
const form = useForm<AddTemplate>({
|
||||||
await mutateAsync({
|
defaultValues: {
|
||||||
name: data.name,
|
name: "",
|
||||||
appName: data.appName,
|
appName: `${slug}-`,
|
||||||
description: data.description,
|
description: "",
|
||||||
projectId,
|
},
|
||||||
serverId: data.serverId,
|
resolver: zodResolver(AddTemplateSchema),
|
||||||
})
|
});
|
||||||
.then(async () => {
|
|
||||||
toast.success("Service Created");
|
|
||||||
form.reset();
|
|
||||||
setVisible(false);
|
|
||||||
await utils.project.one.invalidate({
|
|
||||||
projectId,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
toast.error("Error creating the service");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
const onSubmit = async (data: AddTemplate) => {
|
||||||
<Dialog open={visible} onOpenChange={setVisible}>
|
await mutateAsync({
|
||||||
<DialogTrigger className="w-full">
|
name: data.name,
|
||||||
<DropdownMenuItem
|
appName: data.appName,
|
||||||
className="w-full cursor-pointer space-x-3"
|
description: data.description,
|
||||||
onSelect={(e) => e.preventDefault()}
|
projectId,
|
||||||
>
|
serverId: data.serverId,
|
||||||
<Folder className="size-4 text-muted-foreground" />
|
})
|
||||||
<span>Application</span>
|
.then(async () => {
|
||||||
</DropdownMenuItem>
|
toast.success("Service Created");
|
||||||
</DialogTrigger>
|
form.reset();
|
||||||
<DialogContent className="sm:max-w-lg">
|
setVisible(false);
|
||||||
<DialogHeader>
|
await utils.project.one.invalidate({
|
||||||
<DialogTitle>Create</DialogTitle>
|
projectId,
|
||||||
<DialogDescription>
|
});
|
||||||
Assign a name and description to your application
|
})
|
||||||
</DialogDescription>
|
.catch(() => {
|
||||||
</DialogHeader>
|
toast.error("Error creating the service");
|
||||||
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
});
|
||||||
<Form {...form}>
|
};
|
||||||
<form
|
|
||||||
id="hook-form"
|
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
|
||||||
className="grid w-full gap-4"
|
|
||||||
>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="name"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Name</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
placeholder="Frontend"
|
|
||||||
{...field}
|
|
||||||
onChange={(e) => {
|
|
||||||
const val = e.target.value?.trim() || "";
|
|
||||||
const serviceName = slugify(val);
|
|
||||||
form.setValue("appName", `${slug}-${serviceName}`);
|
|
||||||
field.onChange(val);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="serverId"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<TooltipProvider delayDuration={0}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
|
|
||||||
Select a Server {!isCloud ? "(Optional)" : ""}
|
|
||||||
<HelpCircle className="size-4 text-muted-foreground" />
|
|
||||||
</FormLabel>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent
|
|
||||||
className="z-[999] w-[300px]"
|
|
||||||
align="start"
|
|
||||||
side="top"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
If no server is selected, the application will be
|
|
||||||
deployed on the server where the user is logged in.
|
|
||||||
</span>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</TooltipProvider>
|
|
||||||
|
|
||||||
<Select
|
return (
|
||||||
onValueChange={field.onChange}
|
<Dialog open={visible} onOpenChange={setVisible}>
|
||||||
defaultValue={field.value}
|
<DialogTrigger className="w-full">
|
||||||
>
|
<DropdownMenuItem
|
||||||
<SelectTrigger>
|
className="w-full cursor-pointer space-x-3"
|
||||||
<SelectValue placeholder="Select a Server" />
|
onSelect={(e) => e.preventDefault()}
|
||||||
</SelectTrigger>
|
>
|
||||||
<SelectContent>
|
<Folder className="size-4 text-muted-foreground" />
|
||||||
<SelectGroup>
|
<span>Application</span>
|
||||||
{servers?.map((server) => (
|
</DropdownMenuItem>
|
||||||
<SelectItem
|
</DialogTrigger>
|
||||||
key={server.serverId}
|
<DialogContent className="sm:max-w-lg">
|
||||||
value={server.serverId}
|
<DialogHeader>
|
||||||
>
|
<DialogTitle>Create</DialogTitle>
|
||||||
<span className="flex items-center gap-2 justify-between w-full">
|
<DialogDescription>
|
||||||
<span>{server.name}</span>
|
Assign a name and description to your application
|
||||||
<span className="text-muted-foreground text-xs self-center">
|
</DialogDescription>
|
||||||
{server.ipAddress}
|
</DialogHeader>
|
||||||
</span>
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
||||||
</span>
|
<Form {...form}>
|
||||||
</SelectItem>
|
<form
|
||||||
))}
|
id="hook-form"
|
||||||
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
onSubmit={form.handleSubmit(onSubmit)}
|
||||||
</SelectGroup>
|
className="grid w-full gap-4"
|
||||||
</SelectContent>
|
>
|
||||||
</Select>
|
<FormField
|
||||||
<FormMessage />
|
control={form.control}
|
||||||
</FormItem>
|
name="name"
|
||||||
)}
|
render={({ field }) => (
|
||||||
/>
|
<FormItem>
|
||||||
<FormField
|
<FormLabel>Name</FormLabel>
|
||||||
control={form.control}
|
<FormControl>
|
||||||
name="appName"
|
<Input
|
||||||
render={({ field }) => (
|
placeholder="Frontend"
|
||||||
<FormItem>
|
{...field}
|
||||||
<FormLabel>App Name</FormLabel>
|
onChange={(e) => {
|
||||||
<FormControl>
|
const val = e.target.value?.trim() || "";
|
||||||
<Input placeholder="my-app" {...field} />
|
const serviceName = slugify(val);
|
||||||
</FormControl>
|
form.setValue("appName", `${slug}-${serviceName}`);
|
||||||
<FormMessage />
|
field.onChange(val);
|
||||||
</FormItem>
|
}}
|
||||||
)}
|
/>
|
||||||
/>
|
</FormControl>
|
||||||
<FormField
|
<FormMessage />
|
||||||
control={form.control}
|
</FormItem>
|
||||||
name="description"
|
)}
|
||||||
render={({ field }) => (
|
/>
|
||||||
<FormItem>
|
{hasServers && (
|
||||||
<FormLabel>Description</FormLabel>
|
<FormField
|
||||||
<FormControl>
|
control={form.control}
|
||||||
<Textarea
|
name="serverId"
|
||||||
placeholder="Description of your service..."
|
render={({ field }) => (
|
||||||
className="resize-none"
|
<FormItem>
|
||||||
{...field}
|
<TooltipProvider delayDuration={0}>
|
||||||
/>
|
<Tooltip>
|
||||||
</FormControl>
|
<TooltipTrigger asChild>
|
||||||
|
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
|
||||||
|
Select a Server {!isCloud ? "(Optional)" : ""}
|
||||||
|
<HelpCircle className="size-4 text-muted-foreground" />
|
||||||
|
</FormLabel>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
className="z-[999] w-[300px]"
|
||||||
|
align="start"
|
||||||
|
side="top"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
If no server is selected, the application will be
|
||||||
|
deployed on the server where the user is logged in.
|
||||||
|
</span>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
|
||||||
<FormMessage />
|
<Select
|
||||||
</FormItem>
|
onValueChange={field.onChange}
|
||||||
)}
|
defaultValue={field.value}
|
||||||
/>
|
>
|
||||||
</form>
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select a Server" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
{servers?.map((server) => (
|
||||||
|
<SelectItem
|
||||||
|
key={server.serverId}
|
||||||
|
value={server.serverId}
|
||||||
|
>
|
||||||
|
<span className="flex items-center gap-2 justify-between w-full">
|
||||||
|
<span>{server.name}</span>
|
||||||
|
<span className="text-muted-foreground text-xs self-center">
|
||||||
|
{server.ipAddress}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="appName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>App Name</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="my-app" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Description</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Description of your service..."
|
||||||
|
className="resize-none"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<DialogFooter>
|
<FormMessage />
|
||||||
<Button isLoading={isLoading} form="hook-form" type="submit">
|
</FormItem>
|
||||||
Create
|
)}
|
||||||
</Button>
|
/>
|
||||||
</DialogFooter>
|
</form>
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
<DialogFooter>
|
||||||
</Dialog>
|
<Button isLoading={isLoading} form="hook-form" type="submit">
|
||||||
);
|
Create
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,290 +1,294 @@
|
|||||||
import { AlertBlock } from "@/components/shared/alert-block";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
||||||
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 {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipProvider,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip";
|
|
||||||
import { slugify } from "@/lib/slug";
|
|
||||||
import { api } from "@/utils/api";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { CircuitBoard, HelpCircle } from "lucide-react";
|
import { CircuitBoard, HelpCircle } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||||
|
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 {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip";
|
||||||
|
import { slugify } from "@/lib/slug";
|
||||||
|
import { api } from "@/utils/api";
|
||||||
|
|
||||||
const AddComposeSchema = z.object({
|
const AddComposeSchema = z.object({
|
||||||
composeType: z.enum(["docker-compose", "stack"]).optional(),
|
composeType: z.enum(["docker-compose", "stack"]).optional(),
|
||||||
name: z.string().min(1, {
|
name: z.string().min(1, {
|
||||||
message: "Name is required",
|
message: "Name is required",
|
||||||
}),
|
}),
|
||||||
appName: z
|
appName: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, {
|
.min(1, {
|
||||||
message: "App name is required",
|
message: "App name is required",
|
||||||
})
|
})
|
||||||
.regex(/^[a-z](?!.*--)([a-z0-9-]*[a-z])?$/, {
|
.regex(/^[a-z](?!.*--)([a-z0-9-]*[a-z])?$/, {
|
||||||
message:
|
message:
|
||||||
"App name supports lowercase letters, numbers, '-' and can only start and end letters, and does not support continuous '-'",
|
"App name supports lowercase letters, numbers, '-' and can only start and end letters, and does not support continuous '-'",
|
||||||
}),
|
}),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AddCompose = z.infer<typeof AddComposeSchema>;
|
type AddCompose = z.infer<typeof AddComposeSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
projectName?: string;
|
projectName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddCompose = ({ projectId, projectName }: Props) => {
|
export const AddCompose = ({ projectId, projectName }: Props) => {
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const slug = slugify(projectName);
|
const slug = slugify(projectName);
|
||||||
const { data: isCloud } = api.settings.isCloud.useQuery();
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
||||||
const { data: servers } = api.server.withSSHKey.useQuery();
|
const { data: servers } = api.server.withSSHKey.useQuery();
|
||||||
const { mutateAsync, isLoading, error, isError } =
|
const { mutateAsync, isLoading, error, isError } =
|
||||||
api.compose.create.useMutation();
|
api.compose.create.useMutation();
|
||||||
|
|
||||||
const form = useForm<AddCompose>({
|
const hasServers = servers && servers.length > 0;
|
||||||
defaultValues: {
|
|
||||||
name: "",
|
|
||||||
description: "",
|
|
||||||
composeType: "docker-compose",
|
|
||||||
appName: `${slug}-`,
|
|
||||||
},
|
|
||||||
resolver: zodResolver(AddComposeSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
const form = useForm<AddCompose>({
|
||||||
form.reset();
|
defaultValues: {
|
||||||
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
name: "",
|
||||||
|
description: "",
|
||||||
|
composeType: "docker-compose",
|
||||||
|
appName: `${slug}-`,
|
||||||
|
},
|
||||||
|
resolver: zodResolver(AddComposeSchema),
|
||||||
|
});
|
||||||
|
|
||||||
const onSubmit = async (data: AddCompose) => {
|
useEffect(() => {
|
||||||
await mutateAsync({
|
form.reset();
|
||||||
name: data.name,
|
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
||||||
description: data.description,
|
|
||||||
projectId,
|
|
||||||
composeType: data.composeType,
|
|
||||||
appName: data.appName,
|
|
||||||
serverId: data.serverId,
|
|
||||||
})
|
|
||||||
.then(async () => {
|
|
||||||
toast.success("Compose Created");
|
|
||||||
setVisible(false);
|
|
||||||
await utils.project.one.invalidate({
|
|
||||||
projectId,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
toast.error("Error creating the compose");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
const onSubmit = async (data: AddCompose) => {
|
||||||
<Dialog open={visible} onOpenChange={setVisible}>
|
await mutateAsync({
|
||||||
<DialogTrigger className="w-full">
|
name: data.name,
|
||||||
<DropdownMenuItem
|
description: data.description,
|
||||||
className="w-full cursor-pointer space-x-3"
|
projectId,
|
||||||
onSelect={(e) => e.preventDefault()}
|
composeType: data.composeType,
|
||||||
>
|
appName: data.appName,
|
||||||
<CircuitBoard className="size-4 text-muted-foreground" />
|
serverId: data.serverId,
|
||||||
<span>Compose</span>
|
})
|
||||||
</DropdownMenuItem>
|
.then(async () => {
|
||||||
</DialogTrigger>
|
toast.success("Compose Created");
|
||||||
<DialogContent className="sm:max-w-xl">
|
setVisible(false);
|
||||||
<DialogHeader>
|
await utils.project.one.invalidate({
|
||||||
<DialogTitle>Create Compose</DialogTitle>
|
projectId,
|
||||||
<DialogDescription>
|
});
|
||||||
Assign a name and description to your compose
|
})
|
||||||
</DialogDescription>
|
.catch(() => {
|
||||||
</DialogHeader>
|
toast.error("Error creating the compose");
|
||||||
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
<Form {...form}>
|
return (
|
||||||
<form
|
<Dialog open={visible} onOpenChange={setVisible}>
|
||||||
id="hook-form"
|
<DialogTrigger className="w-full">
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
<DropdownMenuItem
|
||||||
className="grid w-full gap-4"
|
className="w-full cursor-pointer space-x-3"
|
||||||
>
|
onSelect={(e) => e.preventDefault()}
|
||||||
<div className="flex flex-col gap-4">
|
>
|
||||||
<FormField
|
<CircuitBoard className="size-4 text-muted-foreground" />
|
||||||
control={form.control}
|
<span>Compose</span>
|
||||||
name="name"
|
</DropdownMenuItem>
|
||||||
render={({ field }) => (
|
</DialogTrigger>
|
||||||
<FormItem>
|
<DialogContent className="sm:max-w-xl">
|
||||||
<FormLabel>Name</FormLabel>
|
<DialogHeader>
|
||||||
<FormControl>
|
<DialogTitle>Create Compose</DialogTitle>
|
||||||
<Input
|
<DialogDescription>
|
||||||
placeholder="Frontend"
|
Assign a name and description to your compose
|
||||||
{...field}
|
</DialogDescription>
|
||||||
onChange={(e) => {
|
</DialogHeader>
|
||||||
const val = e.target.value?.trim() || "";
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
||||||
const serviceName = slugify(val);
|
|
||||||
form.setValue("appName", `${slug}-${serviceName}`);
|
|
||||||
field.onChange(val);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="serverId"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<TooltipProvider delayDuration={0}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
|
|
||||||
Select a Server {!isCloud ? "(Optional)" : ""}
|
|
||||||
<HelpCircle className="size-4 text-muted-foreground" />
|
|
||||||
</FormLabel>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent
|
|
||||||
className="z-[999] w-[300px]"
|
|
||||||
align="start"
|
|
||||||
side="top"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
If no server is selected, the application will be
|
|
||||||
deployed on the server where the user is logged in.
|
|
||||||
</span>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</TooltipProvider>
|
|
||||||
|
|
||||||
<Select
|
<Form {...form}>
|
||||||
onValueChange={field.onChange}
|
<form
|
||||||
defaultValue={field.value}
|
id="hook-form"
|
||||||
>
|
onSubmit={form.handleSubmit(onSubmit)}
|
||||||
<SelectTrigger>
|
className="grid w-full gap-4"
|
||||||
<SelectValue placeholder="Select a Server" />
|
>
|
||||||
</SelectTrigger>
|
<div className="flex flex-col gap-4">
|
||||||
<SelectContent>
|
<FormField
|
||||||
<SelectGroup>
|
control={form.control}
|
||||||
{servers?.map((server) => (
|
name="name"
|
||||||
<SelectItem
|
render={({ field }) => (
|
||||||
key={server.serverId}
|
<FormItem>
|
||||||
value={server.serverId}
|
<FormLabel>Name</FormLabel>
|
||||||
>
|
<FormControl>
|
||||||
<span className="flex items-center gap-2 justify-between w-full">
|
<Input
|
||||||
<span>{server.name}</span>
|
placeholder="Frontend"
|
||||||
<span className="text-muted-foreground text-xs self-center">
|
{...field}
|
||||||
{server.ipAddress}
|
onChange={(e) => {
|
||||||
</span>
|
const val = e.target.value?.trim() || "";
|
||||||
</span>
|
const serviceName = slugify(val);
|
||||||
</SelectItem>
|
form.setValue("appName", `${slug}-${serviceName}`);
|
||||||
))}
|
field.onChange(val);
|
||||||
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
}}
|
||||||
</SelectGroup>
|
/>
|
||||||
</SelectContent>
|
</FormControl>
|
||||||
</Select>
|
<FormMessage />
|
||||||
<FormMessage />
|
</FormItem>
|
||||||
</FormItem>
|
)}
|
||||||
)}
|
/>
|
||||||
/>
|
</div>
|
||||||
<FormField
|
{hasServers && (
|
||||||
control={form.control}
|
<FormField
|
||||||
name="appName"
|
control={form.control}
|
||||||
render={({ field }) => (
|
name="serverId"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<FormLabel>App Name</FormLabel>
|
<FormItem>
|
||||||
<FormControl>
|
<TooltipProvider delayDuration={0}>
|
||||||
<Input placeholder="my-app" {...field} />
|
<Tooltip>
|
||||||
</FormControl>
|
<TooltipTrigger asChild>
|
||||||
<FormMessage />
|
<FormLabel className="break-all w-fit flex flex-row gap-1 items-center">
|
||||||
</FormItem>
|
Select a Server {!isCloud ? "(Optional)" : ""}
|
||||||
)}
|
<HelpCircle className="size-4 text-muted-foreground" />
|
||||||
/>
|
</FormLabel>
|
||||||
<FormField
|
</TooltipTrigger>
|
||||||
control={form.control}
|
<TooltipContent
|
||||||
name="composeType"
|
className="z-[999] w-[300px]"
|
||||||
render={({ field }) => (
|
align="start"
|
||||||
<FormItem>
|
side="top"
|
||||||
<FormLabel>Compose Type</FormLabel>
|
>
|
||||||
<Select
|
<span>
|
||||||
onValueChange={field.onChange}
|
If no server is selected, the application will be
|
||||||
defaultValue={field.value}
|
deployed on the server where the user is logged in.
|
||||||
>
|
</span>
|
||||||
<FormControl>
|
</TooltipContent>
|
||||||
<SelectTrigger>
|
</Tooltip>
|
||||||
<SelectValue placeholder="Select a compose type" />
|
</TooltipProvider>
|
||||||
</SelectTrigger>
|
|
||||||
</FormControl>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="docker-compose">
|
|
||||||
Docker Compose
|
|
||||||
</SelectItem>
|
|
||||||
<SelectItem value="stack">Stack</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="description"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Description</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Textarea
|
|
||||||
placeholder="Description of your service..."
|
|
||||||
className="resize-none"
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
<Select
|
||||||
</FormItem>
|
onValueChange={field.onChange}
|
||||||
)}
|
defaultValue={field.value}
|
||||||
/>
|
>
|
||||||
</form>
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select a Server" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
{servers?.map((server) => (
|
||||||
|
<SelectItem
|
||||||
|
key={server.serverId}
|
||||||
|
value={server.serverId}
|
||||||
|
>
|
||||||
|
<span className="flex items-center gap-2 justify-between w-full">
|
||||||
|
<span>{server.name}</span>
|
||||||
|
<span className="text-muted-foreground text-xs self-center">
|
||||||
|
{server.ipAddress}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="appName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>App Name</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input placeholder="my-app" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="composeType"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Compose Type</FormLabel>
|
||||||
|
<Select
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
defaultValue={field.value}
|
||||||
|
>
|
||||||
|
<FormControl>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Select a compose type" />
|
||||||
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="docker-compose">
|
||||||
|
Docker Compose
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="stack">Stack</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Description</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Description of your service..."
|
||||||
|
className="resize-none"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<DialogFooter>
|
<FormMessage />
|
||||||
<Button isLoading={isLoading} form="hook-form" type="submit">
|
</FormItem>
|
||||||
Create
|
)}
|
||||||
</Button>
|
/>
|
||||||
</DialogFooter>
|
</form>
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
<DialogFooter>
|
||||||
</Dialog>
|
<Button isLoading={isLoading} form="hook-form" type="submit">
|
||||||
);
|
Create
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</Form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@ const examples = [
|
|||||||
export const StepOne = ({ setTemplateInfo, templateInfo }: any) => {
|
export const StepOne = ({ setTemplateInfo, templateInfo }: any) => {
|
||||||
// Get servers from the API
|
// Get servers from the API
|
||||||
const { data: servers } = api.server.withSSHKey.useQuery();
|
const { data: servers } = api.server.withSSHKey.useQuery();
|
||||||
|
const hasServers = servers && servers.length > 0;
|
||||||
|
|
||||||
const handleExampleClick = (example: string) => {
|
const handleExampleClick = (example: string) => {
|
||||||
setTemplateInfo({ ...templateInfo, userInput: example });
|
setTemplateInfo({ ...templateInfo, userInput: example });
|
||||||
@@ -47,37 +48,39 @@ export const StepOne = ({ setTemplateInfo, templateInfo }: any) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
{hasServers && (
|
||||||
<Label htmlFor="server-deploy">
|
<div className="space-y-2">
|
||||||
Select the server where you want to deploy (optional)
|
<Label htmlFor="server-deploy">
|
||||||
</Label>
|
Select the server where you want to deploy (optional)
|
||||||
<Select
|
</Label>
|
||||||
value={templateInfo.server?.serverId}
|
<Select
|
||||||
onValueChange={(value) => {
|
value={templateInfo.server?.serverId}
|
||||||
const server = servers?.find((s) => s.serverId === value);
|
onValueChange={(value) => {
|
||||||
if (server) {
|
const server = servers?.find((s) => s.serverId === value);
|
||||||
setTemplateInfo({
|
if (server) {
|
||||||
...templateInfo,
|
setTemplateInfo({
|
||||||
server: server,
|
...templateInfo,
|
||||||
});
|
server: server,
|
||||||
}
|
});
|
||||||
}}
|
}
|
||||||
>
|
}}
|
||||||
<SelectTrigger className="w-full">
|
>
|
||||||
<SelectValue placeholder="Select a server" />
|
<SelectTrigger className="w-full">
|
||||||
</SelectTrigger>
|
<SelectValue placeholder="Select a server" />
|
||||||
<SelectContent>
|
</SelectTrigger>
|
||||||
<SelectGroup>
|
<SelectContent>
|
||||||
{servers?.map((server) => (
|
<SelectGroup>
|
||||||
<SelectItem key={server.serverId} value={server.serverId}>
|
{servers?.map((server) => (
|
||||||
{server.name}
|
<SelectItem key={server.serverId} value={server.serverId}>
|
||||||
</SelectItem>
|
{server.name}
|
||||||
))}
|
</SelectItem>
|
||||||
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
))}
|
||||||
</SelectGroup>
|
<SelectLabel>Servers ({servers?.length})</SelectLabel>
|
||||||
</SelectContent>
|
</SelectGroup>
|
||||||
</Select>
|
</SelectContent>
|
||||||
</div>
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Examples:</Label>
|
<Label>Examples:</Label>
|
||||||
|
|||||||
Reference in New Issue
Block a user