chore: update with the last step - workflow component

This commit is contained in:
Pablo Lara
2024-11-03 10:39:10 +01:00
parent 4a3b767002
commit ff9d5442ab
3 changed files with 47 additions and 5 deletions
@@ -4,7 +4,7 @@ import React from "react";
import { TestConnectionForm } from "@/components/providers/workflow/forms";
interface Props {
searchParams: { id: string };
searchParams: { type: string; id: string };
}
export default function TestConnectionPage({ searchParams }: Props) {
@@ -3,12 +3,13 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { Icon } from "@iconify/react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
// import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { checkConnectionProvider } from "@/actions/providers/providers";
import { getTask } from "@/actions/task/tasks";
import { SaveIcon } from "@/components/icons";
import { useToast } from "@/components/ui";
import { CustomButton } from "@/components/ui/custom";
@@ -20,13 +21,19 @@ type FormValues = z.infer<typeof testConnectionFormSchema>;
export const TestConnectionForm = ({
searchParams,
}: {
searchParams: { id: string };
searchParams: { type: string; id: string };
}) => {
const { toast } = useToast();
const router = useRouter();
const providerType = searchParams.type;
const providerId = searchParams.id;
const formSchema = testConnectionFormSchema;
const [apiErrorMessage, setApiErrorMessage] = useState<string | null>(null);
const [connectionStatus, setConnectionStatus] = useState<{
connected: boolean;
error: string | null;
} | null>(null);
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
@@ -62,7 +69,25 @@ export const TestConnectionForm = ({
});
} else {
console.log({ data: data.data.id }, "success");
const taskId = data.data.id;
setApiErrorMessage(null);
const task = await getTask(taskId);
console.log({ task }, "task");
const connected = task.data.attributes.result.connected;
const error = task.data.attributes.result.error;
setConnectionStatus({
connected,
error,
});
if (connected) {
router.push(
`/providers/launch-scan?type=${providerType}&id=${providerId}&connected=${connected}`,
);
}
}
};
@@ -87,6 +112,22 @@ export const TestConnectionForm = ({
</div>
)}
{connectionStatus && !connectionStatus.connected && (
<div className="flex items-center gap-4 rounded-lg border border-red-200 bg-red-50 p-4">
<div className="flex items-center">
<Icon
icon="heroicons:exclamation-circle"
className="h-5 w-5 text-red-500"
/>
</div>
<div className="flex items-center">
<p className="text-red-700">
{connectionStatus.error || "Unknown error"}
</p>
</div>
</div>
)}
<input type="hidden" name="providerId" value={providerId} />
<div className="flex w-full justify-end sm:space-x-6">
+3 -2
View File
@@ -26,8 +26,9 @@ const steps = [
},
{
title: "Launch scan",
description: "Choose when you want to launch your scan.",
href: "/providers",
description:
"Launch the scan now or schedule it for a later date and time.",
href: "/providers/launch-scan",
},
];