All files / src/features/GiveOnboarding mutations.ts

64.7% Statements 11/17
6.25% Branches 1/16
44.44% Functions 4/9
64.7% Lines 11/17

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                  9x         10x                                   10x     9x       3x             3x           3x     9x         13x                 9x         8x                
import { useMutation } from "react-query";
import { customInstance } from "@services/api";
import {
  convertPhoneNumber,
  toISODateString,
} from "@utils/date.helpers";
import { patchBusinessOwner } from "@services/api/business-owners";
import { createBusinessOwner } from "@services/api/business-owners";
 
export const useCreateBusinessProfileMutation = (
  merchantId: number,
  legalEntityID?: number,
  hasExistingTaxId?: boolean,
) => {
  const createBusinessProfileMutation = useMutation(({ DBA, ...data }: any) => {
    return customInstance({
      url:
        legalEntityID && !hasExistingTaxId
          ? `/merchants/${merchantId}/legal-entities/${legalEntityID}`
          : `/merchants/${merchantId}/legal-entities`,
      method: Boolean(legalEntityID) && !hasExistingTaxId ? "PATCH" : "POST",
      data: {
        ...data,
        doingBusinessAs: DBA,
        businessOpenedAt: toISODateString(data.businessOpenedAt as Date | string | null) ?? undefined,
        phoneNumber: data.phoneNumber
          ? convertPhoneNumber(data.phoneNumber)
          : undefined,
      },
    });
  });
 
  return createBusinessProfileMutation;
};
 
export const useCreateBusinesOwnerMutation = (
  merchantId: number,
  legalEntityID?: number,
) => {
  Iif (!legalEntityID)
    return {
      mutate: () => {
        return;
      },
    } as any;
 
  const createBusinessProfileMutation = useMutation((data: any) => {
    return data.id
      ? patchBusinessOwner(legalEntityID, data.id, data, merchantId)
      : createBusinessOwner(legalEntityID, data, merchantId);
  });
 
  return createBusinessProfileMutation;
};
 
export const usePatchBusinessDetailsMutation = ({
  merchantId,
}: {
  merchantId: number | string;
}) => {
  return useMutation((data: any) => {
    return customInstance({
      url: `/merchants/${merchantId}`,
      method: "PATCH",
      data,
    });
  });
};
 
export const useDeleteCompletedSteps = ({
  merchantId,
}: {
  merchantId: number | string;
}) => {
  return useMutation((data: any) => {
    return customInstance({
      url: `/merchants/${merchantId}/onboarding/steps`,
      method: "DELETE",
      data,
    });
  });
};