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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 584x 10x 10x 584x 584x 24x 24x 584x 22x 22x 584x 22x 584x 584x 1x 584x 1x 1x 584x 584x 584x 1x 584x 584x 899x 584x 584x 584x 584x 584x 1x 1x 584x 584x 584x | import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { useMerchantDataPreview } from "@components/Merchants/MerchantPreview/hooks/useMerchantDataPreview";
import { useMasquerade, useWatchlist } from "@hooks/enterprise-api/merchants";
import { IButtonComponent } from "@shared/SidePanel/SidePanelAtoms";
import { checkPortals } from "@utils/routing";
import { useConversationsModal } from "features/Minibuilders/Conversations/hooks/useConversationsModal";
import ChangelogButton from "../components/ChangelogButton";
import ConversationsButton from "../components/ConversationsButton";
import { useNotifications } from "../WithRepository/Challenges/hooks/useNotifications";
import { MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS } from "@shared/SidePanel/GiveSidePanel";
import { useMediaQuery } from "@mui/material";
import { useListTopics } from "features/Minibuilders/Conversations/hooks/useListTopics";
import { calculateTotalUnreadSum } from "features/Minibuilders/Conversations/utils/functions";
import NiceModal from "@ebay/nice-modal-react";
import {
CONVERSATION_MODAL,
DELETE_MERCHANT_MODAL,
ENTERPRISE_CONFIGURATION_MODAL,
} from "modals/modal_names";
import { useAppDispatch } from "@redux/hooks";
import { resetConversationsState } from "@redux/slices/conversations";
import { useState } from "react";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { useOpenGiveConversation } from "@features/GiveConversation/hooks/useOpenGiveConversation";
import { getCounterVariant } from "@features/GiveConversation/utils";
import { useNavigate } from "react-router-dom";
import { Role } from "@hooks/common/useUser/types";
import useOpenGiveNotification from "@features/GiveNotificationModal/hooks/useOpenGiveNotification";
import { useChangelogModal } from "@features/ChangeLog/hooks/useChanglelogModal";
import { TTransaction } from "@features/TransactionPanel/types";
import { CUSTOM_SECOND_PANEL_WIDTH } from "../constants";
import { endpointNames } from "@shared/GiveFilter/constants";
import { formatObjectArrayFilter } from "@shared/GiveFilter/utils";
import { useGetCurrentMerchantId } from "@hooks/common";
export type TMerchantDoublePanelNew =
| "merchantFile"
| "agreement"
| "underwriting"
| "riskExport"
| "customer"
| "transactionRiskProfile"
| "provider"
| "merchant"
| "transaction"
| "riskFilter"
| "";
type Props = {
id: number;
setSelectedRow?: (newIdx: string | number) => void;
onCloseCallback?: () => void;
setProviderID: (id: number | null) => void;
};
export default function useMerchantSidePanel({
id,
setSelectedRow,
onCloseCallback,
setProviderID,
}: Props) {
const { open, onClose } = useNiceModal();
const navigate = useNavigate();
const { handleOpenConversation, open: isOpenConvModal } =
useOpenGiveConversation();
const { isOpen: isOpenChangelogModal, handleOpenChangelogModal } =
useChangelogModal();
// This firstPanelContent state is mainly used for showing content details in the first panel
const [firstPanelContent, setFirstPanelContent] = useState("");
const [secondPanelContent, setSecondPanelContent] =
useState<TMerchantDoublePanelNew>("");
const [transactionRiskProfile, setTransactionRiskProfile] =
useState<TTransaction | null>(null);
const [transactionCounts, setTransactionCounts] = useState({
total: 0,
filtered: 0,
});
const { isAcquirerPortal } = checkPortals();
const {
data,
merchant,
isLoading,
isMerchantFileLoading,
isRefetching,
queries,
loadNextFilesPage,
} = useMerchantDataPreview({
id,
isMerchantFileOpen: secondPanelContent === "merchantFile",
isAgreementOpen: secondPanelContent === "agreement",
});
const { masqueradeHandler } = useMasquerade();
const isSinglePanelSize = useMediaQuery(
`(max-width:${MIN_ALLOWED_SCREEN_SIZE_FOR_DOUBLE_PANELS}px)`,
);
const [contentHistory, setContentHistory] = useState<string>("");
const [secondPanelContentHistory, setSecondPanelContentHistory] =
useState<TMerchantDoublePanelNew>("");
const { addMerchantToWatchlist, removeMerchantFromWatchlist } =
useWatchlist();
const { isOpen, handleOpenConversationsModal } = useConversationsModal();
const { closeNotifyMerchantModal } = useNotifications({
merchantID: id,
statusName: data?.status.statusName,
});
const isCollapsed = contentHistory !== "" && firstPanelContent === "";
const isDoublePanel =
!!secondPanelContent && !isSinglePanelSize && !isCollapsed;
const dispatch = useAppDispatch();
const { isSponsor } = useGetCurrentMerchantId();
const { handleClose: closeNotificationModal } = useOpenGiveNotification();
const { data: topicData } = useListTopics({ merchantId: merchant?.accID });
const { totalUnread } = calculateTotalUnreadSum(topicData?.data);
const { isNewConversationsEnabled } = useGetFeatureFlagValues();
const isProvider = merchant?.type === "enterprise";
const openConv = (open?: boolean) => {
Iif (isNewConversationsEnabled)
handleOpenConversation({
merchantData: {
id,
},
});
else handleOpenConversationsModal(open);
};
const Buttons: IButtonComponent = {
conversations: (
<ConversationsButton
isLoading={isLoading}
totalUnread={
isNewConversationsEnabled
? data?.conversationStats?.totalUnreadMessages || 0
: totalUnread
}
isOpen={isOpen || isOpenConvModal}
handleOpenConversationsModal={openConv}
isDoublePanel={isDoublePanel}
counterVariant={getCounterVariant({
isMentioned: !!data?.conversationStats?.isMentioned,
unreadMessagesCount:
data?.conversationStats?.totalUnreadMessages || 0,
didMerchantReply: !!data?.conversationStats?.didMerchantReply,
})}
secondPanelWidth={
secondPanelContent
? CUSTOM_SECOND_PANEL_WIDTH[secondPanelContent]
: undefined
}
/>
),
changelog: (
<ChangelogButton
isOpen={isOpen || isOpenChangelogModal}
handleOpenChangelogModal={handleOpenChangelogModal}
isDoublePanel={isDoublePanel}
isLoadingConversation={isOpenConvModal}
isOpenConversations={isOpenConvModal}
secondPanelWidth={
secondPanelContent
? CUSTOM_SECOND_PANEL_WIDTH[secondPanelContent]
: undefined
}
/>
),
};
const handleSecondPanel = (option: TMerchantDoublePanelNew) => {
Iif (["merchant", "provider"].includes(secondPanelContent)) {
setFirstPanelContent("");
}
setSecondPanelContent(option);
};
const handleExtendedNavigation = (option: "merchantFile" | "agreement") => {
// If we're opening from provider/merchant second panel, move it to first panel and save history
Iif (["merchant", "provider"].includes(secondPanelContent)) {
setFirstPanelContent(secondPanelContent);
// Save current second panel content as history
setSecondPanelContentHistory(secondPanelContent);
// If we came from transaction, save that to contentHistory
if (firstPanelContent === "transaction") {
setContentHistory("transaction");
}
setSecondPanelContent(option);
} else {
handleSecondPanel(option);
}
};
const handleOpenMerchantFile = () => {
handleExtendedNavigation("merchantFile");
};
const handleOpenAgreementSnapshot = () => {
handleExtendedNavigation("agreement");
};
const handleOpenUnderwriting = () => {
handleSecondPanel("underwriting");
};
const handleOpenRiskExport = () => {
handleSecondPanel("riskExport");
setProviderID(null);
};
const handleOpenCustomer = () => {
handleSecondPanel("customer");
setProviderID(null);
};
const handleOpenTransactionRiskProfile = (
riskProfile: TTransaction | null,
) => {
setSecondPanelContent(riskProfile ? "transactionRiskProfile" : "");
setTransactionRiskProfile(riskProfile);
};
const handleOpenRiskFilter = () => {
setSecondPanelContent("riskFilter");
};
const handleLoadNextMerchant = () => {
if (setSelectedRow) {
setSelectedRow("next");
NiceModal.remove(CONVERSATION_MODAL);
}
};
const handleLoadPrevMerchant = () => {
if (setSelectedRow) {
setSelectedRow("prev");
NiceModal.remove(CONVERSATION_MODAL);
}
};
const renderButton = (e: keyof IButtonComponent) => Buttons[e];
const handleControlMode = () => {
masqueradeHandler(
isAcquirerPortal ? "acquirer" : "provider",
{
...merchant,
nextRoute: isProvider ? "/provider" : "/merchant",
...(isProvider && {
origin: "/acquirer/providers",
role: Role.ENTERPRISE,
}),
},
() => {
NiceModal.remove(CONVERSATION_MODAL);
closeNotificationModal();
onClose();
},
);
};
const handleAddToWatchList = () => {
if (data.header.watchlist) {
removeMerchantFromWatchlist(id, data.header.name);
} else {
addMerchantToWatchlist(id, data.header.name);
}
};
const handleCloseAll = (isRedirecting = false) => {
onClose();
setContentHistory("");
setFirstPanelContent("");
setSecondPanelContent("");
setProviderID(null);
closeNotifyMerchantModal();
NiceModal.remove(CONVERSATION_MODAL);
// onCloseCallback reopens the previous modal if any, in redirection we dont want that, we just redirect
if (onCloseCallback && !isRedirecting) onCloseCallback();
};
const handleRedirectToMerchantsOfProvider = () => {
const parentNameFilter = [
{
id,
imageURL: merchant.imageURL || "",
label: merchant.name,
value: merchant.name,
},
];
const formattedFilterString = formatObjectArrayFilter({
array: parentNameFilter,
key: endpointNames.providerName,
});
handleClose(undefined, undefined, true);
// Pass navigation state with filter data and tab info
// Filter will be set in MerchantsTable useEffect after tab is set and cleanup runs
navigate("acquirer/merchants", {
state: {
fromProvider: true,
shouldSetApprovedTab: isSponsor,
providerFilter: {
parentNameFilter,
formattedFilterString,
},
},
});
};
const handleOpenDeleteMerchantModal = () => {
const providerHasMerchants = (data.stats?.totalMerchants ?? 0) > 0;
NiceModal.show(DELETE_MERCHANT_MODAL, {
id: data.status.accID,
name: merchant.name,
providerHasMerchants,
customCb: providerHasMerchants
? handleRedirectToMerchantsOfProvider
: undefined,
type: isProvider ? "Provider" : "Merchant",
closeSidepanel: onClose,
});
};
const handleOpenProviderConfiguration = () => {
NiceModal.show(ENTERPRISE_CONFIGURATION_MODAL, { enterpriseId: id });
};
const handleClose = (
event?: any,
reason?: "backdropClick" | "escapeKeyDown",
isRedirecting = false,
) => {
if (secondPanelContent && !firstPanelContent && !reason && !isRedirecting) {
setContentHistory("default");
return;
}
if (firstPanelContent === "transaction" && !reason) {
setSecondPanelContent("transaction");
setFirstPanelContent("");
setContentHistory("");
setProviderID(null);
return;
}
dispatch(resetConversationsState());
handleCloseAll(isRedirecting);
};
return {
data,
merchant,
isLoading,
isMerchantFileLoading,
isRefetching,
open,
onClose: handleClose,
handleCloseAll,
renderButton,
contentHistory,
setContentHistory,
secondPanelContentHistory,
setSecondPanelContentHistory,
firstPanelContent,
setFirstPanelContent,
secondPanelContent,
setSecondPanelContent,
isSinglePanelSize,
queries,
transactionRiskProfile,
loadNextFilesPage,
transactionCounts,
handlers: {
handleOpenAgreementSnapshot,
handleOpenUnderwriting,
handleOpenMerchantFile,
handleOpenRiskExport,
handleOpenTransactionRiskProfile,
handleOpenRiskFilter,
handleNext: handleLoadNextMerchant,
handlePrevious: handleLoadPrevMerchant,
handleControlMode,
handleAddToWatchList,
handleOpenDeleteMerchantModal,
openConversation: openConv,
handleOpenProviderConfiguration,
handleRedirectToMerchantsOfProvider,
handleOpenCustomer,
setTransactionCounts,
},
};
}
|