Skip to content

Commit

Permalink
refactor: ajouter activité bénéficiaire dans portefeuille context
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzem committed Dec 12, 2024
1 parent 0c5dfb5 commit 50b05c1
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function CreationBeneficiaireFranceTravailPage(): ReactElement {
email: nouveauBeneficiaire.email,
})

setPortefeuille(portefeuille.concat(beneficiaireCree))
setPortefeuille(
portefeuille.concat({ ...beneficiaireCree, estAArchiver: false })
)
setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id)
router.push('/mes-jeunes')
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function CreationBeneficiaireMiloPage() {
surcharge
)

setPortefeuille(portefeuille.concat(beneficiaireCree))
setPortefeuille(
portefeuille.concat({ ...beneficiaireCree, estAArchiver: false })
)
setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id)
router.push('/mes-jeunes')
router.refresh()
Expand Down
26 changes: 25 additions & 1 deletion fixtures/beneficiaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BeneficiaireAvecCompteursActionsRdvs,
BeneficiaireEtChat,
BeneficiaireFromListe,
BeneficiaireWithActivity,
CategorieSituation,
Chat,
ConseillerHistorique,
Expand Down Expand Up @@ -34,6 +35,17 @@ export const uneBaseBeneficiaire = (
}
return { ...defaults, ...overrides }
}
export const unBeneficiaireWithActivity = (
overrides: Partial<BeneficiaireWithActivity> = {}
): BeneficiaireWithActivity => {
const defaults: BeneficiaireWithActivity = {
id: 'beneficiaire-1',
prenom: 'Kenji',
nom: 'Jirac',
estAArchiver: false,
}
return { ...defaults, ...overrides }
}

