All files / src/store/features/integrations/api getConnectorKeyOptionsApi.ts

46.66% Statements 7/15
0% Branches 0/2
20% Functions 1/5
46.66% Lines 7/15

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 391x 1x 1x 1x   1x 1x                                                         1x      
import { GET_CONNECTOR_OPTIONS } from "../../../../constants/index.ts";
import handleDefaultValues from "../../../../utils/integrations/handleDefaultValues.ts";
import { apiSlice } from "../../../app/apiSlice.ts";
import { setKeysOptions } from "../integrationsSlice.ts";
 
export const getConnectorKeyOptionsApi = apiSlice.injectEndpoints({
  endpoints: (builder) => ({
    getConnectorKeyOptions: builder.query<any, string>({
      query: (connectorType) => ({
        url: GET_CONNECTOR_OPTIONS,
        method: "POST",
        body: {
          connector_type: connectorType.toUpperCase(),
        },
      }),
      providesTags: ["Integrations"],
      transformResponse: (response: any) => {
        return response?.connector ?? [];
      },
      onQueryStarted: async (arg, { dispatch, queryFulfilled }) => {
        try {
          const { data } = await queryFulfilled;
          dispatch(setKeysOptions(data?.keys));
          data?.keys?.forEach((e) => {
            handleDefaultValues(e);
          });
        } catch (e) {
          console.log(e);
        }
      },
    }),
  }),
});
 
export const {
  useLazyGetConnectorKeyOptionsQuery,
  useGetConnectorKeyOptionsQuery,
} = getConnectorKeyOptionsApi;