All files / src/componentsV2/SideMenu/components/hooks useMerchantIdentityNotification.tsx

41.66% Statements 5/12
0% Branches 0/2
33.33% Functions 1/3
41.66% Lines 5/12

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              14x 14x   14x                 14x                           14x    
import { showMessage } from "@common/Toast";
import { useGetCurrentMerchantId } from "@hooks/common";
import { customInstance } from "@services/api";
import { useMutation, useQueryClient } from "react-query";
import { QKEY_GET_MERCHANT_BY_ID } from "@constants/queryKeys";
 
export function useMerchantIdentityNotification() {
  const queryClient = useQueryClient();
  const { merchantId } = useGetCurrentMerchantId();
 
  const { mutateAsync: readNotifiacationAsync, isLoading } = useMutation(
    (data: any) => {
      return customInstance({
        url: `/merchants/${merchantId}/profile/read-completation`,
        method: "PUT",
      });
    },
  );
 
  const handleCloseNotification = async (cb?: () => void) => {
    try {
      await readNotifiacationAsync({});
 
      await queryClient.invalidateQueries(QKEY_GET_MERCHANT_BY_ID);
 
      if (cb) {
        cb();
      }
    } catch (error) {
      showMessage("Error", "Sorry something went wrong");
    }
  };
 
  return { handleCloseNotification, isLoading };
}