From 819bb6ca147b67aa97889481e643b129ad5ce623 Mon Sep 17 00:00:00 2001 From: HarikrishnanD Date: Thu, 16 Oct 2025 12:17:45 +0530 Subject: [PATCH 1/2] fix(schedules): track loading state per scheduler --- .../application/schedules/show-schedules.tsx | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx index 3209b6e03..9cab9ed9e 100644 --- a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx +++ b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx @@ -7,6 +7,7 @@ import { Trash2, } from "lucide-react"; import { toast } from "sonner"; +import { useState } from "react"; import { DialogAction } from "@/components/shared/dialog-action"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; @@ -33,6 +34,7 @@ interface Props { } export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { + const [runningSchedules, setRunningSchedules] = useState>(new Set()); const { data: schedules, isLoading: isLoadingSchedules, @@ -46,15 +48,29 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { enabled: !!id, }, ); - const utils = api.useUtils(); - const { mutateAsync: deleteSchedule, isLoading: isDeleting } = api.schedule.delete.useMutation(); - - const { mutateAsync: runManually, isLoading } = + const { mutateAsync: runManually } = api.schedule.runManually.useMutation(); + const handleRunManually = async (scheduleId: string) => { + setRunningSchedules((prev) => new Set(prev).add(scheduleId)); + try { + await runManually({ scheduleId }); + toast.success("Schedule run successfully"); + await refetchSchedules(); + } catch { + toast.error("Error running schedule"); + } finally { + setRunningSchedules((prev) => { + const newSet = new Set(prev); + newSet.delete(scheduleId); + return newSet; + }); + } + }; + return ( @@ -67,7 +83,6 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { Schedule tasks to run automatically at specified intervals. - {schedules && schedules.length > 0 && ( )} @@ -75,7 +90,7 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { {isLoadingSchedules ? ( -
+
Loading scheduled tasks... @@ -141,7 +156,6 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { )}
-
{ serverId={serverId || undefined} > - @@ -160,37 +173,24 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { type="button" variant="ghost" size="icon" - isLoading={isLoading} - onClick={async () => { - toast.success("Schedule run successfully"); - - await runManually({ - scheduleId: schedule.scheduleId, - }) - .then(async () => { - await new Promise((resolve) => - setTimeout(resolve, 1500), - ); - refetchSchedules(); - }) - .catch(() => { - toast.error("Error running schedule"); - }); - }} + disabled={runningSchedules.has(schedule.scheduleId)} + onClick={() => handleRunManually(schedule.scheduleId)} > - + {runningSchedules.has(schedule.scheduleId) ? ( + + ) : ( + + )} Run Manual Schedule - - { From 6d52ab13a6f32d61def9461b2dea5a88a5bb58aa Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 16 Oct 2025 06:50:39 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- .../application/schedules/show-schedules.tsx | 11 +++++++---- .../dashboard/impersonation/impersonation-bar.tsx | 2 +- apps/dokploy/components/layouts/user-nav.tsx | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx index 9cab9ed9e..e87e953fd 100644 --- a/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx +++ b/apps/dokploy/components/dashboard/application/schedules/show-schedules.tsx @@ -34,7 +34,9 @@ interface Props { } export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { - const [runningSchedules, setRunningSchedules] = useState>(new Set()); + const [runningSchedules, setRunningSchedules] = useState>( + new Set(), + ); const { data: schedules, isLoading: isLoadingSchedules, @@ -51,8 +53,7 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { const utils = api.useUtils(); const { mutateAsync: deleteSchedule, isLoading: isDeleting } = api.schedule.delete.useMutation(); - const { mutateAsync: runManually } = - api.schedule.runManually.useMutation(); + const { mutateAsync: runManually } = api.schedule.runManually.useMutation(); const handleRunManually = async (scheduleId: string) => { setRunningSchedules((prev) => new Set(prev).add(scheduleId)); @@ -174,7 +175,9 @@ export const ShowSchedules = ({ id, scheduleType = "application" }: Props) => { variant="ghost" size="icon" disabled={runningSchedules.has(schedule.scheduleId)} - onClick={() => handleRunManually(schedule.scheduleId)} + onClick={() => + handleRunManually(schedule.scheduleId) + } > {runningSchedules.has(schedule.scheduleId) ? ( diff --git a/apps/dokploy/components/dashboard/impersonation/impersonation-bar.tsx b/apps/dokploy/components/dashboard/impersonation/impersonation-bar.tsx index a5aae598c..b96b7c866 100644 --- a/apps/dokploy/components/dashboard/impersonation/impersonation-bar.tsx +++ b/apps/dokploy/components/dashboard/impersonation/impersonation-bar.tsx @@ -281,7 +281,7 @@ export const ImpersonationBar = () => {
diff --git a/apps/dokploy/components/layouts/user-nav.tsx b/apps/dokploy/components/layouts/user-nav.tsx index ca5854196..337e8f483 100644 --- a/apps/dokploy/components/layouts/user-nav.tsx +++ b/apps/dokploy/components/layouts/user-nav.tsx @@ -44,7 +44,7 @@ export const UserNav = () => { >