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

[MPT-91] Mentors: MVP for simple questionnaire #750

Merged
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
87 changes: 87 additions & 0 deletions components/PersonalisationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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>(true);

// 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);
};

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>}
wei2912 marked this conversation as resolved.
Show resolved Hide resolved
{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;
29 changes: 24 additions & 5 deletions pages/mentors/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) => {
Expand Down Expand Up @@ -103,7 +105,7 @@ const App = () => {
values: [WAVES[currentTabId].waveId],
},
],
disjunctiveFacets: ["organisation", "course_of_study"],
disjunctiveFacets: ["organisation", "course_of_study", "industries"],
facets: {
industries: { type: "value", size: 100 },
organisation: { type: "value", size: 100 },
Expand Down Expand Up @@ -170,9 +172,11 @@ const App = () => {
</div>
}
bodyContent={
<Results
resultView={({ result }) => <ResultView result={result} />}
/>
<React.Fragment>
<Results
resultView={({ result }) => <ResultView result={result} />}
/>
</React.Fragment>
}
sideContent={
<div>
Expand All @@ -183,7 +187,7 @@ const App = () => {
{ name: "Name", value: "name", direction: "asc" },
]}
/>
<Facet field="industries" label="Industries" />
<Facet field="industries" filterType="any" label="Industries" />
<Facet
field="organisation"
filterType="any"
Expand All @@ -208,6 +212,21 @@ const App = () => {
bodyFooter={<Paging />}
/>
</div>
<WithSearch
mapContextToProps={({ facets, clearFilters, addFilter }) => ({
facets,
clearFilters,
addFilter,
})}
>
{({ facets, clearFilters, addFilter }) => (
<PersonalisationModal
industries={facets.industries}
clearFilters={clearFilters}
addFilter={addFilter}
/>
)}
</WithSearch>
</SearchProvider>
<Footer />
</div>
Expand Down
Loading