2024-06-11 03:28:24 -07:00
|
|
|
import { getClient } from "@/api/AxiosClient";
|
|
|
|
|
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
2024-05-20 08:27:36 -07:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import { getSampleForInitialFormValues } from "../data/sampleTaskData";
|
|
|
|
|
import { SampleCase, sampleCases } from "../types";
|
2024-06-11 03:28:24 -07:00
|
|
|
import { CreateNewTaskForm } from "./CreateNewTaskForm";
|
2024-05-20 08:27:36 -07:00
|
|
|
import { SavedTaskForm } from "./SavedTaskForm";
|
2024-06-13 08:02:27 -07:00
|
|
|
import { WorkflowParameter } from "@/api/types";
|
2024-05-20 08:27:36 -07:00
|
|
|
|
|
|
|
|
function CreateNewTaskFormPage() {
|
|
|
|
|
const { template } = useParams();
|
|
|
|
|
const credentialGetter = useCredentialGetter();
|
|
|
|
|
|
|
|
|
|
const { data, isFetching } = useQuery({
|
|
|
|
|
queryKey: ["workflows", template],
|
|
|
|
|
queryFn: async () => {
|
|
|
|
|
const client = await getClient(credentialGetter);
|
|
|
|
|
return client
|
|
|
|
|
.get(`/workflows/${template}`)
|
|
|
|
|
.then((response) => response.data);
|
|
|
|
|
},
|
|
|
|
|
enabled: !!template && !sampleCases.includes(template as SampleCase),
|
2024-05-29 11:04:12 -07:00
|
|
|
refetchOnWindowFocus: false,
|
2024-06-03 21:35:33 +03:00
|
|
|
staleTime: Infinity,
|
2024-05-20 08:27:36 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!template) {
|
|
|
|
|
return <div>Invalid template</div>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sampleCases.includes(template as SampleCase)) {
|
|
|
|
|
return (
|
|
|
|
|
<CreateNewTaskForm
|
|
|
|
|
key={template}
|
|
|
|
|
initialValues={getSampleForInitialFormValues(template as SampleCase)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isFetching) {
|
|
|
|
|
return <div>Loading...</div>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 08:02:27 -07:00
|
|
|
const navigationPayload = data.workflow_definition.parameters.find(
|
|
|
|
|
(parameter: WorkflowParameter) => parameter.key === "navigation_payload",
|
|
|
|
|
).default_value;
|
|
|
|
|
|
2024-06-19 23:14:10 +03:00
|
|
|
const dataSchema = data.workflow_definition.blocks[0].data_schema;
|
|
|
|
|
|
2024-06-21 13:08:00 -07:00
|
|
|
const maxSteps = data.workflow_definition.blocks[0].max_steps_per_run;
|
|
|
|
|
|
2024-05-20 08:27:36 -07:00
|
|
|
return (
|
|
|
|
|
<SavedTaskForm
|
|
|
|
|
initialValues={{
|
|
|
|
|
title: data.title,
|
|
|
|
|
description: data.description,
|
|
|
|
|
webhookCallbackUrl: data.webhook_callback_url,
|
|
|
|
|
proxyLocation: data.proxy_location,
|
|
|
|
|
url: data.workflow_definition.blocks[0].url,
|
|
|
|
|
navigationGoal: data.workflow_definition.blocks[0].navigation_goal,
|
|
|
|
|
dataExtractionGoal:
|
|
|
|
|
data.workflow_definition.blocks[0].data_extraction_goal,
|
2024-06-19 23:14:10 +03:00
|
|
|
extractedInformationSchema: JSON.stringify(dataSchema, null, 2),
|
2024-06-13 08:02:27 -07:00
|
|
|
navigationPayload,
|
2024-06-21 13:08:00 -07:00
|
|
|
maxSteps,
|
2024-05-20 08:27:36 -07:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { CreateNewTaskFormPage };
|