All files / src/components/BankAccounts BankAccountWarningAlert.tsx

100% Statements 8/8
100% Branches 13/13
100% Functions 3/3
100% Lines 6/6

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                          20x   20x   1x                                                           19x                           6x                                                   19x                                  
import { Text } from "@common/Text";
import { NOT_ALLOWED_TO_ADD_BANK_ACCOUNT_BANNER_MESSAGE } from "@constants/stringConstants";
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
import { palette } from "@palette";
import { WarningIcon } from "@phosphor-icons/react";
import { Box, Stack, styled } from "@mui/material";
 
type Props = {
  isAllowedAddAccounts: boolean;
};
export default function BankAccountWarningAlert({
  isAllowedAddAccounts,
}: Props) {
  const { isMasqueradeMode } = useMasqueradeReducer();
 
  if (isAllowedAddAccounts || !isMasqueradeMode) return null;
 
  return (
    <WarningPlaceholderBase
      message={NOT_ALLOWED_TO_ADD_BANK_ACCOUNT_BANNER_MESSAGE}
      icon={
        <WarningIcon size={24} color={palette.filled.orange} weight="duotone" />
      }
      containerStyle={{
        padding: "12px 16px",
        gap: "8px",
        borderRadius: "12px",
        border: "none",
        background: palette.tag.warning.bg,
      }}
      hideTitle
    />
  );
}
 
type WarningPlaceholderBaseProps = {
  title?: string;
  message: string | React.ReactNode;
  messageColor?: string;
  titleColor?: string;
  children?: React.ReactNode;
  containerStyle?: React.CSSProperties;
  icon?: React.ReactNode;
  titleStyle?: React.CSSProperties;
  hideTitle?: boolean;
};
 
export const WarningPlaceholderBase = ({
  title = "Attention",
  message,
  messageColor = palette.warning.text,
  titleColor = palette.tag.warning.hover,
  children,
  containerStyle,
  icon,
  titleStyle = {
    fontSize: 14,
    lineHeight: "16.8px",
  },
  hideTitle = false,
}: WarningPlaceholderBaseProps) => {
  return (
    <WarningContainer sx={containerStyle} data-testid="warning-container">
      <Stack direction="row" spacing="8px" alignItems="center">
        {icon || <WarningIcon height={20} width={20} />}
        {!hideTitle && (
          <Text sx={titleStyle} color={titleColor}>
            {title}
          </Text>
        )}
      </Stack>
      <Stack spacing={2}>
        <Text
          fontSize="14px"
          lineHeight="16.8px"
          color={messageColor}
          fontWeight="book"
          sx={{ wordBreak: "break-word" }}
        >
          {message}
        </Text>
        {children}
      </Stack>
    </WarningContainer>
  );
};
 
const WarningContainer = styled(Box)(() => ({
  display: "flex",
  padding: " 12px 12px",
  flexDirection: "column",
  gap: "12px",
  borderRadius: "8px",
  border: "2px solid rgba(255, 129, 36, 0.50)",
  background: "#FFE7D6",
 
  "& ul": {
    paddingLeft: "25px",
  },
  "& li::marker": {
    color: palette.warning.text,
    paddingLeft: "8px",
  },
}));