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 | 53x 53x 158x 158x 158x 158x | import { Grid } from "@mui/material";
import { KeyVal } from "@common/KeyVal";
import {
PurchaseProductType,
PurchasesListItem,
} from "@customTypes/customer.types";
type functionArguments = {
purchasesList?: PurchasesListItem[];
xs: number;
color?: string;
};
const renderPurchasesStatistics = ({
purchasesList,
xs,
color,
}: functionArguments): JSX.Element[] => {
return ["fundraiser", "event", "invoice", "membership", "sweepstake"].map(
(product) => {
const currentPurchase = purchasesList?.filter(
(purchase: PurchasesListItem) => {
if (product === "fundraiser" && purchase.name === "generic")
return true;
return purchase.name === product;
},
);
const value =
currentPurchase && currentPurchase.length > 0
? (currentPurchase[0].total / 100).toFixed(2)
: "0";
const statName = getProductType(product as PurchaseProductType, true);
return (
<Grid item xs={xs} key={product}>
<KeyVal
keyName={statName}
value={value}
isAmount
sx={{ color: color }}
/>
</Grid>
);
},
);
};
export const getProductType = (
productType: PurchaseProductType,
isPlural = false,
) => {
Iif (productType === "standard") {
return `Product${isPlural ? "s" : ""}`;
}
Iif (productType === "fundraiser" || productType === "generic") {
return isPlural ? "Donations" : "Donation";
}
const plural = isPlural ? "s" : "";
return productType.charAt(0).toUpperCase() + productType.slice(1) + plural;
};
export default renderPurchasesStatistics;
|