Skyvern/skyvern-frontend/src/routes/schedules/useCreateOrgScheduleMutation.ts
Aaron Perez cfe01b0abe
Some checks failed
Build Skyvern SDK and publish to PyPI / run-ci (push) Blocked by required conditions
Build Skyvern SDK and publish to PyPI / build-sdk (push) Blocked by required conditions
Run tests and pre-commit / Run tests and pre-commit hooks (push) Failing after 6s
Auto Create GitHub Release on Version Change / check-version-change (push) Successful in 1m45s
Run tests and pre-commit / Frontend Lint and Build (push) Successful in 3m48s
Publish Fern Docs / run (push) Failing after 2m43s
Auto Create GitHub Release on Version Change / create-release (push) Has been skipped
Build Skyvern SDK and publish to PyPI / check-version-change (push) Successful in 3m14s
feat: add frontend schedule panel to workflow editor (#SKY-8184) (#5146)
2026-03-19 01:07:30 -07:00

47 lines
1.4 KiB
TypeScript

import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AxiosError } from "axios";
import { getClient } from "@/api/AxiosClient";
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { toast } from "@/components/ui/use-toast";
import type {
CreateScheduleRequest,
WorkflowScheduleResponse,
} from "@/routes/workflows/types/scheduleTypes";
type CreateOrgScheduleParams = {
workflowPermanentId: string;
request: CreateScheduleRequest;
};
function useCreateOrgScheduleMutation() {
const credentialGetter = useCredentialGetter();
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
workflowPermanentId,
request,
}: CreateOrgScheduleParams) => {
const client = await getClient(credentialGetter);
const response = await client.post<WorkflowScheduleResponse>(
`/workflows/${workflowPermanentId}/schedules`,
request,
);
return response.data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["organizationSchedules"] });
toast({ title: "Schedule created", variant: "success" });
},
onError: (error: AxiosError) => {
const detail = (error.response?.data as { detail?: string })?.detail;
toast({
title: "Failed to create schedule",
description: detail || error.message,
variant: "destructive",
});
},
});
}
export { useCreateOrgScheduleMutation };