All files / src/features/GiveRiskProfile/Overview TransactionRiskOverview.tsx

100% Statements 17/17
57.14% Branches 8/14
100% Functions 8/8
100% Lines 16/16

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                                              53x               16x 16x 16x 16x 16x   16x   16x       1x         1x         1x       19x   16x                                             1x                                             3x                           3x                                                          
import { Stack } from "@mui/material";
import IPProfileInfo from "./components/IPProfileInfo";
import IPAddressLocationMapV2 from "./components/IPAddressLocationMapV2";
import GiveTabs from "@shared/Tabs/GiveTabs";
import { useAppTheme } from "@theme/v2/Provider";
import { useState } from "react";
import ContextualMenu from "@shared/ContextualMenu/ContextualMenu";
import GiveTableHeader from "@shared/Table/GiveTableHeader";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import AllPage from "./components/AllPage";
 
import { TransactionRiskProps } from "../types";
import {
  selectTimeFilter,
  selectTypeFilter,
  setTimeFilter,
  setTypeFilter,
} from "@redux/slices/acquirer/transactionRiskProfile";
import { useAppDispatch, useAppSelector } from "@redux/hooks";
 
// Union type for tabs
type TabKey = "all" | "escalations";
 
const TransactionRiskOverview = ({
  data,
  riskProfileData,
  setSelectedRow,
  isLast,
  isFirst,
  openMainPanel
}: TransactionRiskProps) => {
  const theme = useAppTheme();
  const { isMobileView } = useCustomThemeV2();
  const dispatch = useAppDispatch();
  const typeFilter = useAppSelector(selectTypeFilter);
  const timeFilter = useAppSelector(selectTimeFilter);
 
  const [anchor, setMenuAnchor] = useState<null | HTMLElement>(null);
 
  const timeArray = [
    {
      text: isMobileView ? "All" : "All Time",
      value: "all",
      onClick: () => dispatch(setTimeFilter("all")),
    },
    {
      text: isMobileView ? "30d" : "Last 30 days",
      value: "month",
      onClick: () => dispatch(setTimeFilter("month")),
    },
    {
      text: isMobileView ? "24h" : "Last 24 Hours",
      value: "day",
      onClick: () => dispatch(setTimeFilter("day")),
    },
  ];
 
  const selectedOption = timeArray.find((o) => o.value === timeFilter);
 
  return (
    <Stack spacing={2}>
      <IPAddressLocationMapV2 data={riskProfileData.geomap} />
      <IPProfileInfo data={data} riskProfileData={riskProfileData} />
 
      <Stack
        width="100%"
        justifyContent="space-between"
        flexDirection="row"
        alignItems="center"
      >
        <GiveTabs
          items={[
            { label: "All activity", value: "all" },
            { label: "Escalations", value: "escalations" },
          ]}
          type="segmented"
          selected={typeFilter}
          variant={"primary" as any}
          tabSx={{
            borderRadius: "40px",
            padding: "8px 16px",
          }}
          onClick={(val) => dispatch(setTypeFilter(val as TabKey))}
          containerSx={{
            display: "flex",
            overflowX: "auto",
            scrollbarWidth: "none",
            border: "none",
            [theme.breakpoints.down("v2_sm")]: {
              width: "100vw",
              marginLeft: "-20px",
              marginRight: "-20px",
              whiteSpace: "nowrap",
              padding: "0 20px",
              overflowX: "auto",
            },
            gap: "16px",
          }}
          applyGradient={false}
        />
 
        <GiveTableHeader
          component="div"
          state={anchor ? "asc" : "desc"}
          onClick={(e) => {
            setMenuAnchor(e?.currentTarget);
          }}
          width="auto"
          sxProps={{
            background: "transparent",
          }}
          sxContentProps={{
            justifySelf: "right",
          }}
        >
          {selectedOption?.text || timeFilter}
        </GiveTableHeader>
        <ContextualMenu
          handleClose={() => {
            setMenuAnchor(null);
          }}
          anchorEl={anchor}
          options={timeArray}
          color={isMobileView ? "primary" : "tertiary"}
          texture={isMobileView ? "solid" : "blurred"}
          transformOrigin={{
            vertical: "top",
            horizontal: "left",
          }}
          anchorOrigin={{
            vertical: "bottom",
            horizontal: "left",
          }}
        />
      </Stack>
 
      <AllPage
        setSelectedRow={setSelectedRow}
        isLast={isLast}
        isFirst={isFirst}
        transactions={riskProfileData?.transactions}
        openMainPanel={openMainPanel}
      />
    </Stack>
  );
};
 
export default TransactionRiskOverview;