2024-03-18 13:58:05 +01:00
|
|
|
import { useState, type VFC } from 'react';
|
2024-03-04 12:56:17 +01:00
|
|
|
import { Box, styled } from '@mui/material';
|
|
|
|
import { ArrayParam, withDefault } from 'use-query-params';
|
|
|
|
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
2024-03-01 13:28:57 +01:00
|
|
|
import {
|
|
|
|
allOption,
|
2024-03-04 12:56:17 +01:00
|
|
|
ProjectSelect,
|
|
|
|
} from 'component/common/ProjectSelect/ProjectSelect';
|
|
|
|
import { useExecutiveDashboard } from 'hooks/api/getters/useExecutiveSummary/useExecutiveSummary';
|
|
|
|
import { DashboardHeader } from './components/DashboardHeader/DashboardHeader';
|
2024-03-20 08:24:56 +01:00
|
|
|
import { useDashboardData } from './hooks/useDashboardData';
|
|
|
|
import { Charts } from './Charts';
|
|
|
|
|
|
|
|
const StickyWrapper = styled(Box)<{ scrolled?: boolean }>(
|
|
|
|
({ theme, scrolled }) => ({
|
|
|
|
position: 'sticky',
|
|
|
|
top: 0,
|
|
|
|
zIndex: 1000,
|
|
|
|
padding: scrolled ? theme.spacing(2, 0) : theme.spacing(0, 0, 2),
|
|
|
|
background: theme.palette.background.application,
|
|
|
|
transition: 'padding 0.3s ease',
|
|
|
|
}),
|
|
|
|
);
|
2024-03-14 10:33:30 +01:00
|
|
|
|
2024-01-18 12:32:25 +01:00
|
|
|
export const ExecutiveDashboard: VFC = () => {
|
2024-03-14 10:33:30 +01:00
|
|
|
const [scrolled, setScrolled] = useState(false);
|
2024-01-26 09:03:12 +01:00
|
|
|
const { executiveDashboardData, loading, error } = useExecutiveDashboard();
|
2024-03-04 12:56:17 +01:00
|
|
|
const stateConfig = {
|
|
|
|
projects: withDefault(ArrayParam, [allOption.id]),
|
|
|
|
};
|
2024-03-06 12:19:27 +01:00
|
|
|
const [state, setState] = usePersistentTableState('insights', stateConfig);
|
2024-03-04 12:56:17 +01:00
|
|
|
const setProjects = (projects: string[]) => {
|
|
|
|
setState({ projects });
|
|
|
|
};
|
|
|
|
const projects = state.projects
|
|
|
|
? (state.projects.filter(Boolean) as string[])
|
|
|
|
: [];
|
2024-03-15 09:37:02 +01:00
|
|
|
|
2024-03-20 08:24:56 +01:00
|
|
|
const dashboardData = useDashboardData(executiveDashboardData, projects);
|
2024-01-30 10:07:16 +01:00
|
|
|
|
2024-03-14 10:33:30 +01:00
|
|
|
const handleScroll = () => {
|
|
|
|
if (!scrolled && window.scrollY > 0) {
|
|
|
|
setScrolled(true);
|
|
|
|
} else if (scrolled && window.scrollY === 0) {
|
|
|
|
setScrolled(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.addEventListener('scroll', handleScroll);
|
|
|
|
}
|
|
|
|
|
2024-01-22 11:07:38 +01:00
|
|
|
return (
|
|
|
|
<>
|
2024-03-14 10:33:30 +01:00
|
|
|
<StickyWrapper scrolled={scrolled}>
|
2024-03-04 12:56:17 +01:00
|
|
|
<DashboardHeader
|
|
|
|
actions={
|
|
|
|
<ProjectSelect
|
|
|
|
selectedProjects={projects}
|
|
|
|
onChange={setProjects}
|
|
|
|
dataTestId={'DASHBOARD_PROJECT_SELECT'}
|
2024-03-06 12:19:27 +01:00
|
|
|
sx={{ flex: 1, maxWidth: '360px', width: '100%' }}
|
2024-03-04 12:56:17 +01:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2024-03-14 10:33:30 +01:00
|
|
|
</StickyWrapper>
|
2024-03-20 08:24:56 +01:00
|
|
|
<Charts loading={loading} projects={projects} {...dashboardData} />
|
2024-01-22 11:07:38 +01:00
|
|
|
</>
|
|
|
|
);
|
2024-01-18 12:32:25 +01:00
|
|
|
};
|