All files / src/features/Notifications/NotificationsCenter/components NotificationImage.tsx

100% Statements 12/12
100% Branches 8/8
100% Functions 5/5
100% Lines 12/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                26x           26x                         26x                 2115x   2115x 2115x                       26x   6371x   2115x                           26x 1784x 1784x                        
import { Box, styled } from "@mui/material";
import { NotificationType } from "../types";
import { palette } from "@palette";
import { AlertDot } from "@components/ManageMoney/TransactionTable/TransactionTable.atoms";
import { HiddenComponent } from "@containers/HiddenComponent";
import WarningIcon from "@assets/icons/RebrandedIcons/WarningIcon";
import { ConversationsChallengesIcon, EnvelopeSimpleIcon } from "@assets/icons";
 
const svgElements: Record<NotificationType, any> = {
  underwriting: WarningIcon,
  conversation: ConversationsChallengesIcon,
  generic: EnvelopeSimpleIcon,
};
 
const colors = {
  mandatory: {
    icon: palette.filled.orange,
    background: palette.tag.warning.bg,
    border: palette.filled.orange,
  },
  generic: {
    icon: palette.black[100],
    background: palette.liftedWhite[100],
    border: palette.liftedWhite[200],
  },
};
 
const NotificationImage = ({
  variant,
  isUnread,
  isMandatory,
}: {
  variant: NotificationType;
  isUnread: boolean;
  isMandatory: boolean;
}) => {
  const Icon = svgElements[isMandatory ? "underwriting" : variant];
  const { icon, background, border } =
    colors[isMandatory ? "mandatory" : "generic"];
  return (
    <CustomImage backgroundColor={background} borderColor={border}>
      <Icon width={20} height={20} stroke={icon} />
      <HiddenComponent hidden={!isUnread}>
        <CustomAlertDot isMandatory={isMandatory} />
      </HiddenComponent>
    </CustomImage>
  );
};
 
export default NotificationImage;
 
const CustomImage = styled(Box, {
  shouldForwardProp: (prop) =>
    prop !== "backgroundColor" && prop !== "borderColor",
})<{ backgroundColor: string; borderColor: string }>(
  ({ backgroundColor, borderColor }) => ({
    width: "36px",
    minWidth: "36px",
    height: "36px",
    borderRadius: "5px",
    position: "relative",
    border: `1px solid ${borderColor}`,
    backgroundColor,
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
  }),
);
 
const CustomAlertDot = styled(AlertDot, {
  shouldForwardProp: (prop) => prop !== "isMandatory",
})<{ isMandatory: boolean }>(({ isMandatory }) => ({
  width: "12px",
  height: "12px",
  position: "absolute",
  left: 0,
  top: 0,
  transform: "translate(-6px, -6px)",
  zIndex: 2,
  ...(isMandatory && {
    background: palette.accent[4],
  }),
}));