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 - - {