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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | 35x 35x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 99x 21x 99x 21x 99x 99x | import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import GiveSidePanel, {
MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS,
} from "@shared/SidePanel/GiveSidePanel";
import CustomerPanelContent from "features/MerchantPortal/Customer/Modals/CustomerPanelContent";
import { useEffect, useState } from "react";
import TransactionPanelContent from "./components/Summary/TransactionPanelContent";
import { TransactionStatus, TransactionType } from "./utils";
import { useAccessControl } from "@features/Permissions/AccessControl";
import RESOURCE_BASE, { OPERATIONS } from "@constants/permissions";
import { GiveWithMissingPermissionModule } from "@common/GiveWithMissingPermissionModule";
import { useMediaQuery } from "@mui/material";
import CollapseNavigation from "@features/Merchants/MerchantSidePanel/components/Collapse1stLevel/CollapseNavigation";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
QKEY_PROCESSING_LIST,
QKEY_PROVIDER_PROCESSING,
} from "@constants/queryKeys";
import { useQueryClient } from "react-query";
import { setCheckedTransaction } from "@services/api/products/transactions";
import { BaseTransactionModalProps, TransactionSidePanelType } from "./types";
import GiveRiskProfile from "@features/GiveRiskProfile";
import { checkPortals } from "@utils/routing";
const TRANSACTION_PANEL_WIDTH = 640;
const GiveTransactionPanel = ({
isFirst,
isLast,
setSelectedRow,
data,
secondPanelType = null,
}: BaseTransactionModalProps) => {
const [openPanelType, setOpenPanelType] =
useState<TransactionSidePanelType | null>(secondPanelType);
const { open, onRemove } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const isSinglePanelSize = useMediaQuery(
`(max-width:${MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS}px)`,
);
const [showFirstPanel, setShowFirstPanel] = useState(true);
const { isMerchantPortal, isManageMoney } = checkPortals();
const showManageMoneyTopCard = isMerchantPortal && isManageMoney;
const queryClient = useQueryClient();
const handleCloseSecondPanel = () => {
if (!showFirstPanel) {
onRemove();
setTimeout(() => {
setShowFirstPanel(true);
setOpenPanelType(null);
}, 300);
return;
}
setOpenPanelType(null);
setShowFirstPanel(true);
};
const isChargeback = data?.status === TransactionStatus.CHARGEBACK;
const isRefunded =
data?.status === TransactionStatus.REFUNDED ||
data?.transactionType === "refund";
const isTransfer = data?.displayType === TransactionStatus.MONEY_TRANSFER;
const isPreChargebackRefund =
data?.transactionType === TransactionType.PRE_CHARGEBACK_REFUND;
const merchantID =
!isChargeback && !isRefunded && !isPreChargebackRefund
? data?.destinationAccount?.id
: data?.sourceAccount?.id;
const isReadTransferAllowed = useAccessControl({
withPortal: true,
resource: RESOURCE_BASE.BANK_TRANSFER,
operation: OPERATIONS.READ,
});
const notAuthorizedTransfer = isTransfer ? !isReadTransferAllowed : false;
const onCloseFirstPanel = () => {
if (openPanelType) {
setShowFirstPanel(false);
return;
}
onRemove();
setOpenPanelType(null);
};
const showCollapseNavigation =
!isMobileView &&
((isSinglePanelSize && !!openPanelType) || !showFirstPanel);
useEffect(() => {
Iif (data?.isBlocked && !data?.firstCheckedAt) {
const read = async () => {
await setCheckedTransaction(merchantID, data.objID);
queryClient.invalidateQueries([QKEY_PROCESSING_LIST]);
queryClient.invalidateQueries([QKEY_PROVIDER_PROCESSING]);
};
read();
}
}, [data?.firstCheckedAt, data?.objID]);
useEffect(() => {
Iif (
secondPanelType !== undefined &&
secondPanelType !== openPanelType &&
isSinglePanelSize
) {
setOpenPanelType(null);
setShowFirstPanel(true);
}
}, [data?.objID]);
const handleBack = () => {
setShowFirstPanel(true);
isSinglePanelSize && setOpenPanelType(null);
};
return (
<GiveSidePanel
secondPanel={
openPanelType === "customer" ? (
<CustomerPanelContent
isFirst={isFirst}
isLast={isLast}
onClose={handleCloseSecondPanel}
data={data?.customer}
merchantID={merchantID}
/>
) : openPanelType === "risk" ? (
<GiveRiskProfile
isFirst={isFirst}
isLast={isLast}
setSelectedRow={setSelectedRow}
data={data}
onClose={handleCloseSecondPanel}
/>
) : null
}
isSecondPanelOpen={Boolean(openPanelType)}
isFirstPannelHidden={!showFirstPanel}
floatingContent={
showCollapseNavigation && (
<CollapseNavigation
show={showCollapseNavigation}
navigationOffSet={TRANSACTION_PANEL_WIDTH}
onBack={handleBack}
/>
)
}
open={open}
onClose={() => {
onRemove();
setOpenPanelType(null);
}}
data-testid="transaction-panel-rebranded"
width={TRANSACTION_PANEL_WIDTH}
>
<GiveWithMissingPermissionModule
sectionName="Transfer section"
notAuthorized={notAuthorizedTransfer}
>
{showFirstPanel ? (
<TransactionPanelContent
data={data}
isFirst={isFirst}
isLast={isLast}
handleCustomer={(open) =>
setOpenPanelType(open ? "customer" : null)
}
handleSidePanelOpen={(type: TransactionSidePanelType) =>
setOpenPanelType(type)
}
setSelectedRow={setSelectedRow}
open={open}
onClose={onCloseFirstPanel}
isManageMoney={showManageMoneyTopCard}
/>
) : (
<></>
)}
</GiveWithMissingPermissionModule>
</GiveSidePanel>
);
};
export default GiveTransactionPanel;
|