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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | 1x 1x | import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import NiceModal from "@ebay/nice-modal-react";
import CollapseNavigation from "@features/Merchants/MerchantSidePanel/components/Collapse1stLevel/CollapseNavigation";
import TransactionPanelContent from "@features/TransactionPanel/components/Summary/TransactionPanelContent";
import {
BaseTransactionModalProps,
TransactionSidePanelType,
} from "@features/TransactionPanel/types";
import { useMediaQuery } from "@mui/material";
import GiveSidePanel, {
MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS,
} from "@shared/SidePanel/GiveSidePanel";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useEffect, useMemo, useState } from "react";
import ManageMoneyPanelContent from "./components/ManageMoneyPanelContent";
import CustomerPanelContent from "@features/MerchantPortal/Customer/Modals/CustomerPanelContent";
import {
TransactionStatus,
TransactionType,
} from "@features/TransactionPanel/shared.types";
import GiveRiskProfile from "@features/GiveRiskProfile";
import { checkPortals } from "@utils/routing";
import { useTransactionHistory } from "@components/ManageMoney/TransactionTable/TransactionInfoModal/hooks";
const TRANSACTION_PANEL_WIDTH = 640;
export const ManageMoneyPanel = NiceModal.create(
({
isFirst,
isLast,
setSelectedRow,
data,
secondPanelType,
}: BaseTransactionModalProps) => {
const { open, onRemove } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const isSinglePanelSize = useMediaQuery(
`(max-width:${MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS}px)`,
);
const { isMerchantPortal, isManageMoney } = checkPortals();
const showManageMoneyTopCard = isMerchantPortal && isManageMoney;
// --- State ---
const [openPanelType, setOpenPanelType] =
useState<TransactionSidePanelType | null>(null);
const [firstPanelType, setFirstPanelType] = useState<
"manageMoney" | "transaction"
>("manageMoney");
const [showFirstPanel, setShowFirstPanel] = useState(true);
const isChargeback = data?.status === TransactionStatus.CHARGEBACK;
const isRefunded =
data?.status === TransactionStatus.REFUNDED ||
data?.transactionType === "refund";
const isPreChargebackRefund =
data?.transactionType === TransactionType.PRE_CHARGEBACK_REFUND;
const merchantID =
!isChargeback && !isRefunded && !isPreChargebackRefund
? data?.destinationAccount?.id
: data?.sourceAccount?.id;
const { isAnyPaymentForm } = checkPortals();
const transactionId = isAnyPaymentForm
? data?.transactionID
: data?.objID ?? data?.id;
const { displayedData, isLoading } = useTransactionHistory(
transactionId,
false,
data,
);
const resetToManageMoney = (panel?: TransactionSidePanelType | null) => {
setFirstPanelType("manageMoney");
setOpenPanelType(panel || null);
setShowFirstPanel(true);
};
const isTansactionModalOpen = [openPanelType, firstPanelType].includes(
"transaction",
);
useEffect(() => {
if (
secondPanelType !== undefined &&
secondPanelType !== openPanelType &&
isSinglePanelSize
) {
resetToManageMoney();
}
}, [data?.objID]);
const handleCloseSecondPanel = () => {
if (firstPanelType === "transaction") {
// When transaction is first, closing secondary panel restores transaction view
resetToManageMoney("transaction");
} else {
if (showFirstPanel) {
//only keep open if its already open
setOpenPanelType(null);
setShowFirstPanel(true);
} else onRemove();
}
};
const handleBack = () => {
if (firstPanelType === "transaction") {
resetToManageMoney();
} else if (firstPanelType === "manageMoney" && openPanelType) {
setShowFirstPanel(true);
}
};
const onCloseFirstPanel = () => {
if (firstPanelType === "transaction") {
resetToManageMoney();
return;
}
if (openPanelType) {
setShowFirstPanel(false);
return;
}
onRemove();
resetToManageMoney();
};
const handleSidePanelOpen = (type: TransactionSidePanelType | null) => {
switch (type) {
case "customer":
case "risk":
// Transaction becomes first, customer/risk becomes second
setFirstPanelType("transaction");
setOpenPanelType(type);
break;
case "transaction":
// ManageMoney as first, Transaction as second
setFirstPanelType("manageMoney");
setShowFirstPanel(true);
setOpenPanelType("transaction");
break;
case "manageMoney":
case null:
default:
// Reset to base view
resetToManageMoney();
break;
}
};
const secondPanel = useMemo(() => {
switch (openPanelType) {
case "transaction":
return (
<TransactionPanelContent
data={data}
isFirst={isFirst}
isLast={isLast}
handleCustomer={(open) =>
handleSidePanelOpen(open ? "customer" : null)
}
handleSidePanelOpen={handleSidePanelOpen}
onClose={handleCloseSecondPanel}
noModal
open={isTansactionModalOpen}
/>
);
case "customer":
return (
<CustomerPanelContent
isFirst={isFirst}
isLast={isLast}
onClose={handleCloseSecondPanel}
data={data?.customer || displayedData?.customer}
merchantID={merchantID}
/>
);
case "risk":
return (
<GiveRiskProfile
isFirst={isFirst}
isLast={isLast}
data={data}
onClose={handleCloseSecondPanel}
/>
);
default:
return null;
}
}, [
openPanelType,
data,
isFirst,
isLast,
handleSidePanelOpen,
handleCloseSecondPanel,
merchantID,
]);
const showCollapseNavigation =
!isMobileView &&
((isSinglePanelSize && !!openPanelType) ||
!showFirstPanel ||
firstPanelType === "transaction");
const navigationOffset =
firstPanelType === "transaction"
? TRANSACTION_PANEL_WIDTH * 2
: TRANSACTION_PANEL_WIDTH;
return (
<GiveSidePanel
width={TRANSACTION_PANEL_WIDTH}
secondPanel={secondPanel}
isSecondPanelOpen={Boolean(openPanelType)}
isFirstPannelHidden={!showFirstPanel}
floatingContent={
showCollapseNavigation && (
<CollapseNavigation
show={showCollapseNavigation}
navigationOffSet={navigationOffset}
onBack={handleBack}
/>
)
}
open={open}
onClose={() => {
onRemove();
setOpenPanelType(null);
}}
data-testid="managemoney-panel-rebranded"
>
{showFirstPanel &&
(firstPanelType === "manageMoney" ? (
<ManageMoneyPanelContent
data={displayedData}
isFirst={isFirst}
isLast={isLast}
handleSidePanelOpen={handleSidePanelOpen}
setSelectedRow={setSelectedRow}
onClose={onCloseFirstPanel}
isManageMoney={true}
isLoading={isLoading}
/>
) : (
<TransactionPanelContent
data={data}
isFirst={isFirst}
isLast={isLast}
handleCustomer={(open) =>
handleSidePanelOpen(open ? "customer" : null)
}
handleSidePanelOpen={handleSidePanelOpen}
onClose={onCloseFirstPanel}
isManageMoney={showManageMoneyTopCard}
open={isTansactionModalOpen}
/>
))}
</GiveSidePanel>
);
},
);
|