export const unDetailBeneficiaire = (
overrides: Partial<DetailBeneficiaire> = {}
Expand Down Expand Up @@ -103,7 +115,7 @@ export const unItemBeneficiaire = (
overrides: Partial<BeneficiaireFromListe> = {}
): BeneficiaireFromListe => {
const defaults: BeneficiaireFromListe = {
...uneBaseBeneficiaire(),
...unBeneficiaireWithActivity(),
isActivated: true,
isReaffectationTemporaire: false,
lastActivity: '2021-12-07T17:30:07.756Z',
Expand Down Expand Up @@ -167,6 +179,7 @@ export const unItemBeneficiaireJson = (
id: 'beneficiaire-1',
firstName: 'Kenji',
lastName: 'Jirac',
estAArchiver: false,
isActivated: true,
isReaffectationTemporaire: false,
lastActivity: '2021-12-07T17:30:07.756Z',
Expand Down Expand Up @@ -317,6 +330,17 @@ export function extractBaseBeneficiaire(
return { id: base.id, nom: base.nom, prenom: base.prenom }
}

export function extractBeneficiaireWithActivity(
beneficiaire: BeneficiaireWithActivity
): BeneficiaireWithActivity {
return {
...extractBaseBeneficiaire(beneficiaire),
estAArchiver: beneficiaire.estAArchiver,
lastActivity: beneficiaire.lastActivity,
dateFinCEJ: beneficiaire.dateFinCEJ,
}
}

export const desIndicateursSemaineJson = (
overrides: Partial<IndicateursSemaineJson> = {}
): IndicateursSemaineJson => {
Expand Down
10 changes: 7 additions & 3 deletions interfaces/beneficiaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ export interface BaseBeneficiaire {
nom: string
}

export interface BeneficiaireFromListe extends BaseBeneficiaire {
export interface BeneficiaireWithActivity extends BaseBeneficiaire {
estAArchiver: boolean
lastActivity?: string
dateFinCEJ?: string
}

export interface BeneficiaireFromListe extends BeneficiaireWithActivity {
isActivated: boolean
isReaffectationTemporaire: boolean
lastActivity?: string
conseillerPrecedent?: {
nom: string
prenom: string
email?: string
}
situationCourante: CategorieSituation
structureMilo?: { id: string }
dateFinCEJ?: string
}

export interface DetailBeneficiaire extends BaseBeneficiaire {
Expand Down
1 change: 1 addition & 0 deletions interfaces/json/beneficiaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface BaseBeneficiaireJson {
export interface ItemBeneficiaireJson extends BaseBeneficiaireJson {
isActivated: boolean
isReaffectationTemporaire: boolean
estAArchiver: boolean
lastActivity?: string
situationCourante?: Situation
dateFinCEJ?: string
Expand Down
1 change: 1 addition & 0 deletions interfaces/json/conseiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ConseillerJson {
}
notificationsSonores: boolean
aDesBeneficiairesARecuperer: boolean
beneficiairesAArchiver?: number
dateSignatureCGU?: string
dateVisionnageActus?: string
}
Expand Down
3 changes: 2 additions & 1 deletion tests/pages/CreationBeneficiaireMiloPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CreationBeneficiaireMiloPage from 'app/(connected)/(with-sidebar)/(with-c
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
unBeneficiaireWithActivity,
uneBaseBeneficiaire,
} from 'fixtures/beneficiaire'
import { unDossierMilo } from 'fixtures/milo'
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('CreationBeneficiaireMiloPage client side', () => {

expect(setPortefeuille).toHaveBeenCalledWith([
...portefeuille,
uneBaseBeneficiaire(),
unBeneficiaireWithActivity(),
])
expect(setAlerte).toHaveBeenCalledWith(
'creationBeneficiaire',
Expand Down
6 changes: 1 addition & 5 deletions tests/pages/pilotage/PilotagePage.sessions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import { act, screen, within } from '@testing-library/react'
import { AxeResults } from 'axe-core'
import { axe } from 'jest-axe'
import { useRouter } from 'next/navigation'
import React from 'react'

import Pilotage from 'app/(connected)/(with-sidebar)/(with-chat)/pilotage/PilotagePage'
import { desCategories } from 'fixtures/action'
import { uneListeDeSessionsAClore } from 'fixtures/session'
import { StructureConseiller } from 'interfaces/conseiller'
import {
getSessionsACloreServerSide,
SessionsAClore,
} from 'services/sessions.service'
import { getSessionsACloreServerSide } from 'services/sessions.service'
import getByDescriptionTerm from 'tests/querySelector'
import renderWithContexts from 'tests/renderWithContexts'

Expand Down
19 changes: 11 additions & 8 deletions tests/renderWithContexts.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { render, RenderResult } from '@testing-library/react'
import React, { Dispatch, ReactNode, SetStateAction } from 'react'
import { Dispatch, ReactNode, SetStateAction } from 'react'

import { uneActualite } from 'fixtures/actualites'
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
extractBeneficiaireWithActivity,
} from 'fixtures/beneficiaire'
import { unConseiller } from 'fixtures/conseiller'
import { ActualitesParsees } from 'interfaces/actualites'
import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire'
import {
BeneficiaireEtChat,
BeneficiaireWithActivity,
} from 'interfaces/beneficiaire'
import { Conseiller } from 'interfaces/conseiller'
import { AlerteParam } from 'referentiel/alerteParam'
import { ActualitesProvider } from 'utils/actualitesContext'
Expand All @@ -32,8 +35,8 @@ export default function renderWithContexts(
options: {
customConseiller?: Partial<Conseiller>
customPortefeuille?: Partial<{
value: BaseBeneficiaire[]
setter: (portefeuille: BaseBeneficiaire[]) => void
value: BeneficiaireWithActivity[]
setter: (portefeuille: BeneficiaireWithActivity[]) => void
}>
customChats?: BeneficiaireEtChat[]
customCurrentConversation?: Partial<{
Expand Down Expand Up @@ -71,7 +74,7 @@ export default function renderWithContexts(
...customPortefeuille,
value:
customPortefeuille?.value ??
desItemsBeneficiaires().map(extractBaseBeneficiaire),
desItemsBeneficiaires().map(extractBeneficiaireWithActivity),
}

const currentConversation = { ...customCurrentConversation }
Expand Down Expand Up @@ -107,8 +110,8 @@ function provideContexts(
children: ReactNode,
conseiller: Conseiller,
portefeuille: Partial<{
value: BaseBeneficiaire[]
setter: (portefeuille: BaseBeneficiaire[]) => void
value: BeneficiaireWithActivity[]
setter: (portefeuille: BeneficiaireWithActivity[]) => void
}>,
chats: BeneficiaireEtChat[] | undefined,
currentConversation: Partial<{
Expand Down
5 changes: 4 additions & 1 deletion tests/utils/chatsContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
extractBeneficiaireWithActivity,
unBeneficiaireChat,
} from 'fixtures/beneficiaire'
import { unConseiller } from 'fixtures/conseiller'
Expand All @@ -24,7 +25,9 @@ global.Audio = class FakeAudio {

describe('ChatsProvider', () => {
let updateChatsRef: (chats: BeneficiaireEtChat[]) => void
const portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire)
const portefeuille = desItemsBeneficiaires().map(
extractBeneficiaireWithActivity
)
const conversations = [
unBeneficiaireChat({
...portefeuille[0],
Expand Down
1 change: 1 addition & 0 deletions tsconfig.tsbuildinfo

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions utils/AppContextProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { apm } from '@elastic/apm-rum'
import { ThemeProvider } from 'next-themes'
import React, { ReactNode } from 'react'

import { extractBaseBeneficiaire } from 'fixtures/beneficiaire'
import {
extractBaseBeneficiaire,
extractBeneficiaireWithActivity,
} from 'fixtures/beneficiaire'
import {
BeneficiaireFromListe,
compareBeneficiairesByNom,
Expand All @@ -31,7 +34,7 @@ export default function AppContextProviders({
children: ReactNode
}) {
const portefeuilleTrie = portefeuille
.map(extractBaseBeneficiaire)
.map(extractBeneficiaireWithActivity)
.sort(compareBeneficiairesByNom)

const theme = estPassEmploi(conseiller) ? 'darker' : 'neutral'
Expand Down
13 changes: 7 additions & 6 deletions utils/portefeuilleContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import { createContext, ReactNode, useContext, useState } from 'react'

import { BaseBeneficiaire } from 'interfaces/beneficiaire'
import { BeneficiaireWithActivity } from 'interfaces/beneficiaire'

type PortefeuilleState = [
BaseBeneficiaire[],
(updatedBeneficiaires: BaseBeneficiaire[]) => void,
BeneficiaireWithActivity[],
(updatedBeneficiaires: BeneficiaireWithActivity[]) => void,
]

const PortefeuilleContext = createContext<PortefeuilleState | undefined>(
Expand All @@ -19,10 +19,11 @@ export function PortefeuilleProvider({
setterForTests,
}: {
children: ReactNode
portefeuille: BaseBeneficiaire[]
setterForTests?: (updatedBeneficiaires: BaseBeneficiaire[]) => void
portefeuille: BeneficiaireWithActivity[]
setterForTests?: (updatedBeneficiaires: BeneficiaireWithActivity[]) => void
}) {
const [state, setPortefeuille] = useState<BaseBeneficiaire[]>(portefeuille)
const [state, setPortefeuille] =
useState<BeneficiaireWithActivity[]>(portefeuille)
const setter = setterForTests ?? setPortefeuille

return (
Expand Down

0 comments on commit 50b05c1

Please sign in to comment.