All files / src/components/ManageMoney/TransactionTable SubExpandedRow.tsx

11.42% Statements 4/35
0% Branches 0/20
0% Functions 0/19
13.33% Lines 4/30

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                                                                      3x                                     3x                                                       3x                                                                                                                                                                                                                                                                                       3x                                                                                                                                                                                          
import * as React from "react";
// mui
import Box from "@mui/material/Box";
import Grid from "@mui/material/Grid";
import Menu from "@mui/material/Menu";
import Stack from "@mui/material/Stack";
import { styled, useTheme } from "@mui/material/styles";
import MuiAccordion, { AccordionProps } from "@mui/material/Accordion";
import ArrowForwardIosSharpIcon from "@mui/icons-material/ArrowForwardIosSharp";
import MuiAccordionSummary, {
  AccordionSummaryProps,
} from "@mui/material/AccordionSummary";
import MuiAccordionDetails from "@mui/material/AccordionDetails";
// component
import { Text } from "@common/Text";
import { KeyVal } from "@common/KeyVal";
import { DropdownItem } from "@common/Select";
 
// assets
import { MoreIcon, RefundTopIcon } from "@assets/icons";
// utils
import { truncateStringLength } from "utils";
// types
import NiceModal from "@ebay/nice-modal-react";
import {
  MERCHANT_PORTAL_MODIFY_RECURRING_MODAL,
  MERCHANT_PORTAL_REFUND_MODAL,
} from "modals/modal_names";
import { Item } from "./transactions.types";
import { palette } from "@palette";
import { HiddenComponent } from "containers/HiddenComponent";
import { shouldBeHidden } from "@constants/constants";
import { RecurringComponent } from "./RecurringComponent";
import { ActionsComponent } from "@common/Table/components/ActionsComponent";
 
const Accordion = styled((props: AccordionProps) => (
  <MuiAccordion disableGutters elevation={0} square {...props} />
))(({ theme }) => ({
  fontSize: 14,
  backgroundColor: "inherit",
  border: "none",
  "&:not(:last-child)": {
    borderBottom: `2px solid ${palette.neutral[10]}`,
  },
  "&:before": {
    display: "none",
  },
  "& sup": {
    fontSize: 9,
    lineHeight: "9px",
    marginLeft: "2px",
  },
}));
 
const AccordionSummary = styled((props: AccordionSummaryProps) => (
  <MuiAccordionSummary {...props} />
))(({ theme }) => ({
  padding: "0 0 0 4px",
  backgroundColor: "inherit",
  flexDirection: "row-reverse",
 
  "& .MuiAccordionSummary-expandIconWrapper.Mui-expanded": {
    transform: "rotate(90deg)",
  },
  "& .MuiPaper-root-MuiAccordion-root:not(:last-child)": {
    borderBottom: `1px solid ${palette.neutral[10]}`,
  },
  "& .MuiAccordionSummary-content": {
    marginLeft: theme.spacing(2.5),
  },
  "& .MuiButton-root.CustomIconButton": {
    border: "none",
    boxShadow: "none",
    backgroundColor: "inherit",
 
    "&:active": {
      boxShadow:
        "inset -4px -4px 9px rgba(255, 255, 255, 0.88), inset 4px 4px 14px #C1D5EE",
    },
  },
}));
 
const AccordionDetails = styled(MuiAccordionDetails)(({ theme }) => ({
  padding: theme.spacing(1, 0, 1, 4.5),
  backgroundColor: "inherit",
}));
 
