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 | 2x 2x | import * as React from "react";
import { palette } from "@palette";
import { Modal } from "@common/Modal";
import { RevenuesTable } from "./RevenuesTable";
import { IconButton } from "@common/IconButton";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
// assets
import { FundsIcon, SortIcon } from "@assets/icons";
import { Stack } from "@mui/material";
import MobileRevenueCard from "./MobileRevenueCard";
// data
import { tableData, RevenuesData } from "./data";
import MobileRevenueDetails from "./MobileRevenueDetails";
import MobileRevenueSortMenu from "./MobileRevenueSortMenu";
import NiceModal, { muiDialogV5, useModal } from "@ebay/nice-modal-react";
type RevenuesProps = {
type: string;
VisitorsViews: boolean;
Visitors: boolean;
};
type MobileCardsProps = {
anchorEl: HTMLElement | null;
isSwitchDetails: boolean;
type: string;
detailsData: RevenuesData | null;
setDetailsData: React.Dispatch<React.SetStateAction<RevenuesData | null>>;
setAnchorEl: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
setSelectedSortIcon: React.Dispatch<React.SetStateAction<JSX.Element>>;
setIsSwitchDetails: React.Dispatch<React.SetStateAction<boolean>>;
};
const MobileCards = ({
anchorEl,
isSwitchDetails,
type,
detailsData,
setAnchorEl,
setSelectedSortIcon,
setIsSwitchDetails,
setDetailsData,
}: MobileCardsProps) => {
return (
<>
<MobileRevenueSortMenu
anchorEl={anchorEl}
setAnchorEl={setAnchorEl}
setSelectedSortIcon={setSelectedSortIcon}
/>
{isSwitchDetails ? (
<MobileRevenueDetails
setIsSwitchDetails={setIsSwitchDetails}
data={detailsData}
title={
type === "Membership" ? "General Membership" : "New Donation Form"
}
type={type}
/>
) : (
<Stack spacing={1}>
{tableData.map((item) => (
<div
key={item.id}
onClick={() => {
setIsSwitchDetails(!isSwitchDetails);
setDetailsData(item);
}}
>
<MobileRevenueCard type={type} data={item} />
</div>
))}
</Stack>
)}
</>
);
};
const Revenues = NiceModal.create(
({ type, VisitorsViews, Visitors }: RevenuesProps) => {
const modal = useModal();
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [selectedSortIcon, setSelectedSortIcon] = React.useState(
<SortIcon />,
);
const [isSwitchDetails, setIsSwitchDetails] = React.useState(false);
const [detailsData, setDetailsData] = React.useState<RevenuesData | null>(
null,
);
const handleOpenMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleCloseModal = () => {
modal.hide();
};
return (
<Modal
{...muiDialogV5(modal)}
width="780px"
title="Revenue Sources"
titleIcon={
<FundsIcon stroke={palette.neutral[600]} width={42} height={40} />
}
onClose={handleCloseModal}
sortIconButton={
!isDesktop && !isSwitchDetails && (
<IconButton aria-label="sort" size="small" onClick={handleOpenMenu}>
{selectedSortIcon}
</IconButton>
)
}
>
{isDesktop ? (
<RevenuesTable
type={type}
VisitorsViews={VisitorsViews}
Visitors={Visitors}
/>
) : (
<MobileCards
anchorEl={anchorEl}
isSwitchDetails={isSwitchDetails}
type={type}
detailsData={detailsData}
setAnchorEl={setAnchorEl}
setDetailsData={setDetailsData}
setIsSwitchDetails={setIsSwitchDetails}
setSelectedSortIcon={setSelectedSortIcon}
/>
)}
</Modal>
);
},
);
export default Revenues;
|