From fafa14c10a7286ffbc58fe620950323ba622efd6 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Fri, 2 May 2025 16:00:05 -0600 Subject: [PATCH] Enhance schedule management with shell type selection - Added a new `shellType` field to the schedule form, allowing users to select between 'bash' and 'sh' for command execution. - Updated the `HandleSchedules` component to include the `shellType` in the form and reset logic. - Modified the `ShowSchedules` component to display the selected shell type for each schedule. - Ensured proper handling of the new field in the API for schedule creation and updates. --- .../schedules/handle-schedules.tsx | 60 +++++++++++++++---- .../application/schedules/show-schedules.tsx | 6 ++ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx b/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx index c5c4d47e..1d5cf080 100644 --- a/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx +++ b/apps/dokploy/components/dashboard/application/schedules/handle-schedules.tsx @@ -51,6 +51,7 @@ const commonCronExpressions = [ const formSchema = z.object({ name: z.string().min(1, "Name is required"), cronExpression: z.string().min(1, "Cron expression is required"), + shellType: z.enum(["bash", "sh"]).default("bash"), command: z.string().min(1, "Command is required"), enabled: z.boolean().default(true), }); @@ -68,6 +69,7 @@ export const HandleSchedules = ({ applicationId, scheduleId }: Props) => { defaultValues: { name: "", cronExpression: "", + shellType: "bash", command: "", enabled: true, }, @@ -79,25 +81,28 @@ export const HandleSchedules = ({ applicationId, scheduleId }: Props) => { ); useEffect(() => { - if (scheduleId) { + if (scheduleId && schedule) { form.reset({ - name: schedule?.name, - cronExpression: schedule?.cronExpression, - command: schedule?.command, - enabled: schedule?.enabled, + name: schedule.name, + cronExpression: schedule.cronExpression, + shellType: schedule.shellType, + command: schedule.command, + enabled: schedule.enabled, }); } - }, [form, form.reset, schedule]); + }, [form, schedule, scheduleId]); const { mutateAsync, isLoading } = scheduleId ? api.schedule.update.useMutation() : api.schedule.create.useMutation(); const onSubmit = async (values: z.infer) => { + if (!applicationId && !scheduleId) return; + await mutateAsync({ ...values, - ...(scheduleId && { scheduleId }), - ...(applicationId && { applicationId }), + scheduleId: scheduleId || "", + applicationId: applicationId || "", }) .then(() => { toast.success( @@ -120,19 +125,18 @@ export const HandleSchedules = ({ applicationId, scheduleId }: Props) => { ) : ( )} - {scheduleId} {scheduleId ? "Edit" : "Create"} Schedule @@ -214,6 +218,37 @@ export const HandleSchedules = ({ applicationId, scheduleId }: Props) => { )} /> + ( + + + + Shell Type + + + + Choose the shell to execute your command + + + + )} + /> + { )} /> +