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 | 1x 6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x | import useRedirect from "@hooks/common/router/useRedirect";
import { getMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { useGetUser } from "@services/api/onboarding/user";
import {
MERCHANT_PREVIEW_PANEL_MODAL,
RESOURCE_NOT_FOUND,
} from "modals/modal_names";
import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";
export const useRedirectToMerchantPanel = () => {
const navigate = useNavigate();
const location = useLocation();
const { merchantData } = useGetUser();
const { redirectToModal } = useRedirect();
useEffect(() => {
Eif (merchantData) {
const path = "/acquirer/merchants";
const searchParams = new URLSearchParams(location.search);
const merchantId = searchParams.get("merchantId");
const section = searchParams.get("section");
const checkMerchantAccess = async (merchantId: string) => {
navigate(path);
try {
// If merchant is accessible to the current user we open sidepanel, otherwise show resource not found popup
await getMerchantById(merchantId);
redirectToModal(MERCHANT_PREVIEW_PANEL_MODAL, {
id: merchantId,
initialSection: section,
});
} catch (err) {
redirectToModal(RESOURCE_NOT_FOUND, {
title:
"This escalated activity is linked to a merchant you cannot view",
info: "You don’t have access to view this merchant's escalated activity, as it is not included in your merchant list. Please sign out of the current account and sign in to the appropriate account.",
styles: {
titleStyle: {
fontSize: "18px",
},
containerWidth: "648px",
},
});
}
};
Iif (merchantId) {
checkMerchantAccess(merchantId);
}
}
}, [merchantData, location.search]);
};
|