mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-13 18:05:31 +02:00
* feat: update dependencies and enhance UI components in Dokploy - Updated various package versions in pnpm-lock.yaml to improve compatibility and performance, including React and Tailwind CSS. - Modified components.json to change the styling to "radix-nova" and added new properties for icon library and menu color. - Refactored multiple components to use updated class names for better styling consistency and responsiveness. - Removed unused Radix UI components from package.json to streamline dependencies. - Adjusted layout and styling in several dashboard components for improved user experience and visual appeal. - Enhanced tooltip and form item components for better accessibility and usability. * refactor: enhance UI components in HandleCertificate and SidebarLogo - Updated the HandleCertificate component to improve dialog content height and textarea styling for better usability. - Adjusted the SidebarLogo component layout to enhance alignment and spacing, ensuring a more consistent appearance across the sidebar. - Implemented responsive design adjustments to textarea elements, preventing overflow and improving user experience. * refactor: improve UI consistency and styling across dashboard components - Updated Card components in ShowDeployments, ShowSchedules, and ShowVolumeBackups to remove unnecessary border styles for a cleaner look. - Enhanced TabsList components in ShowProviderForm and ShowProviderFormCompose by adding a variant for improved visual distinction. - Adjusted spacing in AdvancedEnvironmentSelector for better layout and readability. - Removed redundant border classes in Service component for a more streamlined design. * [autofix.ci] apply automated fixes * chore: update package dependencies and refactor email rendering - Upgraded React and React DOM to version 19.2.7 across multiple packages for improved performance and compatibility. - Updated TSX to version 4.22.4 in various package.json files. - Refactored email rendering from `renderAsync` to `render` in notification utilities and email templates for consistency. - Adjusted Tailwind configuration usage in email templates to utilize a centralized configuration file. These changes enhance the overall stability and maintainability of the codebase. * refactor: update badge variants across dashboard components - Changed badge variant from "outline-solid" to "outline" in multiple components including columns, show-domains, and various deployment tables for consistency in styling. - Updated button variants in billing and project templates to align with the new badge styling. - Enhanced input components to support password generation and error messaging, improving user experience. These changes streamline the UI and ensure a cohesive design across the application. * refactor: clean up calendar component imports and structure - Removed redundant imports of icons from lucide-react and streamlined the import statements for better readability. - Adjusted the placement of type imports to enhance code organization. These changes improve the maintainability and clarity of the calendar component. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
302 lines
8.4 KiB
TypeScript
302 lines
8.4 KiB
TypeScript
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
|
import { Folder, HelpCircle } from "lucide-react";
|
|
import { useState } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
import { toast } from "sonner";
|
|
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";
|
|
import { APP_NAME_MESSAGE, APP_NAME_REGEX } from "@/utils/schema";
|
|
|
|
const AddTemplateSchema = z.object({
|
|
name: z.string().min(1, {
|
|
message: "Name is required",
|
|
}),
|
|
appName: z
|
|
.string()
|
|
.min(1, {
|
|
message: "App name is required",
|
|
})
|
|
.regex(APP_NAME_REGEX, {
|
|
message: APP_NAME_MESSAGE,
|
|
}),
|
|
description: z.string().optional(),
|
|
serverId: z.string().optional(),
|
|
});
|
|
|
|
type AddTemplate = z.infer<typeof AddTemplateSchema>;
|
|
|
|
interface Props {
|
|
environmentId: string;
|
|
projectName?: string;
|
|
}
|
|
|
|
export const AddApplication = ({ environmentId, projectName }: Props) => {
|
|
const utils = api.useUtils();
|
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
|
const { data: webServerSettings } =
|
|
api.settings.getWebServerSettings.useQuery();
|
|
const showLocalOption = !isCloud && !webServerSettings?.remoteServersOnly;
|
|
const [visible, setVisible] = useState(false);
|
|
const slug = slugify(projectName);
|
|
const { data: servers } = api.server.withSSHKey.useQuery();
|
|
|
|
const hasServers = servers && servers.length > 0;
|
|
// Show dropdown logic based on cloud environment
|
|
// Cloud: show only if there are remote servers (no Dokploy option)
|
|
// Self-hosted: show only if there are remote servers (Dokploy is default, hide if no remote servers)
|
|
const shouldShowServerDropdown = hasServers;
|
|
|
|
const { mutateAsync, isPending, error, isError } =
|
|
api.application.create.useMutation();
|
|
|
|
const form = useForm<AddTemplate>({
|
|
defaultValues: {
|
|
name: "",
|
|
appName: `${slug}-`,
|
|
description: "",
|
|
},
|
|
resolver: zodResolver(AddTemplateSchema),
|
|
});
|
|
|
|
const onSubmit = async (data: AddTemplate) => {
|
|
await mutateAsync({
|
|
name: data.name,
|
|
appName: data.appName,
|
|
description: data.description,
|
|
serverId: data.serverId === "dokploy" ? undefined : data.serverId,
|
|
environmentId,
|
|
})
|
|
.then(async () => {
|
|
toast.success("Service Created");
|
|
form.reset();
|
|
setVisible(false);
|
|
await utils.environment.one.invalidate({
|
|
environmentId,
|
|
});
|
|
})
|
|
.catch(() => {
|
|
toast.error("Error creating the service");
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Dialog open={visible} onOpenChange={setVisible}>
|
|
<DialogTrigger className="w-full">
|
|
<DropdownMenuItem
|
|
className="w-full cursor-pointer space-x-3"
|
|
onSelect={(e) => e.preventDefault()}
|
|
>
|
|
<Folder className="size-4 text-muted-foreground" />
|
|
<span>Application</span>
|
|
</DropdownMenuItem>
|
|
</DialogTrigger>
|
|
<DialogContent className="sm:max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle>Create</DialogTitle>
|
|
<DialogDescription>
|
|
Assign a name and description to your application
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
{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 || "";
|
|
const serviceName = slugify(val.trim());
|
|
form.setValue("appName", `${slug}-${serviceName}`);
|
|
field.onChange(val);
|
|
}}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
{shouldShowServerDropdown && (
|
|
<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{" "}
|
|
{showLocalOption ? "(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
|
|
onValueChange={field.onChange}
|
|
defaultValue={
|
|
field.value || (showLocalOption ? "dokploy" : undefined)
|
|
}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue
|
|
placeholder={
|
|
showLocalOption ? "Dokploy" : "Select a Server"
|
|
}
|
|
/>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectGroup>
|
|
{showLocalOption && (
|
|
<SelectItem value="dokploy">
|
|
<span className="flex items-center gap-2 justify-between w-full">
|
|
<span>Dokploy</span>
|
|
<span className="text-muted-foreground text-xs self-center">
|
|
Default
|
|
</span>
|
|
</span>
|
|
</SelectItem>
|
|
)}
|
|
{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 + (showLocalOption ? 1 : 0)})
|
|
</SelectLabel>
|
|
</SelectGroup>
|
|
</SelectContent>
|
|
</Select>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
<FormField
|
|
control={form.control}
|
|
name="appName"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel className="flex items-center gap-2">
|
|
App Name
|
|
<TooltipProvider delayDuration={0}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<HelpCircle className="size-4 text-muted-foreground" />
|
|
</TooltipTrigger>
|
|
<TooltipContent side="right">
|
|
<p>
|
|
This will be the name of the Docker Swarm service
|
|
</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
</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>
|
|
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</form>
|
|
|
|
<DialogFooter>
|
|
<Button isLoading={isPending} form="hook-form" type="submit">
|
|
Create
|
|
</Button>
|
|
</DialogFooter>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|