All files / src/sections/ProductInfosModal ProductInfosModal.tsx

0% Statements 0/11
0% Branches 0/8
0% Functions 0/4
0% Lines 0/11

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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180                                                                                                                                                                                                                                                                                                                                                                       
import React, { useMemo } from "react";
import NiceModal, { useModal, muiDialogV5 } from "@ebay/nice-modal-react";
import { DialogContent, Stack } from "@mui/material";
import { palette } from "@palette";
import { Text } from "@common/Text";
import { EditorState } from "draft-js";
import { ReadOnlyEditor } from "@components/PaymentForm";
import { BaseModal, ModalTitle } from "@common/Modal";
import { Image } from "@common/StyledImage/Image";
import PaymentCardTitle from "@components/PaymentForm/PaymentCard/PaymentCardTitle";
 
type ProductInfoModalProps = {
  title: string;
  renderDescription: () => string | EditorState;
  imageURL?: string;
  price: number;
};
 
type TitleComponentProps = Partial<ProductInfoModalProps>;
const TitleComponent = ({
  imageURL,
  title,
  price,
  ...props
}: TitleComponentProps) => {
  return (
    <Stack
      direction="row"
      gap={2}
      justifyContent="space-between"
      alignItems="start"
      width="100%"
    >
      <Stack pt={0.5} direction="row" gap={2} flexGrow={1} alignItems="start">
        {imageURL && (
          <Image
            width="102px"
            height="102px"
            alt={title}
            src={`${imageURL}/original`}
          />
        )}
 
        <Stack
          direction="column"
          pt={1}
          gap={0.5}
          flexGrow={1}
          justifyContent="start"
          alignItems="start"
          sx={{ overflow: "hidden" }}
        >
          <PaymentCardTitle
            title={title}
            quantity={10}
            price={price}
            style={{
              paddingTop: 0,
              color: palette.neutral[70],
            }}
          />
        </Stack>
      </Stack>
    </Stack>
  );
};
 
const ProductInfoModal = NiceModal.create(
  ({ title, renderDescription, imageURL, price }: ProductInfoModalProps) => {
    const [dialogScrollTop, setDialogScrollTop] = React.useState<number>(0);
 
    const description = useMemo(() => {
      return renderDescription();
    }, [renderDescription]);
    const isDescriptionValid = React.useRef(
      (description as EditorState).getCurrentContent().getPlainText("\u0001")
        .length,
    );
 
    const modal = useModal();
 
    // const handleModalClose = () => {
    //   modal.hide();
    // };
 
    // const handleModalContentScroll = (
    //   event: React.UIEvent<HTMLElement>,
    // ): void => {
    //   let newScrollValue = event.currentTarget.scrollTop;
    //   if (!imageURL) newScrollValue += 114;
    //   setDialogScrollTop(newScrollValue);
    // };
 
    return (
      <BaseModal
        width="720px"
        {...muiDialogV5(modal)}
        sx={{
          "& .MuiDialog-paper": {
            borderRadius: "16px",
            width: "720px",
            maxWidth: "720px",
            background: "#F8F8F6",
            "@media (max-width: 600px)": {
              height: "auto",
              maxHeight: "auto",
              alignSelf: "center",
              margin: 2.5,
            },
          },
          "& .MuiDialogTitle-root + .MuiDialogContent-root": {
            paddingTop: "0px !important",
          },
          "& .MuiDialogActions-root": {
            "@media (max-width: 600px)": {
              flexDirection: "column",
            },
          },
        }}
      >
        {" "}
        <ModalTitle
          titleComponent={
            <TitleComponent title={title} imageURL={imageURL} price={price} />
          }
          onClose={() => modal.hide()}
          backgroundColor="#FFF"
        />
        {isDescriptionValid.current > 0 && (
          <DialogContent
            sx={{
              backgroundColor: "neutral.white",
              padding: 0,
            }}
          >
            <Stack direction="column" gap="12px" position="relative">
              {typeof description === "string" ? (
                <Text
                  color={palette.neutral[600]}
                  variant="headline"
                  sx={{
                    wordBreak: "break-word",
                    position: "relative",
 
                    "&::before": {
                      ...overlayStyle,
                      display: dialogScrollTop >= 160 ? "block" : "none",
                      top: dialogScrollTop - 184,
                    },
                  }}
                >
                  {description}
                </Text>
              ) : (
                <ReadOnlyEditor
                  editorState={description}
                  scrollTop={dialogScrollTop}
                />
              )}
            </Stack>
          </DialogContent>
        )}
      </BaseModal>
    );
  },
);
 
const overlayStyle = {
  content: '""',
  width: "100%",
  height: "77px",
  position: "absolute",
  left: 0,
  zIndex: 10,
  background:
    "linear-gradient(180deg, #FFFFFF 19.27%, rgba(255, 255, 255, 0) 100%)",
};
 
export default ProductInfoModal;