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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 11x 2x 2x 2x | import NiceModal from "@ebay/nice-modal-react";
import { ID, PeekModeModalType } from "./types";
import { useNavigate } from "react-router-dom";
import { Box, Stack } from "@mui/material";
import ProductsCustomerView from "@sections/PayBuilder/components/ProductsCustomerView";
import PeekPreviewWrapper from "./PeekPreviewWrapper";
import { useAppDispatch } from "@redux/hooks";
import { setSelectedPaymentFormID } from "@redux/slices/products";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { styled, useAppTheme } from "@theme/v2/Provider";
import GiveText from "@shared/Text/GiveText";
import {
ArrowUpRightIcon,
XIcon,
ArticleIcon,
EnvelopeSimpleIcon,
} from "@phosphor-icons/react";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { FormType, useGetRebrandedFormTypes } from "@sections/PayBuilder/utils";
import { useState } from "react";
import EmailPreviewController from "@sections/PayBuilder/components/EmailPreview/EmailPreviewController";
import { useGetCurrentMerchantId } from "@hooks/common";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import InvoicePreviewView from "@sections/PayBuilder/components/InvoicePreview/InvoicePreviewView";
const NewPeekModeModal = NiceModal.create(
({ previewLink, state, backgroundColor, title }: PeekModeModalType) => {
const { onClose, open } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const [campaign, id] = previewLink.split("/");
const navigate = useNavigate();
const rebrandedFormTypes = useGetRebrandedFormTypes();
const dispatch = useAppDispatch();
const { palette } = useAppTheme();
const { merchantId } = useGetCurrentMerchantId();
const { data: merchant } = useGetMerchantById({ merchantId });
const [isPreviewReceipt, setIsPreviewReceipt] = useState<boolean>(false);
const isInvoice = state.campaignType === FormType.INVOICES;
const handleClose = () => {
setIsPreviewReceipt(false);
onClose();
dispatch(setSelectedPaymentFormID(null));
};
const handleNavigate = () => {
navigate(`/${id}`, { state: state });
handleClose();
};
const getPreviewContent = () => {
Iif (isPreviewReceipt)
return <EmailPreviewController from={merchant?.name || ""} />;
Iif (isInvoice) return <InvoicePreviewView />;
return <ProductsCustomerView isPeekMode />;
};
const isNewForm = rebrandedFormTypes.includes(state.campaignType);
return (
<GiveBaseModal
open={open}
width={isMobileView ? "100%" : "70vw"}
scroll="paper"
onClose={handleClose}
showFooter={false}
showHeader={false}
sx={{
...(isPreviewReceipt && {
"& *": {
fontFamily: "Arial !important",
},
".MuiDialog-container": {
alignItems: "flex-start",
paddingTop: "48px",
},
}),
}}
PaperProps={{
sx: {
top: "64px!important",
backgroundColor: `${
isNewForm ? backgroundColor : "#F8F8F6"
} !important`,
"& .MuiDialogContent-root": {
"&::-webkit-scrollbar": {
width: "6px",
},
"&::-webkit-scrollbar-thumb": {
backgroundColor: `${palette["text-inverted"]?.tertiary} !important`,
borderRadius: "8px",
border: `1px solid ${palette["text-inverted"]?.tertiary}`,
},
"&::-webkit-scrollbar-track": {
backgroundColor: `${backgroundColor} !important`,
},
},
},
}}
slotProps={{
backdrop: { sx: { backgroundColor: palette.surface?.overlay } },
}}
>
<Box padding="20px">
<StyledButtons
gap={2}
isMobile={isMobileView}
isPreviewReceipt={isPreviewReceipt}
hasPreviewReceipt
>
<Stack gap="8px" direction="row" alignItems="center">
<GiveText variant="bodyS" color="default" whiteSpace="nowrap">
Preview {!isPreviewReceipt ? "Receipt" : "Form"}
</GiveText>
<GiveIconButton
Icon={!isPreviewReceipt ? EnvelopeSimpleIcon : ArticleIcon}
onClick={() => {
setIsPreviewReceipt((prevBool) => !prevBool);
}}
bgColor="solidWhite"
size="small"
data-testid="peek-mode-modal-expand-button"
/>
</Stack>
<Stack gap="8px" direction="row" alignItems="center">
<GiveText variant="bodyS" color="default" whiteSpace="nowrap">
Open Live Page
</GiveText>
<GiveIconButton
Icon={ArrowUpRightIcon}
onClick={handleNavigate}
bgColor="solidWhite"
size="small"
data-testid="peek-mode-modal-expand-button"
/>
</Stack>
<GiveIconButton
Icon={XIcon}
onClick={handleClose}
bgColor="solidWhite"
size="small"
data-testid="peek-mode-modal-close-button"
/>
</StyledButtons>
<Box
sx={{ pointerEvents: "none", height: "100%" }}
data-testid="public-form-container"
>
<PeekPreviewWrapper>{getPreviewContent()}</PeekPreviewWrapper>
</Box>
</Box>
</GiveBaseModal>
);
},
);
const StyledButtons = styled(Stack, {
shouldForwardProp: (prop) =>
prop !== "isMobile" &&
prop !== "isPreviewReceipt" &&
prop !== "hasPreviewReceipt",
})<{
isMobile: boolean;
isPreviewReceipt: boolean;
hasPreviewReceipt: boolean;
}>(({ isMobile, isPreviewReceipt, hasPreviewReceipt }) => {
// Base offsets depending on hasPreviewReceipt
const baseOffset = hasPreviewReceipt
? isMobile
? -242 // mobile with preview receipts in layout
: -338 // desktop with preview receipts in layout
: isMobile
? -127 // mobile without preview receipts
: -189; // desktop without preview receipts
// Extra shift when not actively previewing a receipt
const activePreviewShift = !isPreviewReceipt ? (isMobile ? -15 : -16) : 0;
return {
flexDirection: "row",
alignItems: "center",
position: "fixed",
top: "62px",
left: "calc(calc(100% - 70vw) / 2 + 70.2vw)",
transform: `translateX(${baseOffset + activePreviewShift}px)`,
};
});
export default NewPeekModeModal;
|