All files / src/features/Merchants/MerchantSidePanel/AgreementAndSnapshot/Agreement/components AgreementStatusCard.tsx

96.66% Statements 29/30
77.77% Branches 14/18
88.88% Functions 8/9
96.66% Lines 29/30

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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162                                        17x             7x 7x 7x 7x 7x 7x 7x   7x   7x   7x                                                           7x 7x 7x 7x           7x   7x                                                                     17x 25x 2x               17x 7x                 17x 7x               17x 7x             17x 45x   7x            
import { Box, Stack, TypographyProps } from "@mui/material";
import { CheckCircleIcon, WarningIcon, XCircleIcon } from "@phosphor-icons/react";
import GiveText from "@shared/Text/GiveText";
import { useAppTheme, styled } from "@theme/v2/Provider";
import { StatusInfo } from "../../agreements.types";
import NiceModal from "@ebay/nice-modal-react";
import { GIVE_MERCHANT_AGREEMENT_MODAL } from "modals/modal_names";
import { useMerchantSidePanelContext } from "features/Merchants/MerchantSidePanel/Provider/MerchantSidePanelProvider";
import { TMerchantBaseContextData } from "@components/Merchants/MerchantPreview/data.types";
import { useEnterprisePermissions } from "@components/AcquirerEnterprises/CreateEnterprise/hooks/useEnterprisePermissions";
import { checkPortals } from "@utils/routing";
import { ModalMerchantData } from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/types";
 
interface Props {
  statusInfo?: StatusInfo;
  defaultContext?: TMerchantBaseContextData;
  merchantId?: number;
  merchantData?: ModalMerchantData;
  isProvider?: boolean
}
const AgreementStatusCard = ({
  statusInfo,
  defaultContext,
  merchantId,
  merchantData,
  isProvider
}: Props) => {
  const context = useMerchantSidePanelContext();
  const { data, id } = defaultContext ?? context;
  const usedData = data || merchantData;
  const { agreement_signing } = useEnterprisePermissions();
  const { isEnterprisePortal } = checkPortals();
  const { palette } = useAppTheme();
  const { success, error, warning } = palette.primitive || {};
  const { status, msaLastAcceptedVersion, tcVersion, signedOn, signedBy } =
    statusInfo || {};
   
  const localStatus = status || "not_signed";
 
  const statusDetails = {
    signed: {
      text: `${signedBy} agreed on ${signedOn} to Version ${msaLastAcceptedVersion}  `,
      Icon: CheckCircleIcon,
      colors: {
        bgColor: success?.[25],
        textColor: success?.[100],
        borderColor: success?.[100],
      },
    },
    not_signed: {
      text: `The agreement has not been signed yet. The agreement can be signed by authorized users or the Primary Account Holder.`,
      Icon: XCircleIcon,
      colors: {
        bgColor: error?.[25],
        textColor: error?.[100],
        borderColor: error?.[100],
      },
    },
    newVersion: {
      text: `${signedBy} agreed on ${signedOn} to version ${msaLastAcceptedVersion} but a new TOS version (${tcVersion}) is available`,
      Icon: WarningIcon,
      colors: {
        bgColor: warning?.[10],
        textColor: warning?.[100],
        borderColor: warning?.[100],
      },
    },
  };
 
  const { text, Icon, colors } = statusDetails[localStatus];
  const { bgColor, textColor, borderColor } = colors;
  const isNewVersion = localStatus === "newVersion";
  const handleOpenAgreementModal = () =>
    NiceModal.show(GIVE_MERCHANT_AGREEMENT_MODAL, {
      data: usedData,
      merchantId: id || merchantId,
    });
 
  const isHiddenAction = isEnterprisePortal && !agreement_signing || isProvider;
 
  return (
    <Container
      border={`1px solid ${borderColor}`}
      bgcolor={bgColor}
      width="100%"
    >
      <IconContainer>
        <Icon size="20px" color={textColor} />
      </IconContainer>
      <TextContainer>
        <CustomText
          variant="bodyS"
          textColor={textColor}
          data-testid="disclaimer-content"
        >
          {text}
        </CustomText>
        {isNewVersion && !isHiddenAction && (
          <CheckUpdateText
            onClick={handleOpenAgreementModal}
            variant="bodyS"
            textColor={textColor}
          >
            Check Update
          </CheckUpdateText>
        )}
      </TextContainer>
    </Container>
  );
};
 
export default AgreementStatusCard;
interface CustomTextProps extends TypographyProps {
  textColor?: string;
}
const CheckUpdateText = styled(GiveText, {
  shouldForwardProp: (prop) => prop !== "textColor",
})<CustomTextProps>(({ textColor }) => ({
  color: textColor,
  display: "block",
  textAlign: "left",
  textDecoration: "underline",
  cursor: "pointer",
  marginTop: "14px",
}));
const Container = styled(Stack)(({ theme }) => {
  return {
    padding: "12px",
    flexDirection: "row",
    gap: "12px",
    alignItems: "flex-start",
    borderRadius: `${theme.customs?.radius?.extraSmall}px`,
  };
});
 
const IconContainer = styled(Box)(() => {
  return {
    height: "20px",
    display: "flex",
    alignItems: "center",
    flexShrink: 0,
  };
});
 
const TextContainer = styled(Box)(() => {
  return {
    display: "flex",
    flexDirection: "column",
    flexGrow: 1,
  };
});
 
const CustomText = styled(GiveText, {
  shouldForwardProp: (prop) => prop !== "textColor",
})<CustomTextProps>(({ textColor }) => {
  return {
    color: textColor,
    display: "block",
    textAlign: "left",
  };
});