Skip to content

Commit

Permalink
Fix Provisions popup not to render on SSRed version, or when it was d…
Browse files Browse the repository at this point in the history
…ismissed
  • Loading branch information
igalst committed Feb 20, 2024
1 parent 4863e77 commit b46a225
Showing 1 changed file with 81 additions and 79 deletions.
160 changes: 81 additions & 79 deletions workspaces/website/src/components/ProvisionsPopup/ProvisionsPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@ import { Button } from "@ui/Button";
import { useLocalStorage } from "usehooks-ts";

const ProvisionsPopup = () => {
return null;
const isSsr = typeof window === "undefined";

const [isProvisionsPopupOpen, setIsProvisionsPopupOpen] = useLocalStorage(
const [isOpenStorage, setIsOpenStorage] = useLocalStorage(
"isProvisionsPopupOpen",
true
!isSsr
);

const toggleModal = () => setIsProvisionsPopupOpen((prevState) => !prevState);

const gtmEvent = (event: string) => window?.dataLayer.push({ event });
const gtmEventClickReadMore = () => gtmEvent("Provisions popup click");
const gtmEventClickClose = () => gtmEvent("Provisions popup close");

const onClose = (event: React.MouseEvent) => {
event.stopPropagation();
gtmEventClickClose();
toggleModal();
setIsProvisionsPopupOpen(false);
setIsOpenStorage(false);
};

const onReadMore = (event: React.MouseEvent) => {
event.stopPropagation();
gtmEventClickReadMore();
setIsOpenStorage(false);
};

if (!isOpenStorage) return;

return (
<Fade
in={isProvisionsPopupOpen}
in={isOpenStorage}
style={{ zIndex: "9999" }}
transition={{ enter: { duration: 0.5 } }}
>
Expand All @@ -39,90 +44,87 @@ const ProvisionsPopup = () => {
bottom="0"
right="0"
left="0"
display={isProvisionsPopupOpen ? "unset" : "none"}
display={isOpenStorage ? "unset" : "none"}
backgroundColor="rgba(0,0,0,0.7)"
onClick={onClose}
/>
<Box
pos="fixed"
left="50%"
top="50%"
transform="translate(-50% ,-50%)"
w={[336]}
h={[358]}
borderRadius="8px"
bgGradient="linear(to-l, #0C0C4F, #3F8CFF)"
display={!isOpenStorage ? "none" : "block"}
>
<Box
pos="fixed"
left="50%"
top="50%"
transform="translate(-50% ,-50%)"
w={[336]}
h={[358]}
mt="2px"
ml="2px"
bgColor="white"
w={[332]}
h={[354]}
borderRadius="8px"
bgGradient="linear(to-l, #0C0C4F, #3F8CFF)"
display={!isProvisionsPopupOpen ? "none" : "block"}
>
<Box
mt="2px"
ml="2px"
<IconButton
aria-label="Close"
border="0"
position="absolute"
right="10px"
top="10px"
width="28px"
height="28px"
style={{ backgroundColor: "transparent" }}
onClick={onClose}
>
<CloseIcon />
</IconButton>
<Image
src={Background}
alt=""
width="100%"
height="100%"
borderRadius="6px"
objectFit="cover"
/>
<Image
src={Logo}
alt="STRK Starknet Provisions"
position="absolute"
top="91px"
left="50%"
transform="translateX(-50%)"
borderRadius="6px"
/>
<Button
variant="solid"
bgColor="white"
w={[332]}
h={[354]}
position="absolute"
bottom="40px"
left="50%"
transform="translateX(-50%)"
borderRadius="8px"
mr="px"
width="288px"
height="48px"
color="black"
cursor="pointer"
href="https://www.starknet.io/en/content/starknet-provisions-program"
_hover={{ color: "#8FBCFF" }}
onClick={onReadMore}
>
<IconButton
aria-label="Close"
border="0"
position="absolute"
right="10px"
top="10px"
width="28px"
height="28px"
style={{ backgroundColor: "transparent" }}
onClick={onClose}
>
<CloseIcon />
</IconButton>
<Image
src={Background}
alt=""
width="100%"
height="100%"
borderRadius="6px"
objectFit="cover"
/>
<Image
src={Logo}
alt="STRK Starknet Provisions"
position="absolute"
top="91px"
left="50%"
transform="translateX(-50%)"
borderRadius="6px"
/>
<Button
variant="solid"
bgColor="white"
position="absolute"
bottom="40px"
left="50%"
transform="translateX(-50%)"
borderRadius="8px"
mr="px"
width="288px"
height="48px"
color="black"
cursor="pointer"
href="https://www.starknet.io/en/content/starknet-provisions-program"
Read more
<Icon
mt="1px"
ml="4px"
_hover={{
color: "#8FBCFF",
}}
onClick={gtmEventClickReadMore}
>
Read more
<Icon
mt="1px"
ml="4px"
_hover={{
color: "#8FBCFF",
}}
>
<ArrowRight />
</Icon>
</Button>
</Box>
<ArrowRight />
</Icon>
</Button>
</Box>
</Box>
</Fade>
Expand Down

0 comments on commit b46a225

Please sign in to comment.