mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-02 10:12:15 +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>
309 lines
8.6 KiB
TypeScript
309 lines
8.6 KiB
TypeScript
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
|
import { HelpCircle, PlusIcon, SquarePen } 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 { 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 {
|
|
Select,
|
|
SelectContent,
|
|
SelectGroup,
|
|
SelectItem,
|
|
SelectLabel,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import {
|
|
Tooltip,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip";
|
|
import { api } from "@/utils/api";
|
|
|
|
const certificateDataHolder =
|
|
"-----BEGIN CERTIFICATE-----\nMIIFRDCCAyygAwIBAgIUEPOR47ys6VDwMVB9tYoeEka83uQwDQYJKoZIhvcNAQELBQAwGTEXMBUGA1UEAwwObWktZG9taW5pby5jb20wHhcNMjQwMzExMDQyNzU3WhcN\n------END CERTIFICATE-----";
|
|
|
|
const privateKeyDataHolder =
|
|
"-----BEGIN PRIVATE KEY-----\nMIIFRDCCAyygAwIBAgIUEPOR47ys6VDwMVB9tYoeEka83uQwDQYJKoZIhvcNAQELBQAwGTEXMBUGA1UEAwwObWktZG9taW5pby5jb20wHhcNMjQwMzExMDQyNzU3WhcN\n-----END PRIVATE KEY-----";
|
|
|
|
const handleCertificateSchema = z.object({
|
|
name: z.string().min(1, "Name is required"),
|
|
certificateData: z.string().min(1, "Certificate data is required"),
|
|
privateKey: z.string().min(1, "Private key is required"),
|
|
serverId: z.string().optional(),
|
|
});
|
|
|
|
type HandleCertificateForm = z.infer<typeof handleCertificateSchema>;
|
|
|
|
interface Props {
|
|
certificateId?: string;
|
|
}
|
|
|
|
export const HandleCertificate = ({ certificateId }: Props) => {
|
|
const [open, setOpen] = useState(false);
|
|
const utils = api.useUtils();
|
|
|
|
const { data: isCloud } = api.settings.isCloud.useQuery();
|
|
const { data: servers } = api.server.withSSHKey.useQuery();
|
|
const hasServers = servers && servers.length > 0;
|
|
const shouldShowServerDropdown = hasServers && !certificateId; // Hide on edit
|
|
|
|
const { data: existingCert, refetch } = api.certificates.one.useQuery(
|
|
{ certificateId: certificateId || "" },
|
|
{ enabled: !!certificateId },
|
|
);
|
|
|
|
const createMutation = api.certificates.create.useMutation();
|
|
const updateMutation = api.certificates.update.useMutation();
|
|
const mutation = certificateId ? updateMutation : createMutation;
|
|
const { mutateAsync, isError, error, isPending } = mutation;
|
|
|
|
const form = useForm<HandleCertificateForm>({
|
|
defaultValues: {
|
|
name: "",
|
|
certificateData: "",
|
|
privateKey: "",
|
|
},
|
|
resolver: zodResolver(handleCertificateSchema),
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (existingCert) {
|
|
form.reset({
|
|
name: existingCert.name,
|
|
certificateData: existingCert.certificateData,
|
|
privateKey: existingCert.privateKey,
|
|
});
|
|
} else {
|
|
form.reset({
|
|
name: "",
|
|
certificateData: "",
|
|
privateKey: "",
|
|
});
|
|
}
|
|
}, [existingCert, form, open]);
|
|
|
|
const onSubmit = async (data: HandleCertificateForm) => {
|
|
const basePayload = {
|
|
name: data.name,
|
|
certificateData: data.certificateData,
|
|
privateKey: data.privateKey,
|
|
};
|
|
|
|
const promise = certificateId
|
|
? updateMutation.mutateAsync({
|
|
certificateId,
|
|
...basePayload,
|
|
})
|
|
: createMutation.mutateAsync({
|
|
...basePayload,
|
|
serverId: data.serverId === "dokploy" ? undefined : data.serverId,
|
|
organizationId: "",
|
|
});
|
|
|
|
await promise
|
|
.then(async () => {
|
|
toast.success(
|
|
certificateId ? "Certificate Updated" : "Certificate Created",
|
|
);
|
|
await utils.certificates.all.invalidate();
|
|
if (certificateId) {
|
|
refetch();
|
|
}
|
|
setOpen(false);
|
|
})
|
|
.catch(() => {
|
|
toast.error(
|
|
certificateId
|
|
? "Error updating the Certificate"
|
|
: "Error creating the Certificate",
|
|
);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogTrigger asChild>
|
|
{certificateId ? (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="group hover:bg-blue-500/10"
|
|
>
|
|
<SquarePen className="size-3.5 text-primary group-hover:text-blue-500" />
|
|
</Button>
|
|
) : (
|
|
<Button>
|
|
<PlusIcon className="h-4 w-4" />
|
|
Add Certificate
|
|
</Button>
|
|
)}
|
|
</DialogTrigger>
|
|
<DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
{certificateId ? "Update" : "Add New"} Certificate
|
|
</DialogTitle>
|
|
<DialogDescription>
|
|
{certificateId
|
|
? "Modify the certificate details"
|
|
: "Upload or generate a certificate to secure your application"}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
|
|
|
<Form {...form}>
|
|
<form
|
|
id="hook-form-handle-certificate"
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className="grid w-full gap-4"
|
|
>
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Certificate Name</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="My Certificate" {...field} />
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="certificateData"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Certificate Data</FormLabel>
|
|
<FormControl>
|
|
<Textarea
|
|
className="h-32 max-h-32 resize-none overflow-y-auto field-sizing-fixed"
|
|
placeholder={certificateDataHolder}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="privateKey"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Private Key</FormLabel>
|
|
<FormControl>
|
|
<Textarea
|
|
className="h-32 max-h-32 resize-none overflow-y-auto field-sizing-fixed"
|
|
placeholder={privateKeyDataHolder}
|
|
{...field}
|
|
/>
|
|
</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 {!isCloud && "(Optional)"}
|
|
<HelpCircle className="size-4 text-muted-foreground" />
|
|
</FormLabel>
|
|
</TooltipTrigger>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
|
|
<Select
|
|
onValueChange={field.onChange}
|
|
defaultValue={
|
|
field.value || (!isCloud ? "dokploy" : undefined)
|
|
}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue
|
|
placeholder={!isCloud ? "Dokploy" : "Select a Server"}
|
|
/>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectGroup>
|
|
{!isCloud && (
|
|
<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 + (!isCloud ? 1 : 0)})
|
|
</SelectLabel>
|
|
</SelectGroup>
|
|
</SelectContent>
|
|
</Select>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
</form>
|
|
|
|
<DialogFooter className="flex w-full flex-row justify-end!">
|
|
<Button
|
|
isLoading={isPending}
|
|
form="hook-form-handle-certificate"
|
|
type="submit"
|
|
>
|
|
{certificateId ? "Update" : "Create"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|