(
workflowId: string | undefined,
blockId: string | undefined,
blockType: string,
options?: { timezone?: string }
)
| 136 | * Hook to get processed schedule info with human-readable timing |
| 137 | */ |
| 138 | export function useScheduleInfo( |
| 139 | workflowId: string | undefined, |
| 140 | blockId: string | undefined, |
| 141 | blockType: string, |
| 142 | options?: { timezone?: string } |
| 143 | ): { |
| 144 | scheduleInfo: ScheduleInfo | null |
| 145 | isLoading: boolean |
| 146 | refetch: () => void |
| 147 | } { |
| 148 | const isScheduleBlock = blockType === 'schedule' |
| 149 | |
| 150 | const { data, isLoading, refetch } = useScheduleQuery(workflowId, blockId, { |
| 151 | enabled: isScheduleBlock, |
| 152 | }) |
| 153 | |
| 154 | if (!data) { |
| 155 | return { scheduleInfo: null, isLoading, refetch } |
| 156 | } |
| 157 | |
| 158 | const timezone = options?.timezone || data.timezone || 'UTC' |
| 159 | const scheduleTiming = data.cronExpression |
| 160 | ? parseCronToHumanReadable(data.cronExpression, timezone) |
| 161 | : 'Unknown schedule' |
| 162 | |
| 163 | return { |
| 164 | scheduleInfo: { |
| 165 | id: data.id, |
| 166 | status: data.status, |
| 167 | scheduleTiming, |
| 168 | nextRunAt: data.nextRunAt, |
| 169 | lastRanAt: data.lastRanAt, |
| 170 | timezone, |
| 171 | isDisabled: data.status === 'disabled', |
| 172 | failedCount: data.failedCount || 0, |
| 173 | }, |
| 174 | isLoading, |
| 175 | refetch, |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Mutation to reactivate a disabled schedule |
no test coverage detected