Skip to content

Commit

Permalink
feat(frontend): add analysis dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Falinor committed Nov 14, 2024
1 parent a9d5e49 commit 7936561
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 33 deletions.
12 changes: 9 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ import UsersView from './views/Users/UsersView';
import TerritoryEstablishmentsView from './views/TerritoryEstablishments/TerritoryEstablishmentsView';
import SmallHeader from './components/Header/SmallHeader';
import Header from './components/Header/Header';
import AnalysisView from './views/Analysis/AnalysisView';

const authenticatedRoutes: RouteProps[] = [
{
path: '/parc-de-logements',
component: HousingListView
},
{
path: '/analyses',
component: AnalysisView
},
// TODO: remove this
{ path: '/parc-de-logements/campagnes/:id', component: CampaignView },
{ path: '/groupes/:id', component: GroupView },
Expand Down Expand Up @@ -100,15 +105,16 @@ function App() {
}
}, [dispatch, isSomeQueryPending]);

const routes = (isAuthenticated ? authenticatedRoutes : guestRoutes)
.map((route) => (
const routes = (isAuthenticated ? authenticatedRoutes : guestRoutes).map(
(route) => (
<Route
exact
path={route.path}
component={route.component}
key={`route_${route.path}`}
/>
));
)
);

const redirection = isAuthenticated ? '/parc-de-logements' : '/connexion';

Expand Down
32 changes: 13 additions & 19 deletions frontend/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Header as DSFRHeader } from '@codegouvfr/react-dsfr/Header';
import { useMatomo } from '@jonkoops/matomo-tracker-react';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import LoadingBar from 'react-redux-loading-bar';

Expand All @@ -17,15 +15,10 @@ import { Container } from '../_dsfr';
function Header() {
const location = useLocation();
const dispatch = useAppDispatch();
const { trackPageView } = useMatomo();
const { isAdmin, isVisitor, isAuthenticated } = useUser();

const { authUser } = useAppSelector((state) => state.authentication);

useEffect(() => {
trackPageView({});
}, [location]); //eslint-disable-line react-hooks/exhaustive-deps

function displayName(): string {
return authUser
? authUser.user.firstName && authUser.user.lastName
Expand All @@ -40,11 +33,11 @@ function Header() {
linkProps: {
to: getUserNavItem(navItem).url,
'data-testid': `fr-header-nav-item-${getUserNavItem(
navItem,
).url.substring(1)}`,
navItem
).url.substring(1)}`
},
text: getUserNavItem(navItem).label,
isActive: location.pathname.startsWith(getUserNavItem(navItem).url),
isActive: location.pathname.startsWith(getUserNavItem(navItem).url)
});

return (
Expand All @@ -55,23 +48,23 @@ function Header() {
Ministère <br />
du Logement <br />
et de la Rénovation <br />
urbaine
urbaine
</>
}
homeLinkProps={{
to: '/',
title: 'Accueil - Zéro Logement Vacant',
title: 'Accueil - Zéro Logement Vacant'
}}
serviceTitle="Zéro Logement Vacant"
serviceTagline={
isAuthenticated ? (
(isAdmin || isVisitor) ? (
isAdmin || isVisitor ? (
<EstablishmentSearchableSelect
initialEstablishmentOption={
authUser
? {
value: authUser.establishment.id,
label: authUser.establishment.name,
label: authUser.establishment.name
}
: undefined
}
Expand Down Expand Up @@ -104,24 +97,25 @@ function Header() {
<AccountSideMenu />
</Container>
}
/>,
/>
]
: [
{
iconId: 'fr-icon-user-fill',
linkProps: {
to: '/connexion',
to: '/connexion'
},
text: 'Connexion',
},
text: 'Connexion'
}
]
}
navigation={
isAuthenticated
? [
getMainNavigationItem(UserNavItems.HousingList),
getMainNavigationItem(UserNavItems.Analysis),
getMainNavigationItem(UserNavItems.Campaign),
getMainNavigationItem(UserNavItems.Resources),
getMainNavigationItem(UserNavItems.Resources)
]
: withNavItems && []
}
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/components/Header/SmallHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Button from '@codegouvfr/react-dsfr/Button';
import {
MainNavigation,
MainNavigationProps,
MainNavigationProps
} from '@codegouvfr/react-dsfr/MainNavigation';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
Expand All @@ -23,18 +23,19 @@ import logo from '../../assets/images/zlv.svg';
function SmallHeader() {
const dispatch = useAppDispatch();
const location = useLocation();
const { displayName, establishment, isAdmin, isVisitor, isAuthenticated } = useUser();
const { displayName, establishment, isAdmin, isVisitor, isAuthenticated } =
useUser();

function getMainNavigationItem(
navItem: UserNavItems,
navItem: UserNavItems
): MainNavigationProps.Item {
const link = getUserNavItem(navItem);
return {
linkProps: {
to: link.url,
to: link.url
},
text: link.label,
isActive: location.pathname.startsWith(link.url),
isActive: location.pathname.startsWith(link.url)
};
}

Expand All @@ -45,7 +46,7 @@ function SmallHeader() {
square
sx={(theme) => ({
position: 'sticky',
zIndex: theme.zIndex.appBar,
zIndex: theme.zIndex.appBar
})}
>
<Grid
Expand All @@ -69,27 +70,28 @@ function SmallHeader() {
classes={{
root: styles.root,
list: styles.linkList,
link: styles.link,
link: styles.link
}}
items={
isAuthenticated
? [
getMainNavigationItem(UserNavItems.HousingList),
getMainNavigationItem(UserNavItems.Analysis),
getMainNavigationItem(UserNavItems.Campaign),
getMainNavigationItem(UserNavItems.Resources),
getMainNavigationItem(UserNavItems.Resources)
]
: []
}
/>
<Grid alignItems="center" display="flex" ml="auto">
{isAuthenticated ? (
(isAdmin || isVisitor) ? (
isAdmin || isVisitor ? (
<EstablishmentSearchableSelect
initialEstablishmentOption={
establishment
? {
value: establishment.id,
label: establishment.name,
label: establishment.name
}
: undefined
}
Expand Down Expand Up @@ -124,7 +126,7 @@ function SmallHeader() {
<Button
iconId="fr-icon-user-fill"
linkProps={{
to: '/connexion',
to: '/connexion'
}}
priority="tertiary no outline"
size="small"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/models/UserNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum UserNavItems {
Campaign,
HousingList,
Resources,
Analysis
}

export interface UserNavItem {
Expand All @@ -17,6 +18,8 @@ export const getUserNavItem = (userNavItem: UserNavItems): UserNavItem => {
return { url: '/parc-de-logements', label: 'Parc de logements' };
case UserNavItems.Resources:
return { url: '/ressources', label: 'Ressources' };
case UserNavItems.Analysis:
return { url: '/analyses', label: 'Analyses' };
default:
return { url: '/', label: 'Accueil' };
}
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/views/Analysis/AnalysisView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Skeleton from '@mui/material/Skeleton';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';

import { useDocumentTitle } from '../../hooks/useDocumentTitle';
import MainContainer from '../../components/MainContainer/MainContainer';

function AnalysisView() {
useDocumentTitle('Analyse');

const isLoading = true;

return (
<MainContainer>
{isLoading ? <Loading /> : <Typography variant="h1">Analyse</Typography>}
</MainContainer>
);
}

function Loading() {
return (
<Stack spacing={1} width="100%">
<Skeleton animation="wave" height={600} variant="rectangular" />
</Stack>
);
}

export default AnalysisView;

0 comments on commit 7936561

Please sign in to comment.