-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add modal for user to select preferred industries
- Loading branch information
Showing
2 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean>(false); | ||
|
||
// handles toggling of the selected industries | ||
const [selectedIndustries, setSelectedIndustries] = useState<string[]>([]); | ||
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 ( | ||
<Modal open={open} onClose={() => setOpen(false)}> | ||
<Box sx={modalStyle}> | ||
<p style={modalHeaderStyle}>Hello there!</p> | ||
<p style={modalTextStyle}> | ||
Select some industries you're interested in to help us personalise | ||
your experience. | ||
</p> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexWrap: "wrap", | ||
gap: 1, | ||
marginBottom: "1rem", | ||
}} | ||
> | ||
{industries === undefined && <p>Loading...</p>} | ||
{industries !== undefined && | ||
industries[0].data.map( | ||
(industry: { count: number; value: string }) => ( | ||
<Chip | ||
label={industry.value} | ||
onClick={() => handleIndustryChipToggle(industry.value)} | ||
color="primary" | ||
variant={ | ||
IsChipSelected(industry.value) ? "filled" : "outlined" | ||
} | ||
/> | ||
) | ||
)} | ||
</Box> | ||
<Button onClick={handleContinueButtonClick}>Continue</Button> | ||
</Box> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default PersonalisationModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters