All files / src/sections DrawWinner.tsx

41.66% Statements 5/12
0% Branches 0/8
0% Functions 0/4
41.66% Lines 5/12

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                                2x             2x           2x         2x             2x                                                                                                                
import { Button } from "@common/Button";
import { Box, Divider, Grid } from "@mui/material";
import { Modal } from "@common/Modal";
import React from "react";
import { Text } from "@common/Text";
import { palette } from "@palette";
import { showMessage } from "@common/Toast/ShowToast";
 
type DrawWinnerProps = {
  open: boolean;
  setOpen: (open: boolean) => void;
  title: string;
  isOneWinner: boolean;
  isTicketPurchasesApproved: boolean;
};
 
const bigTitleStyle = {
  color: palette.neutral[800],
  fontSize: "24px",
  fontWeight: 600,
  mb: "8px",
};
 
const descriptionStyle = {
  color: palette.neutral[600],
  fontSize: "16px",
  fontWeight: 400,
};
 
const boldTitleStyle = {
  color: palette.neutral[800],
  fontWeight: 600,
};
 
const captionStyle = {
  fontWeight: 400,
  fontSize: 14,
  color: palette.neutral[600],
  fontStyle: "italic",
};
 
const DrawWinner = ({
  open,
  setOpen,
  title,
  isOneWinner,
  isTicketPurchasesApproved,
}: DrawWinnerProps) => {
  const drawWinnerHandler = () => {
    setOpen(false);
    if (!isTicketPurchasesApproved) {
      showMessage(
        "Warning",
        "Please wait until all outstanding ticket purchases have been approved, this can take up to 24 hours from the last purchase.",
      );
    }
  };
 
  return (
    <Modal
      open={open}
      title={`Draw Winner${isOneWinner ? "" : "s"}`}
      onClose={() => setOpen(false)}
      actions={
        <>
          <Button variant="text" onClick={() => setOpen(false)}>
            Cancel
          </Button>
          <Button onClick={drawWinnerHandler}>
            Draw Winner{isOneWinner ? "" : "s"}
          </Button>
        </>
      }
    >
      <Text sx={bigTitleStyle}>Draw Confirmation</Text>
      <Text sx={descriptionStyle}>
        Please confirm you want to draw the winner of{" "}
        <span style={boldTitleStyle}>{title}</span> sweepstakes.
      </Text>
      <Divider sx={{ my: "16px" }} />
      {isOneWinner ? (
        <Text sx={captionStyle}>
          Only <span style={{ fontWeight: 500 }}>one winner</span> will be drawn
          for the sweepstakes. An email will be sent to all participants.
        </Text>
      ) : (
        <Text sx={captionStyle}>
          You have enabled multiple winners for this Sweepstakes. A winner will
          be drawn <span style={{ fontWeight: 500 }}>for each ticket</span> item
          created. An email will be sent to all participants.
        </Text>
      )}
    </Modal>
  );
};
 
export default DrawWinner;