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-10-14 08:50:03 -07:00
|
|
|
import { useLocation, useParams } from "react-router-dom";
|
2024-05-20 08:27:36 -07:00
|
|
|
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-10-14 08:50:03 -07:00
|
|
|
import { TaskGenerationApiResponse, WorkflowParameter } from "@/api/types";
|
2024-10-15 07:39:31 -07:00
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
2024-05-20 08:27:36 -07:00
|
|
|
|
|
|
|
|
function CreateNewTaskFormPage() {
|
|
|
|
|
const { template } = useParams();
|
|
|
|
|
const credentialGetter = useCredentialGetter();
|
2024-10-14 08:50:03 -07:00
|
|
|
const location = useLocation();
|
2024-05-20 08:27:36 -07:00
|
|
|
|
|
|
|
|
const { data, isFetching } = useQuery({
|
2024-07-11 03:08:52 -07:00
|
|
|
queryKey: ["savedTask", template],
|
2024-05-20 08:27:36 -07:00
|
|
|
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>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 08:50:03 -07:00
|
|
|
if (template === "from-prompt") {
|
|
|
|
|
const data = location.state?.data as TaskGenerationApiResponse;
|
|
|
|
|
if (!data.url) {
|
|
|
|
|
return <div>Something went wrong, please try again</div>; // this should never happen
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h1 className="text-3xl">Create New Task</h1>
|
|
|
|
|
</header>
|
|
|
|
|
<CreateNewTaskForm
|
|
|
|
|
key={template}
|
|
|
|
|
initialValues={{
|
|
|
|
|
url: data.url,
|
|
|
|
|
navigationGoal: data.navigation_goal,
|
|
|
|
|
dataExtractionGoal: data.data_extraction_goal,
|
|
|
|
|
navigationPayload:
|
|
|
|
|
typeof data.navigation_payload === "string"
|
|
|
|
|
? data.navigation_payload
|
|
|
|
|
: JSON.stringify(data.navigation_payload, null, 2),
|
|
|
|
|
extractedInformationSchema: JSON.stringify(
|
|
|
|
|
data.extracted_information_schema,
|
|
|
|
|
null,
|
|
|
|
|
2,
|
|
|
|
|
),
|
|
|
|
|
errorCodeMapping: null,
|
|
|
|
|
totpIdentifier: null,
|
|
|
|
|
totpVerificationUrl: null,
|
|
|
|
|
webhookCallbackUrl: null,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 08:27:36 -07:00
|
|
|
if (sampleCases.includes(template as SampleCase)) {
|
|
|
|
|
return (
|
2024-10-02 08:27:33 -07:00
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h1 className="text-3xl">Create New Task</h1>
|
|
|
|
|
</header>
|
|
|
|
|
<CreateNewTaskForm
|
|
|
|
|
key={template}
|
|
|
|
|
initialValues={getSampleForInitialFormValues(template as SampleCase)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-05-20 08:27:36 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isFetching) {
|
2024-10-15 07:39:31 -07:00
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h1 className="text-3xl">Edit Task Template</h1>
|
|
|
|
|
</header>
|
|
|
|
|
<Skeleton className="h-96" />
|
|
|
|
|
<Skeleton className="h-20" />
|
|
|
|
|
<Skeleton className="h-20" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2024-05-20 08:27:36 -07:00
|
|
|
}
|
|
|
|
|
|
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-09-30 09:08:27 -07:00
|
|
|
const errorCodeMapping =
|
|
|
|
|
data.workflow_definition.blocks[0].error_code_mapping;
|
2024-06-19 23:14:10 +03:00
|
|
|
|
2024-09-30 09:08:27 -07:00
|
|
|
const maxStepsOverride = data.workflow_definition.blocks[0].max_steps_per_run;
|
2024-06-21 13:08:00 -07:00
|
|
|
|
2024-05-20 08:27:36 -07:00
|
|
|
return (
|
2024-10-02 08:27:33 -07:00
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h1 className="text-3xl">Edit Task Template</h1>
|
|
|
|
|
</header>
|
|
|
|
|
<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,
|
|
|
|
|
extractedInformationSchema: JSON.stringify(dataSchema, null, 2),
|
|
|
|
|
navigationPayload,
|
|
|
|
|
maxStepsOverride,
|
|
|
|
|
totpIdentifier: data.workflow_definition.blocks[0].totp_identifier,
|
|
|
|
|
totpVerificationUrl:
|
|
|
|
|
data.workflow_definition.blocks[0].totp_verification_url,
|
|
|
|
|
errorCodeMapping: JSON.stringify(errorCodeMapping, null, 2),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-05-20 08:27:36 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { CreateNewTaskFormPage };
|