All files / src/store/features/triggers/api getTriggerOptionsApi.ts

0% Statements 0/14
0% Branches 0/1
0% Functions 0/4
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                                                                             
import { GET_TRIGGER_OPTIONS } from "../../../../constants/index.ts";
import { apiSlice } from "../../../app/apiSlice.ts";
import { setCurrentWorkflowTriggerKey } from "../../workflow/workflowSlice.ts";
 
export const getTriggerOptionsApi = apiSlice.injectEndpoints({
  endpoints: (builder) => ({
    getTriggerOptions: builder.query<any, void>({
      query: () => ({
        url: GET_TRIGGER_OPTIONS,
        method: "POST",
        body: {
          connector_type_requests: [
            {
              connector_type: "SLACK",
            },
          ],
        },
      }),
      transformResponse: (response) => {
        Iif (response?.alert_ops_options?.comm_options?.workspaces?.length > 0)
          return response?.alert_ops_options?.comm_options?.workspaces[0];
        return [];
      },
      onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
        try {
          const { data } = await queryFulfilled;
          dispatch(
            setCurrentWorkflowTriggerKey({ key: "workflowId", value: data.id }),
          );
        } catch (error) {
          console.log(error);
        }
      },
    }),
  }),
});
 
export const { useGetTriggerOptionsQuery } = getTriggerOptionsApi;