All files / src/componentsV2/Table MainInfo.tsx

64.86% Statements 24/37
80.26% Branches 61/76
33.33% Functions 4/12
62.85% Lines 22/35

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                                                                                                                      1636x 1636x   1636x 1636x   1636x 1636x   1636x   1636x   1636x 1636x     1636x   1636x                               1636x 1636x           1636x   1636x   1636x   1636x   1636x                     1636x                                                                                                                                                                                                                                                                                                                                                                 1636x           1636x                  
import { Box, Stack, StackProps } from "@mui/material";
import { stopEventPropagation } from "@utils/helpers";
import { ACTION_DENY_MESSAGE } from "@constants/permissions";
import useCheckSponsor from "@hooks/common/useCheckSponsor";
import {
  BookmarkSimpleIcon,
  ClockIcon,
  WarningIcon,
} from "@phosphor-icons/react";
import GiveCheckbox from "@shared/GiveCheckbox/GiveCheckbox";
import { GiveTooltipProps } from "@shared/Tooltip/GiveTooltip.types";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { CustomToolTip } from "./CustomTooltip";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import MainInfoImage from "./MainInfoImage";
import { ActionsComponent } from "./ActionsComponent";
import { MerchantData } from "@hooks/enterprise-api/account/types";
import { GiveThumbnailProps } from "@shared/Thumbnail/GiveThumbnail";
import { useBulkMarkMerchants } from "@components/AcquirerMerchants/hooks/useBulkMarkMerchants";
import CanManageMoney from "features/Merchants/MerchantsTable/components/CanManageMoney";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { useCallback, useState } from "react";
import { useGetMerchantsTableColumns } from "@features/Merchants/MerchantsTable/hooks/useGetMerchantsTableColumns";
 
import CounterChat from "./components/CounterChat";
import { getTaxIdFormat } from "@utils/index";
 
import { useConversationPermission } from "@features/GiveConversation/hooks/useConversationaPermission";
 
interface MainInfoProps extends StackProps {
  row: MerchantData;
  thumbnailType: GiveThumbnailProps["type"];
  disabled: boolean;
  isSponsorTable: boolean;
  removeFromWatchlistHandler?: VoidFunction;
  addToWatchlistHandler: VoidFunction;
  isAcquirerPortal?: boolean;
  badgeTooltipProps?: Omit<GiveTooltipProps, "children">;
  isWarnedMerchant?: boolean;
  isEnterpriseTable?: boolean;
  showCanManageMoney?: boolean;
}
 