export default function SubExpandedRow({
  data,
  sourceAccount,
  transactionID,
}: {
  data: Item;
  sourceAccount: any;
  transactionID: any;
}) {
  const [expanded, setExpanded] = React.useState<boolean>(false);
  const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
  const theme = useTheme();
  const open = Boolean(anchorEl);
 
  const handleOpenMenu = (event: React.MouseEvent<HTMLElement>) => {
    setAnchorEl(event.currentTarget);
  };
 
  return (
    <Accordion expanded={expanded}>
      <AccordionSummary
        expandIcon={
          <ArrowForwardIosSharpIcon
            sx={{ fontSize: "0.9rem" }}
            onClick={() => setExpanded((prevState) => !prevState)}
          />
        }
        aria-controls="sub-expanded-row-content"
        id={data.product.name}
      >
        <Grid container alignItems="center">
          <Grid
            item
            xs={6}
            onClick={() => setExpanded((prevState) => !prevState)}
          >
            <Text color="#4C4A52" fontWeight="semibold">
              {truncateStringLength(`${data.product.name ?? ""}`, 15)}
            </Text>
            <Box>
              {expanded
                ? `${(data as any).description ?? ""}`
                : truncateStringLength(
                    `${(data as any).description ?? ""}`,
                    35,
                  )}
            </Box>
          </Grid>
          <Grid item xs={2} visibility={expanded ? "hidden" : "visible"}>
            <Text textTransform="capitalize">{(data as any).recurrence}</Text>
          </Grid>
          <Grid item xs={2} visibility={expanded ? "hidden" : "visible"}>
            <Text>
              {((data.price / 100) * data.quantity).toFixed(2)}
              <sup>USD</sup>
            </Text>
          </Grid>
 
          <Grid item xs={2}>
            <ActionsRow
              id={data.id}
              orderRecurringItemID={data.orderRecurringItemID}
              disallowReversalRequests={data.disallowReversalRequests}
              sourceAccount={sourceAccount}
            />
          </Grid>
        </Grid>
      </AccordionSummary>
 
      <AccordionDetails>
        {/* ---------- TYPE - RECURRENCE - NEXT TRANSACTION  ----------*/}
        <Grid container alignItems="center">
          <Grid item xs={6}>
            <KeyVal keyName="Type" value={data.product.type} />
          </Grid>
 
          <Grid
            item
            xs={6}
            display="flex"
            alignItems="center"
            justifyContent="space-between"
          >
            <KeyVal
              keyName="Recurrence"
              value={
                <RecurringComponent
                  recurringCount={data.recurringCount}
                  recurringInterval={data.recurringInterval}
                  recurringMax={data.recurringMax}
                />
              }
            />
          </Grid>
        </Grid>
 
        <Grid mt={1.5} container rowSpacing={1} alignItems="center">
          {/* ---------- DONATED  ----------*/}
          <Grid item xs={6}>
            <KeyVal
              keyName="Item"
              value={
                <Text>
                  Enter any amount x Qty @ 64.00<sup>USD</sup> each
                </Text>
              }
            />
          </Grid>
 
          {/* ---------- DONATION - GIVEBOX FEE - VISA FEE - CHARGED  ----------*/}
          <Grid item container xs={6}>
            <Grid item xs={3}>
              <KeyVal
                keyName="Amount"
                value={
                  <Text>
                    {(data.quantity * (data.unitPrice / 100)).toFixed(2)}
                    <sup>USD</sup>
                  </Text>
                }
              />
            </Grid>
          </Grid>
 
          <Grid item xs={12} display="flex" justifyContent="flex-end">
            <Text fontSize={12} color={theme.palette.neutral[600]}>
              *Customer Paid Fee
            </Text>
          </Grid>
        </Grid>
      </AccordionDetails>
    </Accordion>
  );
}
 
export const ActionsRow = ({
  orderRecurringItemID,
  disallowReversalRequests,
  id,
  sourceAccount,
  hideRefund,
  transactionStatus,
}: any) => {
  const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
  const open = Boolean(anchorEl);
 
  const handleOpenMenu = (event: React.MouseEvent<HTMLElement>) => {
    setAnchorEl(event.currentTarget);
  };
 
  return (
    <Stack
      gap={0.5}
      direction="row"
      alignItems="center"
      justifyContent="flex-end"
    >
      <HiddenComponent hidden={shouldBeHidden.refund}>
        <ActionsComponent
          disabled={hideRefund}
          onClick={() =>
            NiceModal.show(MERCHANT_PORTAL_REFUND_MODAL, {
              sourceAccount,
              ids: {
                transactionItemIDs: [id],
              },
            })
          }
          title="Refund"
          icon={() => <RefundTopIcon size="20px" />}
        />
      </HiddenComponent>
      <ActionsComponent
        title="More"
        onClick={handleOpenMenu}
        icon={() => <MoreIcon size="20px" />}
      />
 
      <Menu
        open={open}
        anchorEl={anchorEl}
        onClose={() => setAnchorEl(null)}
        anchorOrigin={{
          vertical: "bottom",
          horizontal: "right",
        }}
        transformOrigin={{
          vertical: "top",
          horizontal: "right",
        }}
        sx={{
          "& .MuiPaper-root": {
            width: 159,
          },
        }}
      >
        <HiddenComponent hidden={shouldBeHidden.refund || hideRefund}>
          <DropdownItem
            disabled={disallowReversalRequests}
            onClick={() => {
              NiceModal.show(MERCHANT_PORTAL_REFUND_MODAL, {
                sourceAccount,
                ids: {
                  transactionItemIDs: [id],
                },
              });
              if (anchorEl) setAnchorEl(null);
            }}
          >
            <Text>Refund</Text>
          </DropdownItem>
        </HiddenComponent>
        <DropdownItem
          disabled={!orderRecurringItemID || transactionStatus === "Voided"}
          onClick={() => {
            NiceModal.show(MERCHANT_PORTAL_MODIFY_RECURRING_MODAL, {
              orderRecurringItemID: orderRecurringItemID,
              sourceAccount,
            });
            if (anchorEl) setAnchorEl(null);
          }}
        >
          <Text>Modify Recurring</Text>
        </DropdownItem>
      </Menu>
    </Stack>
  );
};