All files / src/components/Buttons/TestConnectorButton index.tsx

0% Statements 0/14
0% Branches 0/8
0% Functions 0/3
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                                         
import React from "react";
import CustomButton from "../../common/CustomButton/index.tsx";
import { useSelector } from "react-redux";
import { connectorSelector } from "../../../store/features/integrations/integrationsSlice.ts";
import { useLazyTestConnectionQuery } from "../../../store/features/integrations/api/testConnectionApi.ts";
 
function TestConnectorButton({ id, connector, formData }) {
  const currentConnector = useSelector(connectorSelector);
  const [triggerTestConnection, { isFetching: testConnectionLoading }] =
    useLazyTestConnectionQuery();
  const keyOptions = connector?.keys ?? [];
 
  const handleClick = async () => {
    const formattedKeys: any = [];
    keyOptions?.forEach((e) => {
      formattedKeys.push({
        key_type: e.key_type,
        key: (formData[e.key_type] === "SSL_VERIFY"
          ? formData[e.key_type] !== ""
            ? formData[e.key_type]
            : false
          : formData[e.key_type]
        )?.toString(),
      });
    });
 
    await triggerTestConnection({
      type: connector.type,
      keys: formattedKeys,
      name: currentConnector.name,
      id: id,
    });
  };
 
  return (
    <>
      <CustomButton onClick={handleClick}>
        {testConnectionLoading ? "Checking connection..." : "Test Connection"}
      </CustomButton>
    </>
  );
}
 
export default TestConnectorButton;