fix(ui): code formatting and DialogHeader improvements

- Apply consistent code formatting across dialog components
- Add bottom padding to DialogHeader for better visual separation
- Clean up DialogHeader usage in swarm settings (remove duplicate padding)
- Improve schedule dialog layout and add proper description
- Fix indentation and formatting inconsistencies

Final cleanup of dialog component formatting and spacing.
This commit is contained in:
Jhon
2025-07-13 13:35:26 -03:00
parent 2209d44ea5
commit 94829daf15
3 changed files with 119 additions and 100 deletions
@@ -271,7 +271,7 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
</Button> </Button>
</DialogTrigger> </DialogTrigger>
<DialogContent className="sm:max-w-5xl p-0"> <DialogContent className="sm:max-w-5xl p-0">
<DialogHeader className="p-6"> <DialogHeader>
<DialogTitle>Swarm Settings</DialogTitle> <DialogTitle>Swarm Settings</DialogTitle>
<DialogDescription> <DialogDescription>
Update certain settings using a json object. Update certain settings using a json object.
@@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
DialogTrigger, DialogTrigger,
@@ -232,14 +233,17 @@ export const HandleSchedules = ({ id, scheduleId, scheduleType }: Props) => {
</DialogTrigger> </DialogTrigger>
<DialogContent <DialogContent
className={cn( className={cn(
"overflow-y-auto",
scheduleTypeForm === "dokploy-server" || scheduleTypeForm === "server" scheduleTypeForm === "dokploy-server" || scheduleTypeForm === "server"
? "max-h-[95vh] sm:max-w-2xl" ? "sm:max-w-2xl"
: " sm:max-w-lg", : "sm:max-w-lg",
)} )}
> >
<DialogHeader> <DialogHeader>
<DialogTitle>{scheduleId ? "Edit" : "Create"} Schedule</DialogTitle> <DialogTitle>{scheduleId ? "Edit" : "Create"} Schedule</DialogTitle>
<DialogDescription>
{scheduleId ? "Manage" : "Create"} a schedule to run a task at a
specific time or interval.
</DialogDescription>
</DialogHeader> </DialogHeader>
<Form {...form}> <Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6"> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
@@ -434,82 +438,82 @@ export const HandleSchedules = ({ id, scheduleId, scheduleType }: Props) => {
{(scheduleTypeForm === "application" || {(scheduleTypeForm === "application" ||
scheduleTypeForm === "compose") && ( scheduleTypeForm === "compose") && (
<> <>
<FormField <FormField
control={form.control} control={form.control}
name="shellType" name="shellType"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel className="flex items-center gap-2"> <FormLabel className="flex items-center gap-2">
Shell Type Shell Type
</FormLabel> </FormLabel>
<Select <Select
onValueChange={field.onChange} onValueChange={field.onChange}
defaultValue={field.value} defaultValue={field.value}
> >
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select shell type" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="bash">Bash</SelectItem>
<SelectItem value="sh">Sh</SelectItem>
</SelectContent>
</Select>
<FormDescription>
Choose the shell to execute your command
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="command"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-2">
Command
</FormLabel>
<FormControl> <FormControl>
<SelectTrigger> <Input placeholder="npm run backup" {...field} />
<SelectValue placeholder="Select shell type" />
</SelectTrigger>
</FormControl> </FormControl>
<SelectContent> <FormDescription>
<SelectItem value="bash">Bash</SelectItem> The command to execute in your container
<SelectItem value="sh">Sh</SelectItem> </FormDescription>
</SelectContent> <FormMessage />
</Select> </FormItem>
<FormDescription> )}
Choose the shell to execute your command />
</FormDescription> </>
<FormMessage /> )}
</FormItem>
)}
/>
<FormField
control={form.control}
name="command"
render={({ field }) => (
<FormItem>
<FormLabel className="flex items-center gap-2">
Command
</FormLabel>
<FormControl>
<Input placeholder="npm run backup" {...field} />
</FormControl>
<FormDescription>
The command to execute in your container
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</>
)}
{(scheduleTypeForm === "dokploy-server" || {(scheduleTypeForm === "dokploy-server" ||
scheduleTypeForm === "server") && ( scheduleTypeForm === "server") && (
<FormField <FormField
control={form.control} control={form.control}
name="script" name="script"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>Script</FormLabel> <FormLabel>Script</FormLabel>
<FormControl>
<FormControl> <FormControl>
<CodeEditor <FormControl>
language="shell" <CodeEditor
placeholder={`# This is a comment language="shell"
placeholder={`# This is a comment
echo "Hello, world!" echo "Hello, world!"
`} `}
className="h-96 font-mono" className="h-96 font-mono"
{...field} {...field}
/> />
</FormControl>
</FormControl> </FormControl>
</FormControl> <FormMessage />
<FormMessage /> </FormItem>
</FormItem> )}
)} />
/> )}
)}
<FormField <FormField
control={form.control} control={form.control}
+34 -19
View File
@@ -1,16 +1,25 @@
import { cn } from "@/lib/utils";
import * as DialogPrimitive from "@radix-ui/react-dialog"; import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react"; import { X } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@/lib/utils";
const DialogContext = React.createContext<{ const DialogContext = React.createContext<{
onOpenChange?: (open: boolean) => void; onOpenChange?: (open: boolean) => void;
open?: boolean; open?: boolean;
}>({}); }>({});
const Dialog = ({ onOpenChange, open, ...props }: React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root>) => ( const Dialog = ({
onOpenChange,
open,
...props
}: React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root>) => (
<DialogContext.Provider value={{ onOpenChange, open }}> <DialogContext.Provider value={{ onOpenChange, open }}>
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange} {...props} modal={false}/> <DialogPrimitive.Root
open={open}
onOpenChange={onOpenChange}
{...props}
modal={false}
/>
</DialogContext.Provider> </DialogContext.Provider>
); );
Dialog.displayName = DialogPrimitive.Root.displayName; Dialog.displayName = DialogPrimitive.Root.displayName;
@@ -46,12 +55,13 @@ const DialogContent = React.forwardRef<
React.useEffect(() => { React.useEffect(() => {
if (!open) return; if (!open) return;
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; const scrollbarWidth =
window.innerWidth - document.documentElement.clientWidth;
const body = document.body; const body = document.body;
const originalPaddingRight = body.style.paddingRight; const originalPaddingRight = body.style.paddingRight;
const originalOverflow = body.style.overflow; const originalOverflow = body.style.overflow;
body.style.overflow = 'hidden'; body.style.overflow = "hidden";
if (scrollbarWidth > 0) { if (scrollbarWidth > 0) {
body.style.paddingRight = `${scrollbarWidth}px`; body.style.paddingRight = `${scrollbarWidth}px`;
} }
@@ -63,21 +73,24 @@ const DialogContent = React.forwardRef<
}, [open]); }, [open]);
// Handle outside interactions properly with Command components // Handle outside interactions properly with Command components
const handleInteractOutside = React.useCallback((e: Event) => { const handleInteractOutside = React.useCallback(
if (onOpenChange) { (_e: Event) => {
onOpenChange(false); if (onOpenChange) {
} onOpenChange(false);
}, [onOpenChange]); }
},
[onOpenChange],
);
const hasPaddingOverride = className?.includes("p-0"); const hasPaddingOverride = className?.includes("p-0");
// Separate DialogFooter from other children for proper layout // Separate DialogFooter from other children for proper layout
const childrenArray = React.Children.toArray(children); const childrenArray = React.Children.toArray(children);
const dialogFooter = childrenArray.find((child) => const dialogFooter = childrenArray.find(
React.isValidElement(child) && child.type === DialogFooter (child) => React.isValidElement(child) && child.type === DialogFooter,
); );
const otherChildren = childrenArray.filter((child) => const otherChildren = childrenArray.filter(
!(React.isValidElement(child) && child.type === DialogFooter) (child) => !(React.isValidElement(child) && child.type === DialogFooter),
); );
return ( return (
@@ -94,9 +107,11 @@ const DialogContent = React.forwardRef<
onInteractOutside={(e) => { onInteractOutside={(e) => {
const target = e.target as HTMLElement; const target = e.target as HTMLElement;
// Don't close when clicking inside popovers, dropdowns, or command components // Don't close when clicking inside popovers, dropdowns, or command components
if (target.closest('[data-radix-popper-content-wrapper]') || if (
target.closest('[cmdk-root]') || target.closest("[data-radix-popper-content-wrapper]") ||
target.closest('[data-radix-command-root]')) { target.closest("[cmdk-root]") ||
target.closest("[data-radix-command-root]")
) {
e.preventDefault(); e.preventDefault();
return; return;
} }
@@ -109,7 +124,7 @@ const DialogContent = React.forwardRef<
ref={contentRef} ref={contentRef}
className={cn( className={cn(
"overflow-y-auto overflow-x-hidden flex-1 min-h-0 overscroll-contain", "overflow-y-auto overflow-x-hidden flex-1 min-h-0 overscroll-contain",
!hasPaddingOverride && "p-6" !hasPaddingOverride && "p-6",
)} )}
> >
{otherChildren} {otherChildren}
@@ -138,7 +153,7 @@ const DialogHeader = ({
}: React.HTMLAttributes<HTMLDivElement>) => ( }: React.HTMLAttributes<HTMLDivElement>) => (
<div <div
className={cn( className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left", "flex flex-col space-y-1.5 text-center sm:text-left pb-4",
className, className,
)} )}
{...props} {...props}