Skip to content

Commit

Permalink
Merge pull request #407 from salmanja/013-jan-1-joyride
Browse files Browse the repository at this point in the history
adding page tour to dashboard/home page
  • Loading branch information
MuhammadKhalilzadeh authored Jan 4, 2025
2 parents c2f0d0b + 6134d04 commit 31ac9c7
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 4 deletions.
127 changes: 127 additions & 0 deletions Clients/package-lock.json

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

1 change: 1 addition & 0 deletions Clients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"material-ui-popup-state": "^5.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-joyride": "^2.9.3",
"react-redux": "^9.1.2",
"react-router-dom": "^6.26.2",
"redux": "^5.0.1",
Expand Down
17 changes: 17 additions & 0 deletions Clients/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@
body {
margin: 0;
}

/* preventing joyride default container from disrupting page layout */
div.react-joyride {
position: absolute !important;
top: 0;
left:0;
width:100%;
height:100%;
pointer-events:none;
z-index: 1000;
}

div.react-joyride > * {
margin: 0;
padding:0;
box-sizing: border-box;
}
51 changes: 51 additions & 0 deletions Clients/src/presentation/components/PageTour/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Joyride, {Step} from 'react-joyride';
import React, {useEffect, useState} from 'react';

interface PageTourProps {
steps: Step[];
run: boolean;
onFinish?:()=>void;
}

const PageTour: React.FC<PageTourProps> =({steps, run, onFinish}) => {
const [shouldRun, setShouldRun] = useState(false);

useEffect (()=>{
//always check if tour was seen first before running it
const hasSeenTour = localStorage.getItem("hasSeenTour");
if(!hasSeenTour && run){
setShouldRun(true);
}
}, [run])

const handleCallback = (data:any)=>{
const {status} = data;
if (status === 'finished' || status === 'skipped'){
localStorage.setItem("hasSeenTour", "true");
setShouldRun(false);
if (onFinish){
onFinish();
}
}
}

return (
<Joyride
steps={steps}
run={shouldRun}
continuous
hideCloseButton
showProgress
showSkipButton
callback={handleCallback}
styles={{
options: {
primaryColor: "rgba(23, 92, 211, 1)",
zIndex: 1000,
beaconSize: 20,
},
}}
/>
);
}
export default PageTour;
1 change: 1 addition & 0 deletions Clients/src/presentation/components/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Popup: FC<PopupProps> = ({
onClick={handleOpenOrClose}
sx={styles.openPopupButton}
disableRipple={theme.components?.MuiButton?.defaultProps?.disableRipple}
data-joyride-id="new-project-button"
>
{openPopupButtonName}
</Button>
Expand Down
6 changes: 4 additions & 2 deletions Clients/src/presentation/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const Sidebar = ({ projects }: { projects: any }) => {
return (
<Stack
component="aside"
className={collapsed ? "collapsed" : "expanded"}
className={`sidebar-menu ${collapsed ? "collapsed" : "expanded"}`}
py={theme.spacing(6)}
gap={theme.spacing(6)}
sx={{
Expand All @@ -170,7 +170,8 @@ const Sidebar = ({ projects }: { projects: any }) => {
pb={theme.spacing(12)}
pl={theme.spacing(12)}
>
<Stack direction="row" alignItems="center" gap={theme.spacing(4)}>
<Stack direction="row" alignItems="center" gap={theme.spacing(4)}
className="app-title">
<img src={Logo} alt="Logo" width={32} height={30} />
<Typography
component="span"
Expand Down Expand Up @@ -279,6 +280,7 @@ const Sidebar = ({ projects }: { projects: any }) => {
? "selected-path"
: "unselected"
}
data-joyride-id={item.name.toLowerCase().replace(/ /g, "-")}
onClick={() => navigate(`${item.path}`)}
sx={{
height: "37px",
Expand Down
51 changes: 51 additions & 0 deletions Clients/src/presentation/containers/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,49 @@ import {
getEntityById,
getAllEntities,
} from "../../../application/repository/entity.repository";
import PageTour from "../../components/PageTour";

const Dashboard = () => {
const { token, setDashboardValues } = useContext(VerifyWiseContext);
const [projects, setProjects] = useState([]);
const [_, setUsers] = useState([]);

const [runTour, setRunTour] = useState(false);
//joyride steps
const steps = [
// Sidebar steps
{
target: '[data-joyride-id="dashboard"]',
content:
"This is the Dashboard section. Click here to view the overview.",
},
{
target: '[data-joyride-id="compliance-tracker"]',
content: "Track your compliance status here.",
},
{
target: '[data-joyride-id="assessment-tracker"]',
content: "Track your assessments here.",
},
{
target: '[data-joyride-id="vendors"]',
content: "Manage your vendors here.",
},
{
target: '[data-joyride-id="file-manager"]',
content: "Access your files in the File Manager.",
},
// Home Page steps
{
target: '[data-joyride-id="project-overview"]',
content: "This section gives you an overview of all your projects.",
},
{
target: '[data-joyride-id="new-project-button"]',
content: "Click here to create a new project.",
},
];

useEffect(() => {
const fetchProjects = async () => {
try {
Expand Down Expand Up @@ -45,6 +82,13 @@ const Dashboard = () => {
fetchUsers();
}, [setDashboardValues]);

useEffect(() => {
//start tour only after projects load
if (projects.length > 0) {
setRunTour(true);
}
}, [projects]);

const mappedProjects = projects.map((project: any) => ({
_id: project.id,
name: project.project_title,
Expand All @@ -61,6 +105,13 @@ const Dashboard = () => {
sx={{ backgroundColor: "#FCFCFD" }}
>
<Sidebar projects={mappedProjects} />

{/* Joyride */}
<PageTour
steps={steps}
run={runTour}
onFinish={() => setRunTour(false)}
/>
<Outlet />
</Stack>
);
Expand Down
Loading

0 comments on commit 31ac9c7

Please sign in to comment.