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 | 43x 1x 43x 43x 43x 43x 43x 43x 43x 43x 121x 1x | import { Box, Stack } from "@mui/material";
import GiveText from "@shared/Text/GiveText";
import {
DonorComponent,
DonorsSkeleton,
ParticipantComponent,
TranslucentButton,
WinnerComponent,
} from "./Atom.component";
import NiceModal from "@ebay/nice-modal-react";
import { DONORS_MODAL } from "modals/modal_names";
import { TDonor } from "@sections/PayBuilder/provider/provider.type";
type Props = {
id: number;
donors: TDonor[];
winner: TDonor;
isWinnerSelected: boolean;
totalDonors: number;
accentColor: string;
isPreview?: boolean;
isSweepstake: boolean;
hasEnded: boolean;
isLoading?: boolean;
};
function RecentDonors({
id,
donors,
winner,
isWinnerSelected,
totalDonors,
accentColor,
isPreview,
isSweepstake,
hasEnded,
isLoading,
}: Props) {
const showDonorsModal = (type: string, accentColor: string) => {
NiceModal.show(DONORS_MODAL, {
type,
accentColor,
id: id,
isSweepstake,
hasEnded,
});
};
const totalWithWinner =
hasEnded && isWinnerSelected ? totalDonors + 1 : totalDonors;
const showedDonors = donors?.slice(
0,
winner && isSweepstake && hasEnded ? 2 : 3,
);
const showButton =
hasEnded && winner ? donors?.length > 2 : donors?.length > 3;
const getLabel = (count: number, isSweepstake: boolean) => {
const singular = isSweepstake ? "Participant" : "Donation";
const plural = isSweepstake ? "Participants" : "Donations";
return count === 1 ? singular : plural;
};
return (
<Box>
<GiveText fontSize="14px" color="primary" marginBottom="16px">
{isPreview ? donors?.length : totalWithWinner}{" "}
{getLabel(isPreview ? donors?.length : totalWithWinner, isSweepstake)}
</GiveText>
{isLoading ? (
<DonorsSkeleton count={5} />
) : (
<>
{hasEnded && isSweepstake && winner && (
<WinnerComponent {...winner} />
)}
{showedDonors?.map((donor) => {
return isSweepstake ? (
<ParticipantComponent
key={donor.name}
accentColor={accentColor}
{...donor}
/>
) : (
<DonorComponent
key={donor.name}
accentColor={accentColor}
{...donor}
/>
);
})}
</>
)}
{showButton && (
<Stack mt="16px" gap="15px" flexDirection="row">
<TranslucentButton
label="See All"
variant="filled"
size="small"
onClick={() => showDonorsModal("most_recent", accentColor)}
sx={{ fontSize: "14px", lineHeight: "20px" }}
/>
</Stack>
)}
</Box>
);
}
export default RecentDonors;
|