diff --git a/components/providers/workflow/forms/test-connection-form.tsx b/components/providers/workflow/forms/test-connection-form.tsx index 2b2d085564..d8f4a1c46e 100644 --- a/components/providers/workflow/forms/test-connection-form.tsx +++ b/components/providers/workflow/forms/test-connection-form.tsx @@ -1,28 +1,32 @@ "use client"; import { zodResolver } from "@hookform/resolvers/zod"; +import { Icon } from "@iconify/react"; +import Link from "next/link"; +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 { SaveIcon } from "@/components/icons"; -// import { useToast } from "@/components/ui"; +import { useToast } from "@/components/ui"; import { CustomButton } from "@/components/ui/custom"; import { Form } from "@/components/ui/form"; -import { testConnectionFormSchema } from "@/types"; +import { ApiError, testConnectionFormSchema } from "@/types"; type FormValues = z.infer; + export const TestConnectionForm = ({ searchParams, }: { searchParams: { id: string }; }) => { - // const { toast } = useToast(); - // const router = useRouter(); + const { toast } = useToast(); const providerId = searchParams.id; const formSchema = testConnectionFormSchema; + const [apiErrorMessage, setApiErrorMessage] = useState(null); const form = useForm({ resolver: zodResolver(formSchema), @@ -41,36 +45,76 @@ export const TestConnectionForm = ({ const data = await checkConnectionProvider(formData); if (data?.errors && data.errors.length > 0) { - console.log({ data }, "error"); + data.errors.forEach((error: ApiError) => { + const errorMessage = error.detail; + + switch (errorMessage) { + case "Not found.": + setApiErrorMessage(errorMessage); + break; + default: + toast({ + variant: "destructive", + title: `Error ${error.status}`, + description: errorMessage, + }); + } + }); } else { - console.log({ data }, "success"); + console.log({ data: data.data.id }, "success"); + setApiErrorMessage(null); } }; + return (
- +
Test connection
- Please test the connection to the provider. + Please check the provider connection
+ {apiErrorMessage && ( +
+

{`Provider ID ${apiErrorMessage.toLowerCase()}. Please check and try again.`}

+
+ )} + + +
- } - > - {isLoading ? <>Loading : Connect account} - + {apiErrorMessage ? ( + + + Back to providers + + ) : ( + } + > + {isLoading ? <>Loading : Connect account} + + )}