From ec2f64b4eaaa5c5fddd4546cd6229dc6c8742955 Mon Sep 17 00:00:00 2001 From: dabby9734 <62941997+dabby9734@users.noreply.github.com> Date: Sun, 31 Mar 2024 00:11:02 +0800 Subject: [PATCH] add modal for user to select preferred industries --- components/PersonalisationModal.tsx | 95 +++++++++++++++++++++++++++++ pages/mentors/[id].tsx | 25 +++++++- 2 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 components/PersonalisationModal.tsx diff --git a/components/PersonalisationModal.tsx b/components/PersonalisationModal.tsx new file mode 100644 index 00000000..72c87811 --- /dev/null +++ b/components/PersonalisationModal.tsx @@ -0,0 +1,95 @@ +import { Box, Button, Chip, Modal } from "@mui/material"; +import React from "react"; +import { useState, useEffect } from "react"; + +const modalStyle = { + position: "absolute" as "absolute", + top: "50%", + left: "50%", + transform: "translate(-50%, -50%)", + width: 800, + bgcolor: "background.paper", + boxShadow: 24, + borderRadius: 2, + p: 2, +}; + +const modalHeaderStyle = { + fontSize: "1.5rem", + fontWeight: "bold", + margin: 0, +}; + +const modalTextStyle = {}; + +const PersonalisationModal = ({ industries, clearFilters, addFilter }) => { + const [open, setOpen] = useState(false); + + // handles toggling of the selected industries + const [selectedIndustries, setSelectedIndustries] = useState([]); + const handleIndustryChipToggle = (industry: string) => { + if (selectedIndustries.includes(industry)) { + setSelectedIndustries(selectedIndustries.filter((i) => i !== industry)); + } else { + setSelectedIndustries([...selectedIndustries, industry]); + } + }; + + const IsChipSelected = (industry: string) => { + return selectedIndustries.includes(industry); + }; + + const handleContinueButtonClick = () => { + clearFilters(); + selectedIndustries.forEach((industry) => { + addFilter("industries", industry, "any"); + }); + setOpen(false); + localStorage.setItem("ModalClosed", "true"); + }; + + // only open the modal if the user hasn't closed it before + useEffect(() => { + if (localStorage.getItem("ModalClosed") === null) { + setOpen(true); + } + }); + + return ( + setOpen(false)}> + +

Hello there!

+

+ Select some industries you're interested in to help us personalise + your experience. +

+ + {industries === undefined &&

Loading...

} + {industries !== undefined && + industries[0].data.map( + (industry: { count: number; value: string }) => ( + handleIndustryChipToggle(industry.value)} + color="primary" + variant={ + IsChipSelected(industry.value) ? "filled" : "outlined" + } + /> + ) + )} +
+ +
+
+ ); +}; + +export default PersonalisationModal; diff --git a/pages/mentors/[id].tsx b/pages/mentors/[id].tsx index 52026d0d..ebbe6d0c 100644 --- a/pages/mentors/[id].tsx +++ b/pages/mentors/[id].tsx @@ -11,6 +11,7 @@ import { Results, SearchBox, Sorting, + WithSearch, } from "@elastic/react-search-ui"; import { FilterType, SortDirection } from "@elastic/search-ui"; import useMediaQuery from "@mui/material/useMediaQuery"; @@ -31,6 +32,7 @@ import type { GetStaticProps, GetStaticPaths } from "next"; import { useRouter } from "next/router"; import ClearFacets from "../../components/ResetButton"; +import PersonalisationModal from "../../components/PersonalisationModal"; // This also gets called at build time export const getStaticProps: GetStaticProps = async (context) => { @@ -170,9 +172,11 @@ const App = () => { } bodyContent={ - } - /> + + } + /> + } sideContent={
@@ -208,6 +212,21 @@ const App = () => { bodyFooter={} />
+ ({ + facets, + clearFilters, + addFilter, + })} + > + {({ facets, clearFilters, addFilter }) => ( + + )} +