-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mise en place de la pagination pour les admins sur la liste des inven…
…taires
- Loading branch information
Showing
12 changed files
with
388 additions
and
96 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 |
---|---|---|
@@ -1,23 +1,39 @@ | ||
import { inventaireModel } from '@prisma/client' | ||
import { Metadata } from 'next' | ||
import { ReactElement } from 'react' | ||
|
||
import { getProfilAtih } from '../../../../authentification' | ||
import InventairesLayout from '../../../../components/Inventaires/InventairesLayout' | ||
import { inventairesPresenter } from '../../../../presenters/inventairesPresenter' | ||
import { recupererLesInventairesRepository } from '../../../../repositories/inventairesRepository' | ||
import { recupererLeTotalInventairesRepository, recupererLesInventairesPaginesRepository, recupererLesInventairesRepository } from '../../../../repositories/inventairesRepository' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Inventaires', | ||
} | ||
|
||
export default async function PageInventaires(): Promise<ReactElement> { | ||
type PageProps = Readonly<{ | ||
searchParams?: Readonly<{ | ||
page?: string | ||
}> | ||
}> | ||
|
||
export default async function PageInventaires({ searchParams }: PageProps): Promise<ReactElement> { | ||
const profil = await getProfilAtih() | ||
const pageCourante = Number(searchParams?.page ?? 0) | ||
|
||
const inventairesModel = await recupererLesInventairesRepository(profil.nomEtablissement) | ||
// eslint-disable-next-line @typescript-eslint/init-declarations | ||
let inventairesModel: ReadonlyArray<inventaireModel> | ||
let totalInventaires = 0 | ||
if (profil.isAdmin) { | ||
inventairesModel = await recupererLesInventairesPaginesRepository(pageCourante) | ||
totalInventaires = await recupererLeTotalInventairesRepository() | ||
} else { | ||
inventairesModel = await recupererLesInventairesRepository(profil.nomEtablissement) | ||
} | ||
|
||
return ( | ||
<InventairesLayout | ||
presenter={inventairesPresenter(inventairesModel, profil)} | ||
presenter={inventairesPresenter(inventairesModel, profil, pageCourante, totalInventaires)} | ||
/> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -1,90 +1,102 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
import React, { ReactElement } from 'react' | ||
|
||
import ActionSupprimer from './ActionSupprimer' | ||
import styles from './Inventaires.module.css' | ||
import { InventairePresenter } from '../../presenters/inventairesPresenter' | ||
import { formaterLeNomEtablissement } from '../../presenters/sharedPresenter' | ||
import Pagination from '../sharedComponents/Pagination/Pagination' | ||
|
||
type InventairesProps = Readonly<{ | ||
inventaires: ReadonlyArray<InventairePresenter> | ||
isAdmin: boolean | ||
pageCourante: number | ||
totalInventaires: number | ||
}> | ||
|
||
export default function Inventaires({ inventaires }: InventairesProps): ReactElement { | ||
export default function Inventaires({ inventaires, isAdmin, pageCourante, totalInventaires }: InventairesProps): ReactElement { | ||
return ( | ||
<table className="table table-bordered"> | ||
<caption className="nav-skip"> | ||
Votre inventaire | ||
</caption> | ||
<thead> | ||
<tr> | ||
<th scope="col"> | ||
Nom de l’inventaire | ||
</th> | ||
<th scope="col"> | ||
Nom de l’organisation | ||
</th> | ||
<th scope="col"> | ||
Date de création | ||
</th> | ||
<th scope="col"> | ||
État | ||
</th> | ||
<th scope="col"> | ||
Action | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
inventaires.map((inventaire): ReactElement => { | ||
return ( | ||
<tr key={inventaire.id}> | ||
<td> | ||
<Link href={inventaire.lienIndicateursCles}> | ||
{inventaire.nomInventaire} | ||
</Link> | ||
</td> | ||
<td> | ||
{formaterLeNomEtablissement(inventaire.nomEtablissement)} | ||
</td> | ||
<td> | ||
{inventaire.dateInventaire} | ||
</td> | ||
<td> | ||
<span className={`${styles.pastille} ${styles[inventaire.className]} fz-16`}> | ||
{inventaire.statut} | ||
</span> | ||
</td> | ||
<td> | ||
{ | ||
inventaire.lienDupliquer !== '/' ? ( | ||
<Link | ||
className="text-default mr-2" | ||
href={inventaire.lienDupliquer} | ||
> | ||
<svg | ||
aria-hidden | ||
className="svg-icon" | ||
focusable="false" | ||
<> | ||
<table className="table table-bordered"> | ||
<caption className="nav-skip"> | ||
Votre inventaire | ||
</caption> | ||
<thead> | ||
<tr> | ||
<th scope="col"> | ||
Nom de l’inventaire | ||
</th> | ||
<th scope="col"> | ||
Nom de l’organisation | ||
</th> | ||
<th scope="col"> | ||
Date de création | ||
</th> | ||
<th scope="col"> | ||
État | ||
</th> | ||
<th scope="col"> | ||
Action | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
inventaires.map((inventaire): ReactElement => { | ||
return ( | ||
<tr key={inventaire.id}> | ||
<td> | ||
<Link href={inventaire.lienIndicateursCles}> | ||
{inventaire.nomInventaire} | ||
</Link> | ||
</td> | ||
<td> | ||
{formaterLeNomEtablissement(inventaire.nomEtablissement)} | ||
</td> | ||
<td> | ||
{inventaire.dateInventaire} | ||
</td> | ||
<td> | ||
<span className={`${styles.pastille} ${styles[inventaire.className]} fz-16`}> | ||
{inventaire.statut} | ||
</span> | ||
</td> | ||
<td> | ||
{ | ||
inventaire.lienDupliquer !== '/' ? ( | ||
<Link | ||
className="text-default mr-2" | ||
href={inventaire.lienDupliquer} | ||
> | ||
<use xlinkHref="/svg-icons/icon-sprite.svg#duplicate" /> | ||
</svg> | ||
<span className="sr-only"> | ||
Dupliquer l’inventaire | ||
</span> | ||
</Link> | ||
) : null | ||
} | ||
<ActionSupprimer inventaire={inventaire} /> | ||
</td> | ||
</tr> | ||
) | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
<svg | ||
aria-hidden | ||
className="svg-icon" | ||
focusable="false" | ||
> | ||
<use xlinkHref="/svg-icons/icon-sprite.svg#duplicate" /> | ||
</svg> | ||
<span className="sr-only"> | ||
Dupliquer l’inventaire | ||
</span> | ||
</Link> | ||
) : null | ||
} | ||
<ActionSupprimer inventaire={inventaire} /> | ||
</td> | ||
</tr> | ||
) | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
{ | ||
isAdmin ? ( | ||
<Pagination | ||
pageCourante={pageCourante} | ||
totalInventaires={totalInventaires} | ||
/> | ||
) : null | ||
} | ||
</> | ||
) | ||
} |
Oops, something went wrong.