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 | 16x 10x 7x 7x 16x 16x 16x | import { PurchaseProductType, PurchasesListItem } from "types/customer.types";
import { CustomerSection, CustomerSectionItem } from "./CustomerSection";
import { parseAmount } from "@utils/index";
import { useMemo } from "react";
interface Props {
purchases?: PurchasesListItem[];
totalPurchased?: number;
}
export default function CustomerTransaction({
purchases,
totalPurchased,
}: Props) {
const purchasesObject = useMemo(
() =>
purchases?.reduce((acc, item) => {
acc[item.name] = item;
return acc;
}, {} as Record<PurchaseProductType, PurchasesListItem>),
[purchases],
);
const { standard, event, invoice, membership, sweepstakes, fundraiser } =
purchasesObject || {};
const transactionStatistics: CustomerSectionItem[] = [
{
label: "Products (USD)",
value: standard?.total ? parseAmount(standard.total / 100) : "0.00",
},
{
label: "Events (USD)",
value: event?.total ? parseAmount(event.total / 100) : "0.00",
},
{
label: "Invoices (USD)",
value: invoice?.total ? parseAmount(invoice.total / 100) : "0.00",
},
{
label: "Memberships (USD)",
value: membership?.total ? parseAmount(membership.total / 100) : "0.00",
},
{
label: "Sweepstakes (USD)",
value: sweepstakes?.total ? parseAmount(sweepstakes.total / 100) : "0.00",
},
{
label: "Fundraisers (USD)",
value: fundraiser?.total ? parseAmount(fundraiser.total / 100) : "0.00",
},
{
label: "Total (USD)",
value: totalPurchased ? parseAmount(totalPurchased / 100) : "0.00",
customValueTextProps: { variant: "h4", fontWeight: 300 },
},
];
return (
<CustomerSection
title="Transaction Statistics"
items={transactionStatistics}
dividerIndex={transactionStatistics.length - 2}
/>
);
}
|