function MainInfo({
  row,
  disabled,
  isSponsorTable,
  removeFromWatchlistHandler,
  addToWatchlistHandler,
  isAcquirerPortal = true,
  badgeTooltipProps,
  isWarnedMerchant,
  isEnterpriseTable = false,
  thumbnailType,
  showCanManageMoney,
  ...rest
}: MainInfoProps) {
  const { palette } = useAppTheme();
  const { isMobileView, isLargeTabletView, isWideView } = useCustomThemeV2();
  const { isMerchantStatusRefactorEnabled, isNewConversationsEnabled } =
    useGetFeatureFlagValues();
  const [parentTooltipOpen, setParentTooltipOpen] = useState(false);
  const { checkIfMerchantMarked, toggleMark, checkIfMerchantDisabled } =
    useBulkMarkMerchants();
  const { hasSponsorAccess } = useCheckSponsor();
 
  const { hasAccessToViewConversation } = useConversationPermission();
  const showCounterForMerchantListProviderPortal =
    (isNewConversationsEnabled || isAcquirerPortal) &&
    hasAccessToViewConversation;
  const handleWatchlist = (func?: VoidFunction) => {
    return stopEventPropagation(func);
  };
 
  const showForEnterprise = hasAccessToViewConversation;
 
  const watchlistActionProps = row.watchlist
    ? {
        label: "",
        title: disabled ? ACTION_DENY_MESSAGE : "Remove from watchlist",
        onClick: handleWatchlist(removeFromWatchlistHandler),
        icon: BookmarkSimpleIcon,
        disabled: disabled,
      }
    : {
        label: "",
        title: disabled ? ACTION_DENY_MESSAGE : "Add to watchlist",
        onClick: handleWatchlist(addToWatchlistHandler),
        icon: BookmarkSimpleIcon,
        disabled: disabled,
      };
 
  const merchantImage = row?.imageURL ? `${row.imageURL}/small` : "";
  const isSponsorDisabled = checkIfMerchantDisabled(
    (isMerchantStatusRefactorEnabled ? row?.stateName : row?.sponsorStatus) ||
      "",
  );
  const {
    selectedTabStatus: { isApprovedTabSelected, isAllTabSelected },
  } = useGetMerchantsTableColumns();
 
  const isOnApprovalDelay = row?.isOnApprovalDelay;
 
  const showTaxId = isApprovedTabSelected || isAllTabSelected || !isWideView;
 
  const showSubText = !isEnterpriseTable || showTaxId;
 
  const handleTooltipInteraction = useCallback(
    (action: "open" | "close", tooltipType: "parent" | "child") => {
      if (tooltipType === "parent") {
        setParentTooltipOpen(action === "open");
      } else if (tooltipType === "child" && action === "open") {
        setParentTooltipOpen(false);
      }
    },
    [],
  );
 
  return (
    <Wrapper {...rest} alignItems="center">
      <Left>
        {isSponsorTable ? (
          <CustomToolTip
            onClick={(e) => e.stopPropagation()}
            message={ACTION_DENY_MESSAGE}
            showToolTip={!hasSponsorAccess}
            placement={isMobileView ? "bottom" : "bottom-end"}
            customTooltipStyles={{
              "&.MuiStack-root": {
                width: "auto",
                marginRight: "8px",
                cursor: isSponsorDisabled ? "default" : "pointer",
              },
            }}
          >
            <GiveCheckbox
              size="medium"
              sx={{
                cursor: "pointer",
                "& .MuiCheckbox-root": {
                  pointerEvents: "auto",
                },
              }}
              onClick={(e) => e.stopPropagation()}
              onChange={(e) => {
                toggleMark({ id: row.accID, mark: e.target.checked, row });
              }}
              disabled={isSponsorDisabled}
              checked={checkIfMerchantMarked(row)}
            />
          </CustomToolTip>
        ) : (
          <ActionsComponent
            {...watchlistActionProps}
            data-testid="watchlist-btn"
          />
        )}
 
        <MainInfoImage
          src={merchantImage}
          unread={
            isNewConversationsEnabled
              ? row?.didMerchantReply || row?.didMerchantreply
              : row?.hasUnreadMessages || row?.hasUnrepliedActivityMessages
          }
          thumbnailType={thumbnailType}
          isOrange={row?.hasUnreadMentions}
          badgeTooltipProps={badgeTooltipProps}
          id={row.accID}
        />
 
        <Box sx={{ marginLeft: "10px", width: "100%" }}>
          <Stack
            direction="row"
            spacing={0.5}
            height="20px"
            width="100%"
            justifyContent={showCanManageMoney ? "space-between" : "flex-start"}
            alignItems="center"
          >
            <GiveTooltip
              disableHoverListener={
                !row.name ||
                isMobileView ||
                isLargeTabletView ||
                parentTooltipOpen === false
              }
              title={row.name}
              placement={isMobileView ? "bottom" : "top-start"}
              alignment="top"
              fluidWidth
            >
              <Stack
                direction="row"
                alignItems="center"
                width="100%"
                onMouseEnter={() => handleTooltipInteraction("open", "parent")}
                onMouseLeave={() => handleTooltipInteraction("close", "parent")}
              >
                <GiveTruncateText
                  variant="bodyS"
                  lineClamp={1}
                  sx={{
                    wordBreak: "break-all",
                    marginRight: "4px",
                    maxWidth: `calc(100% - ${
                      (isWarnedMerchant ? 20 : 0) +
                      (isOnApprovalDelay ? 18 : 0) +
                      (isWarnedMerchant && isOnApprovalDelay ? 8 : 0)
                    }px - 4px)`,
                  }}
                >
                  {row.name}
                </GiveTruncateText>
                <Stack
                  direction="row"
                  gap="8px"
                  sx={{
                    flexShrink: 0,
                    minWidth: "fit-content",
                  }}
                >
                  {isWarnedMerchant && (
                    <WarningIcon
                      size={20}
                      color={palette.primitive?.warning[50]}
                      style={{ flexShrink: 0, marginRight: "8px" }}
                    />
                  )}
                  {isOnApprovalDelay && isApprovedTabSelected && (
                    <Box
                      onMouseEnter={(e) => {
                        e.stopPropagation();
                        handleTooltipInteraction("open", "child");
                      }}
                      onMouseLeave={(e) => {
                        e.stopPropagation();
                        handleTooltipInteraction("close", "child");
                      }}
                      sx={{ display: "flex", alignItems: "center" }}
                    >
                      <GiveTooltip
                        title="Merchant will be activated and notified after the 2 hours from the approval"
                        color="default"
                        placement="top"
                      >
                        <ClockIcon
                          data-testid="give-clock-icon"
                          size={18}
                          color={palette.text.tertiary}
                          style={{
                            flexShrink: 0,
                            display: "block",
                          }}
                        />
                      </GiveTooltip>
                    </Box>
                  )}
                </Stack>
              </Stack>
            </GiveTooltip>
          </Stack>
          {isAcquirerPortal && showSubText && (
            <GiveTruncateText
              variant="bodyXS"
              color="secondary"
              lineClamp={1}
              onHoverShowAll
              sx={{ marginTop: "4px" }}
            >
              {isEnterpriseTable
                ? getTaxIdFormat(row?.taxIDNumber, row?.tinType, true)
                : row.parentName}
            </GiveTruncateText>
          )}
        </Box>
      </Left>
      {showCounterForMerchantListProviderPortal &&
        showForEnterprise &&
        !isMobileView &&
        isNewConversationsEnabled &&
        (row?.unreadMessagesCount || 0) > 0 && (
          <CounterChat sx={{ mr: 4 }} id={row.accID} />
        )}
      {showCanManageMoney && (
        <CanManageMoney
          canProcess={row?.canProcessMoney}
          canTransfer={row?.canTransferMoney}
          isOnApprovalDelay={row?.isOnApprovalDelay}
        />
      )}
    </Wrapper>
  );
}
 
const Wrapper = styled(Stack)(() => ({
  flexDirection: "row",
  gap: "12px",
  width: "100%",
}));
 
const Left = styled(Stack)(() => ({
  flexDirection: "row",
  alignItems: "center",
  gap: "8px",
  width: "100%",
  minWidth: "100px",
}));
 
export default MainInfo;