mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-19 02:15:17 +00:00
3ca5afd49f
* 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>
326 lines
7.4 KiB
TypeScript
326 lines
7.4 KiB
TypeScript
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
|
import { PenBoxIcon } from "lucide-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";
|
|
import { CodeEditor } from "@/components/shared/code-editor";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog";
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from "@/components/ui/form";
|
|
import { Input } from "@/components/ui/input";
|
|
import { api } from "@/utils/api";
|
|
|
|
const mountSchema = z.object({
|
|
mountPath: z.string().min(1, "Mount path required"),
|
|
});
|
|
|
|
const mySchema = z.discriminatedUnion("type", [
|
|
z
|
|
.object({
|
|
type: z.literal("bind"),
|
|
hostPath: z.string().min(1, "Host path required"),
|
|
})
|
|
.merge(mountSchema),
|
|
z
|
|
.object({
|
|
type: z.literal("volume"),
|
|
volumeName: z
|
|
.string()
|
|
.min(1, "Volume name required")
|
|
.regex(
|
|
/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/,
|
|
"Invalid volume name. Use letters, numbers, '._-' and start with a letter/number.",
|
|
),
|
|
})
|
|
.merge(mountSchema),
|
|
z
|
|
.object({
|
|
type: z.literal("file"),
|
|
content: z.string().optional(),
|
|
filePath: z.string().min(1, "File path required"),
|
|
})
|
|
.merge(mountSchema),
|
|
]);
|
|
|
|
type UpdateMount = z.infer<typeof mySchema>;
|
|
|
|
interface Props {
|
|
mountId: string;
|
|
type: "bind" | "volume" | "file";
|
|
refetch: () => void;
|
|
serviceType:
|
|
| "application"
|
|
| "compose"
|
|
| "libsql"
|
|
| "mariadb"
|
|
| "mongo"
|
|
| "mysql"
|
|
| "postgres"
|
|
| "redis";
|
|
}
|
|
|
|
export const UpdateVolume = ({
|
|
mountId,
|
|
type,
|
|
refetch,
|
|
serviceType,
|
|
}: Props) => {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const _utils = api.useUtils();
|
|
const { data } = api.mounts.one.useQuery(
|
|
{
|
|
mountId,
|
|
},
|
|
{
|
|
enabled: !!mountId,
|
|
},
|
|
);
|
|
|
|
const { mutateAsync, isPending, error, isError } =
|
|
api.mounts.update.useMutation();
|
|
|
|
const form = useForm<UpdateMount>({
|
|
defaultValues: {
|
|
type,
|
|
hostPath: "",
|
|
mountPath: "",
|
|
},
|
|
resolver: zodResolver(mySchema),
|
|
});
|
|
|
|
const typeForm = form.watch("type");
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
if (typeForm === "bind") {
|
|
form.reset({
|
|
hostPath: data.hostPath || "",
|
|
mountPath: data.mountPath,
|
|
type: "bind",
|
|
});
|
|
} else if (typeForm === "volume") {
|
|
form.reset({
|
|
volumeName: data.volumeName || "",
|
|
mountPath: data.mountPath,
|
|
type: "volume",
|
|
});
|
|
} else if (typeForm === "file") {
|
|
form.reset({
|
|
content: data.content || "",
|
|
mountPath: serviceType === "compose" ? "/" : data.mountPath,
|
|
filePath: data.filePath || "",
|
|
type: "file",
|
|
});
|
|
}
|
|
}
|
|
}, [form, form.reset, data]);
|
|
|
|
const onSubmit = async (data: UpdateMount) => {
|
|
if (data.type === "bind") {
|
|
await mutateAsync({
|
|
hostPath: data.hostPath,
|
|
mountPath: data.mountPath,
|
|
type: data.type,
|
|
mountId,
|
|
})
|
|
.then(() => {
|
|
toast.success("Mount Update");
|
|
setIsOpen(false);
|
|
})
|
|
.catch(() => {
|
|
toast.error("Error updating the Bind mount");
|
|
});
|
|
} else if (data.type === "volume") {
|
|
await mutateAsync({
|
|
volumeName: data.volumeName,
|
|
mountPath: data.mountPath,
|
|
type: data.type,
|
|
mountId,
|
|
})
|
|
.then(() => {
|
|
toast.success("Mount Update");
|
|
setIsOpen(false);
|
|
})
|
|
.catch(() => {
|
|
toast.error("Error updating the Volume mount");
|
|
});
|
|
} else if (data.type === "file") {
|
|
await mutateAsync({
|
|
content: data.content,
|
|
mountPath: data.mountPath,
|
|
type: data.type,
|
|
filePath: data.filePath,
|
|
mountId,
|
|
})
|
|
.then(() => {
|
|
toast.success("Mount Update");
|
|
setIsOpen(false);
|
|
})
|
|
.catch(() => {
|
|
toast.error("Error updating the File mount");
|
|
});
|
|
}
|
|
refetch();
|
|
};
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="group hover:bg-blue-500/10 "
|
|
isLoading={isPending}
|
|
>
|
|
<PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" />
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent className="sm:max-w-3xl">
|
|
<DialogHeader>
|
|
<DialogTitle>Update</DialogTitle>
|
|
<DialogDescription>Update the mount</DialogDescription>
|
|
</DialogHeader>
|
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
|
{type === "file" && (
|
|
<AlertBlock type="warning">
|
|
Updating the mount will recreate the file or directory.
|
|
</AlertBlock>
|
|
)}
|
|
|
|
<Form {...form}>
|
|
<form
|
|
id="hook-form-update-volume"
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className="grid w-full gap-4"
|
|
>
|
|
<div className="flex flex-col gap-4">
|
|
{type === "bind" && (
|
|
<FormField
|
|
control={form.control}
|
|
name="hostPath"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Host Path</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="Host Path" {...field} />
|
|
</FormControl>
|
|
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
{type === "volume" && (
|
|
<FormField
|
|
control={form.control}
|
|
name="volumeName"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Volume Name</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
placeholder="Volume Name"
|
|
{...field}
|
|
value={field.value || ""}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
|
|
{type === "file" && (
|
|
<>
|
|
<FormField
|
|
control={form.control}
|
|
name="content"
|
|
render={({ field }) => (
|
|
<FormItem className="w-full max-w-180">
|
|
<FormLabel>Content</FormLabel>
|
|
<FormControl>
|
|
<FormControl>
|
|
<CodeEditor
|
|
language="properties"
|
|
placeholder={`NODE_ENV=production
|
|
PORT=3000
|
|
`}
|
|
className="h-96 font-mono w-full"
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="filePath"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>File Path</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
disabled
|
|
placeholder="Name of the file"
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</>
|
|
)}
|
|
{serviceType !== "compose" && (
|
|
<FormField
|
|
control={form.control}
|
|
name="mountPath"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Mount Path (In the container)</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="Mount Path" {...field} />
|
|
</FormControl>
|
|
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
</div>
|
|
<DialogFooter>
|
|
<Button
|
|
isLoading={isPending}
|
|
// form="hook-form-update-volume"
|
|
type="submit"
|
|
>
|
|
Update
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|