Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge to prod #2329

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zesty-website",
"author": "Zesty.io Platform Inc.",
"email": "[email protected]",
"version": "1.0.9",
"version": "1.0.10",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev",
Expand Down
32 changes: 30 additions & 2 deletions src/components/marketing/PopupLeadCapture/PopUpForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Button, TextField, Typography, useTheme } from '@mui/material';
import { useState } from 'react';
import CloseIcon from '@mui/icons-material/Close';
import { ErrorMessage, Field, Form, Formik } from 'formik';

import { setCookie, getCookie, hasCookie } from 'cookies-next';
import * as Yup from 'yup';
import {
getLeadObjectZOHO,
Expand All @@ -24,6 +24,8 @@ export default function PopUpForm({
description,
thankYouMessage,
pdfLink,
cookieName,
setShowPopup,
}) {
const theme = useTheme();

Expand Down Expand Up @@ -51,8 +53,31 @@ export default function PopUpForm({

setSuccess(true);

// save pathname to cookie after downloading pdf
savePathnameToCookie(window.location.pathname);

return values;
};

const savePathnameToCookie = (pathname) => {
const cookieOptions = {
maxAge: 365 * 24 * 60 * 60 * 1000,
};
const expiration = new Date();
expiration.setDate(new Date().getDate() + 15); // Set to expire after 15 days
if (!hasCookie(cookieName)) {
setCookie(
cookieName,
JSON.stringify([{ path: pathname, expire: expiration }]),
cookieOptions,
);
return;
}

let value = JSON.parse(getCookie(cookieName));
value.push({ path: pathname, expire: expiration });
setCookie(cookieName, JSON.stringify(value), cookieOptions);
};
return (
<Box
sx={{
Expand All @@ -73,7 +98,10 @@ export default function PopUpForm({
<Box sx={{ p: 2 }}>
{height ? (
<CloseIcon
onClick={() => setDownloadClick(false)}
onClick={() => {
setDownloadClick(false);
success && setShowPopup(false);
}}
sx={{
color: 'white',
cursor: 'pointer',
Expand Down
5 changes: 5 additions & 0 deletions src/components/marketing/PopupLeadCapture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export default function PopUpLeadCapture({
ctaText,
thankYouMessage,
pdfLink,
cookieName,
setShowPopup,
}) {
const [isExpanded, setIsExpanded] = useState(true);
const [downloadClick, setDownloadClick] = useState(false);
const theme = useTheme();

return (
<Box
sx={{
Expand Down Expand Up @@ -101,6 +104,8 @@ export default function PopUpLeadCapture({
description={description}
setDownloadClick={setDownloadClick}
height={downloadClick ? 425 : 0}
cookieName={cookieName}
setShowPopup={setShowPopup}
/>
</Box>
</Box>
Expand Down
48 changes: 46 additions & 2 deletions src/pages/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,52 @@ export function DocSearchModal() {

return (
<DocSearch
transformItems={(item) => {
return item.reverse();
transformItems={(items) => {
/*
* Group items by hierarchy and remove items without hierarchy
*/
const groupBy = items.reduce((acc, item) => {
if (!item.hierarchy) {
return acc;
}
const list = acc[item.hierarchy.lvl1] || [];

return {
...acc,
[item.hierarchy.lvl1]: list.concat(item),
};
}, {});

/**
* Group based on parent page
*/
const groups = Object.keys(groupBy).map((level) => ({
items: groupBy[level],
}));

const groupItems = groups?.[0]?.items || [];

/**
* Find the parent page from groupItems
*/
const parent = groupItems?.find((item) => {
if (
item.hierarchy.lvl1 !== null &&
item.hierarchy.lvl2 == null &&
item.hierarchy.lvl3 == null &&
item.hierarchy.lvl4 == null &&
item.hierarchy.lvl5 == null &&
item.hierarchy.lvl6 == null
) {
return item;
}
});

/**
* find the index of the parent from groupItems and put it in the first index
*/
const parentIndex = groupItems?.indexOf(parent);
return groupItems.splice(parentIndex, 1).concat(groupItems);
}}
placeholder="Search docs..."
maxResultsPerGroup={100}
Expand Down
29 changes: 28 additions & 1 deletion src/views/zesty/Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import useFetch from 'components/hooks/useFetch';
import BlogContent from 'revamp/ui/BlogContent';
import { CtaWithInputField } from 'blocks/cta';
import PopUpLeadCapture from 'components/marketing/PopupLeadCapture';
import { getCookie, hasCookie, setCookie } from 'cookies-next';

function Article({ content }) {
const [newContent, setNewContent] = useState(content.article);
Expand Down Expand Up @@ -80,6 +81,8 @@ function Article({ content }) {
name: c?.tag,
link: c?.meta?.web?.uri,
}));
const [showPopup, setShowPopup] = useState(false);
const cookieName = 'DOWNLOADED_PDF';

// Define a regular expression pattern to match [_CTA_]
let regexPattern = /\[CALL TO ACTION\]/g;
Expand Down Expand Up @@ -108,8 +111,30 @@ function Article({ content }) {
'<acronym title="Call to Action"></acronym>',
),
);

verifyPathnameInCookie(window.location.pathname);
}, []);

const verifyPathnameInCookie = (path) => {
if (!hasCookie(cookieName)) {
setShowPopup(true);
return;
}

const value = JSON.parse(getCookie(cookieName));
const newValue = value.filter((obj) => !isDateExpired(obj.expire));

if (value.length !== newValue.length)
setCookie(cookieName, newValue, { maxAge: 365 * 24 * 60 * 60 * 1000 });

if (!newValue.some((item) => item.path === path)) setShowPopup(true);
};

const isDateExpired = (inputDate) => {
const currentDate = new Date();
return new Date(inputDate) < currentDate;
};

const popupLeadCaptureProps = {
title: content?.pop_up_title || 'FREE CMS BUYING GUIDE',
description: content?.pop_up_description || 'DOWNLOAD CMS BUYING GUIDE',
Expand All @@ -120,6 +145,8 @@ function Article({ content }) {
pdfLink:
content?.pdf_link ||
'https://kfg6bckb.media.zestyio.com/HeadlessCMS-Buyers-Guide-Zesty.H17lCRwtp.pdf',
cookieName,
setShowPopup,
};

return (
Expand Down Expand Up @@ -617,7 +644,7 @@ function Article({ content }) {
</Container>

{/* Side PopUp */}
<PopUpLeadCapture {...popupLeadCaptureProps} />
{showPopup && <PopUpLeadCapture {...popupLeadCaptureProps} />}
</Box>
);
}
Expand Down
Loading