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>
235 lines
6.0 KiB
TypeScript
235 lines
6.0 KiB
TypeScript
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
|
|
import { useEffect } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
import { toast } from "sonner";
|
|
import { z } from "zod";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card } from "@/components/ui/card";
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
} from "@/components/ui/form";
|
|
import { Secrets } from "@/components/ui/secrets";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { api } from "@/utils/api";
|
|
|
|
const addEnvironmentSchema = z.object({
|
|
env: z.string(),
|
|
buildArgs: z.string(),
|
|
buildSecrets: z.string(),
|
|
createEnvFile: z.boolean(),
|
|
});
|
|
|
|
type EnvironmentSchema = z.infer<typeof addEnvironmentSchema>;
|
|
|
|
interface Props {
|
|
applicationId: string;
|
|
}
|
|
|
|
export const ShowEnvironment = ({ applicationId }: Props) => {
|
|
const { data: permissions } = api.user.getPermissions.useQuery();
|
|
const canWrite = permissions?.envVars.write ?? false;
|
|
const { mutateAsync, isPending } =
|
|
api.application.saveEnvironment.useMutation();
|
|
|
|
const { data, refetch } = api.application.one.useQuery(
|
|
{
|
|
applicationId,
|
|
},
|
|
{
|
|
enabled: !!applicationId,
|
|
},
|
|
);
|
|
|
|
const form = useForm<EnvironmentSchema>({
|
|
defaultValues: {
|
|
env: "",
|
|
buildArgs: "",
|
|
buildSecrets: "",
|
|
createEnvFile: true,
|
|
},
|
|
resolver: zodResolver(addEnvironmentSchema),
|
|
});
|
|
|
|
// Watch form values
|
|
const currentEnv = form.watch("env");
|
|
const currentBuildArgs = form.watch("buildArgs");
|
|
const currentBuildSecrets = form.watch("buildSecrets");
|
|
const currentCreateEnvFile = form.watch("createEnvFile");
|
|
const hasChanges =
|
|
currentEnv !== (data?.env || "") ||
|
|
currentBuildArgs !== (data?.buildArgs || "") ||
|
|
currentBuildSecrets !== (data?.buildSecrets || "") ||
|
|
currentCreateEnvFile !== (data?.createEnvFile ?? true);
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
form.reset({
|
|
env: data.env || "",
|
|
buildArgs: data.buildArgs || "",
|
|
buildSecrets: data.buildSecrets || "",
|
|
createEnvFile: data.createEnvFile ?? true,
|
|
});
|
|
}
|
|
}, [data, form]);
|
|
|
|
const onSubmit = async (formData: EnvironmentSchema) => {
|
|
mutateAsync({
|
|
env: formData.env,
|
|
buildArgs: formData.buildArgs,
|
|
buildSecrets: formData.buildSecrets,
|
|
createEnvFile: formData.createEnvFile,
|
|
applicationId,
|
|
})
|
|
.then(async () => {
|
|
toast.success("Environments Added");
|
|
await refetch();
|
|
})
|
|
.catch(() => {
|
|
toast.error("Error adding environment");
|
|
});
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
form.reset({
|
|
env: data?.env || "",
|
|
buildArgs: data?.buildArgs || "",
|
|
buildSecrets: data?.buildSecrets || "",
|
|
createEnvFile: data?.createEnvFile ?? true,
|
|
});
|
|
};
|
|
|
|
// Add keyboard shortcut for Ctrl+S/Cmd+S
|
|
useEffect(() => {
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
if ((e.ctrlKey || e.metaKey) && e.code === "KeyS" && !isPending) {
|
|
e.preventDefault();
|
|
form.handleSubmit(onSubmit)();
|
|
}
|
|
};
|
|
|
|
document.addEventListener("keydown", handleKeyDown);
|
|
return () => {
|
|
document.removeEventListener("keydown", handleKeyDown);
|
|
};
|
|
}, [form, onSubmit, isPending]);
|
|
|
|
return (
|
|
<Card className="bg-background px-6 pb-6">
|
|
<Form {...form}>
|
|
<form
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className="flex w-full flex-col gap-4"
|
|
>
|
|
<Secrets
|
|
name="env"
|
|
title="Environment Settings"
|
|
description={
|
|
<span>
|
|
You can add environment variables to your resource.
|
|
{hasChanges && (
|
|
<span className="text-yellow-500 ml-2">
|
|
(You have unsaved changes)
|
|
</span>
|
|
)}
|
|
</span>
|
|
}
|
|
placeholder={["NODE_ENV=production", "PORT=3000"].join("\n")}
|
|
/>
|
|
{data?.buildType === "dockerfile" && (
|
|
<Secrets
|
|
name="buildArgs"
|
|
title="Build-time Arguments"
|
|
description={
|
|
<span>
|
|
Arguments are available only at build-time. See
|
|
documentation
|
|
<a
|
|
className="text-primary"
|
|
href="https://docs.docker.com/build/building/variables/"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
here
|
|
</a>
|
|
.
|
|
</span>
|
|
}
|
|
placeholder="NPM_TOKEN=xyz"
|
|
/>
|
|
)}
|
|
{data?.buildType === "dockerfile" && (
|
|
<Secrets
|
|
name="buildSecrets"
|
|
title="Build-time Secrets"
|
|
description={
|
|
<span>
|
|
Secrets are specially designed for sensitive information and
|
|
are only available at build-time. See documentation
|
|
<a
|
|
className="text-primary"
|
|
href="https://docs.docker.com/build/building/secrets/"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
here
|
|
</a>
|
|
.
|
|
</span>
|
|
}
|
|
placeholder="NPM_TOKEN=xyz"
|
|
/>
|
|
)}
|
|
{data?.buildType === "dockerfile" && (
|
|
<FormField
|
|
control={form.control}
|
|
name="createEnvFile"
|
|
render={({ field }) => (
|
|
<FormItem className="flex flex-row items-center justify-between p-3 border rounded-lg shadow-xs">
|
|
<div className="space-y-0.5">
|
|
<FormLabel>Create Environment File</FormLabel>
|
|
<FormDescription>
|
|
When enabled, an .env file will be created in the same
|
|
directory as your Dockerfile during the build process.
|
|
Disable this if you don't want to generate an environment
|
|
file.
|
|
</FormDescription>
|
|
</div>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={!canWrite}
|
|
/>
|
|
</FormControl>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
)}
|
|
{canWrite && (
|
|
<div className="flex flex-row justify-end gap-2">
|
|
{hasChanges && (
|
|
<Button type="button" variant="outline" onClick={handleCancel}>
|
|
Cancel
|
|
</Button>
|
|
)}
|
|
<Button
|
|
isLoading={isPending}
|
|
className="w-fit"
|
|
type="submit"
|
|
disabled={!hasChanges}
|
|
>
|
|
Save
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</form>
|
|
</Form>
|
|
</Card>
|
|
);
|
|
};
|