diff --git a/src/client/services/cookies/cookies.service.fixture.ts b/src/client/services/cookies/cookies.service.fixture.ts index 777b5d7f42..0b07edac85 100644 --- a/src/client/services/cookies/cookies.service.fixture.ts +++ b/src/client/services/cookies/cookies.service.fixture.ts @@ -7,6 +7,7 @@ export function aCookiesService(override?: Partial): CookiesServ allowService: jest.fn(), isServiceAllowed: jest.fn(() => true), openPanel: jest.fn(), + triggerJobs: jest.fn(), ...override, }; } diff --git a/src/client/services/cookies/cookies.service.ts b/src/client/services/cookies/cookies.service.ts index a45adcc696..57c260cac8 100644 --- a/src/client/services/cookies/cookies.service.ts +++ b/src/client/services/cookies/cookies.service.ts @@ -13,4 +13,6 @@ export interface CookiesService { allowService(nom: string): void; openPanel(): void; + + triggerJobs(): void; } diff --git a/src/client/services/cookies/null/null.cookies.service.ts b/src/client/services/cookies/null/null.cookies.service.ts index cf6c849b24..2321eb1ea6 100644 --- a/src/client/services/cookies/null/null.cookies.service.ts +++ b/src/client/services/cookies/null/null.cookies.service.ts @@ -20,4 +20,8 @@ export class NullCookiesService implements CookiesService { openPanel(): void { return; } + + triggerJobs(): void { + return; + } } diff --git a/src/client/services/cookies/tarteaucitron/tarteAuCitron.cookies.service.ts b/src/client/services/cookies/tarteaucitron/tarteAuCitron.cookies.service.ts index 1baa4805a1..5e8cf545a8 100644 --- a/src/client/services/cookies/tarteaucitron/tarteAuCitron.cookies.service.ts +++ b/src/client/services/cookies/tarteaucitron/tarteAuCitron.cookies.service.ts @@ -17,6 +17,7 @@ export type TarteAuCitron = { openPanel: () => void, } state: Record; + triggerJobsAfterAjaxCall: () => void; } export class TarteAuCitronCookiesService implements CookiesService { @@ -87,4 +88,8 @@ export class TarteAuCitronCookiesService implements CookiesService { openPanel(): void { return this.tarteaucitron.userInterface.openPanel(); } + + triggerJobs(): void { + return this.tarteaucitron.triggerJobsAfterAjaxCall(); + } } diff --git a/src/client/services/cookies/tarteaucitron/tarteAuCitron.fixture.ts b/src/client/services/cookies/tarteaucitron/tarteAuCitron.fixture.ts index 505003f421..16a6c27108 100644 --- a/src/client/services/cookies/tarteaucitron/tarteAuCitron.fixture.ts +++ b/src/client/services/cookies/tarteaucitron/tarteAuCitron.fixture.ts @@ -6,6 +6,7 @@ export function aTarteAuCitron(override?: Partial): TarteAuCitron job: undefined, services: {}, state: {}, + triggerJobsAfterAjaxCall: jest.fn(), user: {}, userInterface: { openPanel: jest.fn(), diff --git a/src/pages/_app.page.tsx b/src/pages/_app.page.tsx index 1bf08abea7..42a9a11b84 100644 --- a/src/pages/_app.page.tsx +++ b/src/pages/_app.page.tsx @@ -46,20 +46,14 @@ export default function App({ Component, pageProps }: AppPropsWithLayout) { const previousPath = useRef(''); + const cookiesService = dependenciesContainerInstance.cookiesService; useEffect(() => { - // eslint-disable-next-line - console.log(previousPath.current, router.asPath); if (previousPath.current && previousPath.current !== router.asPath) { - // eslint-disable-next-line - console.log('trigger jobs'); - // FIXME (GAFI 08-10-2024): Déplacer dans le service - // eslint-disable-next-line - // @ts-ignore - window.tarteaucitron.triggerJobsAfterAjaxCall(); + cookiesService.triggerJobs(); } previousPath.current = router.asPath; return () => { document.dispatchEvent(new Event('navigate')); }; - }, [router.asPath, sessionId]); + }, [cookiesService, router.asPath, sessionId]); const getLayout = Component.getLayout ?? defaultLayout; return (