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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | 10x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 387x 42x 41x 41x 41x 41x 41x 41x 41x 387x 377x 18x 4x 11x 344x 1161x 387x 4x 36x 4x 383x 10x 10x 809x 637x 172x 14x 158x 20x 138x 16x 122x 7x 115x 33x 82x | import { MouseEventHandler, useEffect, useState } from "react";
import { XIcon, DotsThreeVerticalIcon, PlusIcon } from "@phosphor-icons/react";
import { Stack } from "@mui/material";
import GiveMerchantTableActions from "@shared/MerchantsProviders/GiveMerchantTableActions";
import GiveExpandingSearch from "@shared/SearchBar/GiveExpandingSearch";
import { useAppDispatch, useAppSelector } from "@redux/hooks";
import NiceModal from "@ebay/nice-modal-react";
import {
GIVE_EXPORT_MODAL,
GIVE_MERCHANT_BULK_INVITE,
TABLE_FILTERS_MODAL,
} from "modals/modal_names";
import { useCreateMerchantActions } from "@components/AcquirerMerchants/hooks/useCreateMerchantActions";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { checkPortals } from "@utils/routing";
import {
selectedQueryString,
setFilters,
useTableFilters,
} from "@redux/slices/tableFilters";
import { useLocation } from "react-router-dom";
import { getSelectedFiltersAmount } from "@redux/slices/tableFilters";
import { useNavigate } from "react-router-dom";
import { selectMerchantTab } from "@redux/slices/enterprise/merchants";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import {
composePermission,
useAccessControl,
} from "features/Permissions/AccessControl";
import RESOURCE_BASE, {
ACTION_DENY_MESSAGE,
OPERATIONS,
} from "@constants/permissions";
import { getSelectedTab } from "features/Merchants/MerchantsTable/utils";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { ExportRecordsTotal } from "@common/Table/helpers";
import { useGetMerchantsTableColumns } from "features/Merchants/MerchantsTable/hooks/useGetMerchantsTableColumns";
import RiskLevelFilter from "features/Merchants/MerchantsTable/components/RiskLevelFilter";
import {
FilterPagesEnum,
FilterPageValuesTYpes,
} from "@shared/GiveFilter/constants";
import { useFilterButton } from "@shared/GiveFilter/hooks/useFilterButton";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { useEnterprisePermissions } from "@components/AcquirerEnterprises/CreateEnterprise/hooks/useEnterprisePermissions";
import ApprovalStateFilter from "@features/Merchants/MerchantsTable/components/ApprovalStateFilter";
import ContextualMenu from "@shared/ContextualMenu/ContextualMenu";
import {
Container,
ACTIONS,
MOBILE_ACTIONS_ICONS,
} from "@features/MerchantPortal/ManageMoney/ManageMoneyActions.atoms";
import { useIsMutating } from "react-query";
import GiveCircularProgress from "@shared/GiveCircularProgress";
import { useGetCurrentMerchantId } from "@hooks/common";
import { exportType } from "@shared/GiveExportModal/const";
import { useAsyncReconciliationExport } from "@hooks/exports/useAsyncReconciliationExport";
import { CompactTableActionsProps, CompactTableFilter } from "./Table.types";
type TMerchantActionsHandler = {
totalRows?: number | ExportRecordsTotal;
totalFilteredRows?: number;
handleSearchChange?: (value: string) => void;
search: string;
} & CompactTableActionsProps;
const MerchantActionsHandler = ({
totalRows = 0,
totalFilteredRows,
handleSearchChange,
search,
compact = false,
filters,
selectedTab,
handleCreate,
createLabel,
disableCreate,
}: TMerchantActionsHandler) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const { isCreateMerchantAllowed } = useCreateMerchantActions();
const { data, merchantId } = useGetMerchantById();
const { isAcquirerPortal, isEnterprisePortal } = checkPortals();
const filtersAmount = useAppSelector(getSelectedFiltersAmount);
const tab = useAppSelector(selectMerchantTab);
const navigate = useNavigate();
const { state, pathname } = useLocation();
const { resetTableFilters } = useTableFilters();
const { isMobileView, isNarrowView: showMobileActions } = useCustomThemeV2();
const isExporting = useIsMutating({ mutationKey: ["export-merchants"] }) > 0;
const { isSponsor } = useGetCurrentMerchantId();
// Mount the reconciliation export hook here (always rendered with the table) so that
// global polling resumes from sessionStorage if the page is refreshed mid-export.
useAsyncReconciliationExport();
//This is the FF what we are using for the new story where we integrating the new filter modal, isMerchantProcessorEnabled completes rebrand
const { isNewApprovalFlowEnabled, isMerchantProcessorEnabled } =
useGetFeatureFlagValues();
const { risk_monitoring } = useEnterprisePermissions();
const isRiskFilterHidden = isEnterprisePortal && !risk_monitoring;
const {
selectedTabStatus: {
isAllTabSelected,
isInvitedTabSelected,
isOnboardingSelected,
isSponsorTabSelected,
isRiskTabSelected,
isKYBSelected,
isUnderwritingTabSelected,
isApprovedTabSelected,
isPendingTabSelected,
},
} = useGetMerchantsTableColumns();
const isExportAllowed = useAccessControl({
resource: RESOURCE_BASE.MERCHANT,
operation: OPERATIONS.LIST,
});
const isSponsorExportAllowed = useAccessControl({
resource: composePermission(RESOURCE_BASE.MERCHANT, RESOURCE_BASE.SPONSOR),
operation: OPERATIONS.LIST,
});
const usedExportPermission = isSponsor
? isSponsorExportAllowed
: isExportAllowed;
const queryString = useAppSelector(selectedQueryString);
const dispatch = useAppDispatch();
const isProviderDisabled =
!(data?.statusName === "approved") && !isAcquirerPortal;
const isMerchantInvitesDisabled =
!isCreateMerchantAllowed || isProviderDisabled;
const currentTab = getSelectedTab(tab);
const isRebrandedFilterEnabled =
(isNewApprovalFlowEnabled &&
(isSponsorTabSelected ||
isKYBSelected ||
isUnderwritingTabSelected ||
isApprovedTabSelected ||
isPendingTabSelected)) ||
isMerchantProcessorEnabled;
//TODO cleanup
//hide the filter button based on the FF
const shouldHideFilterButton =
!isNewApprovalFlowEnabled && (isSponsorTabSelected || isKYBSelected);
const hiddenActions = {
invite:
isOnboardingSelected ||
isSponsorTabSelected ||
!(isAllTabSelected || isInvitedTabSelected),
filter:
isOnboardingSelected || isInvitedTabSelected || shouldHideFilterButton,
export: isOnboardingSelected || isInvitedTabSelected,
};
const selectedFilterPage = getSelectedFilterPage({
isKYBSelected,
isSponsorTabSelected,
isApprovedTabSelected,
isPendingTabSelected,
isRiskTabSelected,
isAllTabSelected,
});
const {
handleOpenFilterModal,
handleResetFilters: resetFiltersV2,
filtersAmount: buttonFiltersAmount,
} = useFilterButton({
filterPage: selectedFilterPage as FilterPageValuesTYpes,
});
//TODO CLEAN UP
const usedFilterAmount = isRebrandedFilterEnabled
? buttonFiltersAmount
: filtersAmount;
const filterLabel =
usedFilterAmount > 0 ? `Filters (${usedFilterAmount})` : "Filter";
const handleOpenInvitePanel = () => {
NiceModal.show(GIVE_MERCHANT_BULK_INVITE);
};
const handleOpenModal = () => {
// TODO: for now we are using the portfolio tab for all, we need to change this to all.
// But this might need a refactor which can cause regression if not handled properly
isRebrandedFilterEnabled
? //TODO FIX... for now aplied only on sponsor tab for testing porpose
handleOpenFilterModal()
: NiceModal.show(TABLE_FILTERS_MODAL, {
tab: isAllTabSelected ? "portfolio" : currentTab,
});
};
const handleResetFilters: MouseEventHandler = (e: any) => {
e.stopPropagation();
resetTableFilters();
if (isRebrandedFilterEnabled) resetFiltersV2(e);
};
const hasFilters = usedFilterAmount > 0;
const handleOpenPanel = () => {
NiceModal.show(GIVE_EXPORT_MODAL, {
fieldTypes: exportType.MERCHANT_TABLE,
merchantID: merchantId,
counts: {
total: totalRows,
filtered: totalFilteredRows,
},
tab: currentTab,
hasFilters,
});
};
const merchantActions = [
{
...ACTIONS.invite,
handleAction: handleOpenInvitePanel,
disabled: isMerchantInvitesDisabled,
hidden: hiddenActions.invite,
tooltipProps: {
title: isProviderDisabled
? "Your provider account must be approved before inviting merchants in bulk."
: "You don't have access to invite merchants in bulk.",
disableHoverListener: !isMerchantInvitesDisabled,
},
order: isMobileView ? 2 : 0,
},
{
...ACTIONS.filter,
label: filterLabel,
handleAction: handleOpenModal,
disabled: false,
hidden: hiddenActions.filter,
...(usedFilterAmount > 0 && {
endIcon: (
<GiveIconButton
Icon={XIcon}
size="extraSmall"
onClick={handleResetFilters}
/>
),
}),
order: isMobileView ? 0 : 1,
},
{
...ACTIONS.export,
handleAction: handleOpenPanel,
disabled: !usedExportPermission || isExporting,
hidden: hiddenActions.export,
tooltipProps: {
title: ACTION_DENY_MESSAGE,
disableHoverListener: usedExportPermission,
},
order: isMobileView ? 1 : 2,
endIcon: isExporting ? (
<GiveCircularProgress size={14} thickness={4} color={"inherit"} />
) : undefined,
},
];
useEffect(() => {
// The compact (scroll-revealed) banner mounts/unmounts as the user scrolls.
// Its unmount must NOT reset search/filters, otherwise triggering a search
// (which scrolls back to top and hides the compact banner) instantly clears
// the query. The always-mounted full banner owns the tab-change/unmount
// reset. See TRA013.
if (compact) return;
const isDefaultFilterActive = state && state?.filtersActive;
//Ensure default filter is only applied once
Iif (isDefaultFilterActive) {
navigate(pathname, { replace: true });
}
//Reset filters once component unmounts
return () => {
if (isRebrandedFilterEnabled) resetFiltersV2();
resetTableFilters(true);
handleSearchChange?.("");
dispatch(setFilters({ queryString: "" }));
};
}, [currentTab, compact]);
const LeftSideFilterWrapper: React.FC = () => {
switch (true) {
case isRiskTabSelected:
return <RiskLevelFilter isRiskTab />;
case isApprovedTabSelected && !isRiskFilterHidden:
return <RiskLevelFilter isRiskTab={false} />;
case isSponsorTabSelected:
return <ApprovalStateFilter />;
default:
return null;
}
};
const mobileActions = merchantActions.map((action) => ({
text: action.label,
IconRight: MOBILE_ACTIONS_ICONS[action.id],
onClick: () => {
action.handleAction();
},
hidden: !!action.hidden,
disabled: !!action.disabled,
}));
if (compact) {
const compactMenuOptions = [
...(handleCreate
? [
{
text: createLabel ?? "Add",
IconRight: PlusIcon,
disabled: disableCreate,
onClick: () => handleCreate(),
},
]
: []),
...mobileActions,
...((filters?.length ?? 0) > 0
? [{ type: "divider" as const, text: "" }]
: []),
...(filters ?? []).map((filter: CompactTableFilter) => ({
text: filter.label,
isSelected: filter.value === selectedTab,
disabled: filter.disabled,
hidden: filter.hidden,
onClick: () => filter.onClickItem?.(),
})),
];
return (
<Stack direction="row" alignItems="center" gap="8px">
<GiveExpandingSearch value={search} onChange={handleSearchChange} />
<GiveIconButton
Icon={DotsThreeVerticalIcon}
variant="ghost"
onClick={(e) => setAnchorEl(e.currentTarget)}
/>
<ContextualMenu
anchorEl={anchorEl}
options={compactMenuOptions}
handleClose={() => setAnchorEl(null)}
color="primary"
texture="solid"
/>
</Stack>
);
}
return (
<Container isMobileView={showMobileActions}>
<GiveMerchantTableActions
actions={merchantActions}
search={search}
onSearchChange={handleSearchChange}
searchOnEnter={true}
isAllActionsHidden={isOnboardingSelected || showMobileActions}
leftActions={LeftSideFilterWrapper}
{...(isOnboardingSelected || isRiskTabSelected
? {
sx: {
"& .MuiInputBase-root": {
margin: TAB_SEARCH_MARGINS[tab.replace("-", "")],
},
},
}
: {})}
/>
{showMobileActions && !isOnboardingSelected && (
<>
<GiveIconButton
Icon={DotsThreeVerticalIcon}
variant="ghost"
onClick={(e) => setAnchorEl(e.currentTarget)}
/>
<ContextualMenu
anchorEl={anchorEl}
options={mobileActions}
handleClose={() => setAnchorEl(null)}
color="primary"
texture="solid"
/>
</>
)}
</Container>
);
};
export default MerchantActionsHandler;
const TAB_SEARCH_MARGINS: { [x: string]: string } = {
onboarding: "1px 0px",
risk: "1px 0px",
sponsor: "1px 0px",
};
export const getSelectedFilterPage = ({
isKYBSelected,
isSponsorTabSelected,
isApprovedTabSelected,
isPendingTabSelected,
isAllTabSelected,
isRiskTabSelected,
isProvider,
}: {
isKYBSelected: boolean;
isSponsorTabSelected: boolean;
isApprovedTabSelected: boolean;
isPendingTabSelected: boolean;
isAllTabSelected?: boolean;
isRiskTabSelected?: boolean;
isProvider?: boolean;
}) => {
if (isAllTabSelected) {
return isProvider
? FilterPagesEnum.PROVIDER_ALL_TAB
: FilterPagesEnum.MERCHANT_ALL_TAB;
}
if (isKYBSelected) {
return isProvider
? FilterPagesEnum.PROVIDER_KYB_TAB
: FilterPagesEnum.MERCHANT_KYB_TAB;
}
if (isSponsorTabSelected) {
return FilterPagesEnum.MERCHANT_SPONSOR_TAB;
}
if (isApprovedTabSelected) {
return isProvider
? FilterPagesEnum.PROVIDER_APPROVED_TAB
: FilterPagesEnum.MERCHANT_APPROVED_TAB;
}
if (isPendingTabSelected) {
return FilterPagesEnum.MERCHANT_PENDING_TAB;
}
if (isRiskTabSelected) {
return FilterPagesEnum.MERCHANT_RISK_TAB;
}
return isProvider
? FilterPagesEnum.PROVIDER_UNDERWRITING_TAB
: FilterPagesEnum.MERCHANT_UNDERWRITING_TAB;
};
|