All files / src/features/Merchants/MerchantSidePanel/ApprovalFlowPanel/hooks useEDDTaskMutations.tsx

54.54% Statements 6/11
0% Branches 0/4
25% Functions 1/4
54.54% Lines 6/11

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                  21x 2594x   2594x       2594x                   2594x                 2594x    
import { useMutation, useQueryClient } from "react-query";
import { customInstance } from "@services/api";
import { UNDERWRITING_CHALLENGE_API_KEYS } from "@features/Merchants/MerchantSidePanel/constants";
type TaskPayload = {
  id?: string | number;
  name: string;
  description?: string;
};
 
export const useEDDTaskMutations = ({ merchantId }: { merchantId: number }) => {
  const queryClient = useQueryClient();
 
  const invalidateTasks = () => {
    queryClient.invalidateQueries(UNDERWRITING_CHALLENGE_API_KEYS.GET_TASKS);
  };
 
  const upsertTask = useMutation(
    ({ id, ...data }: TaskPayload) => {
      const method = id ? "PATCH" : "POST";
      const url = `/merchants/${merchantId}/tasks${id ? `/${id}` : ""}`;
 
      return customInstance({ url, method, data });
    },
    { onSuccess: invalidateTasks },
  );
 
  const deleteTask = useMutation(
    (id: string | number) =>
      customInstance({
        url: `/merchants/${merchantId}/tasks/${id}`,
        method: "DELETE",
      }),
    { onSuccess: invalidateTasks },
  );
 
  return { upsertTask, deleteTask };
};