Skip to content

Commit

Permalink
logout with query
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Jun 7, 2024
1 parent dc6091c commit 4532dd1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 66 deletions.
5 changes: 1 addition & 4 deletions src/pages/Collect/CollectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ import type {
Nomenclature,
} from 'shared/components/Orchestrator/utils/lunaticType'
import { useDocumentTitle } from 'shared/hooks/useDocumentTitle'
import { useSetLogoutQuestionnaire } from 'shared/hooks/useLogoutUrl'
import { collectRoute } from './route'

export function CollectPage() {
const { surveyUnitId, questionnaireId } = collectRoute.useParams()
const { surveyUnitId } = collectRoute.useParams()
const queryClient = useQueryClient()

useSetLogoutQuestionnaire(questionnaireId)

const loaderResults = collectRoute.useLoaderData()

//TODO -> use Metadata
Expand Down
13 changes: 7 additions & 6 deletions src/pages/Collect/route.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { LunaticSource } from '@inseefr/lunatic'
import { createRoute } from '@tanstack/react-router'
import { getGetQuestionnaireDataQueryOptions } from 'api/03-questionnaires'
import { getGetMetadataByQuestionnaireIdQueryOptions } from 'api/05-metadata'
import { getGetSurveyUnitByIdQueryOptions } from 'api/06-survey-units'
import {
getGetSurveyUnitByIdQueryOptions,
getGetSurveyUnitMetadataByIdQueryOptions,
} from 'api/06-survey-units'
import type { SurveyUnitData } from 'model/SurveyUnitData'
import { rootRoute } from 'router/router'
import { ErrorComponent } from 'shared/components/Error/ErrorComponent'
Expand All @@ -11,8 +13,8 @@ import { z } from 'zod'
import { CollectPage } from './CollectPage'

const collectSearchParams = z.object({
pathLogout: z.string(),
pathAssistance: z.string(),
pathLogout: z.string().optional(),
pathAssistance: z.string().optional(),
})

export const collectPath =
Expand Down Expand Up @@ -45,9 +47,8 @@ export const collectRoute = createRoute({
)
.then((suData) => suData as SurveyUnitData) // data are heavy too

//TODO use metadata and type
const metadataPr = queryClient.ensureQueryData(
getGetMetadataByQuestionnaireIdQueryOptions(questionnaireId, {
getGetSurveyUnitMetadataByIdQueryOptions(surveyUnitId, {
request: { signal: abortController.signal },
})
)
Expand Down
2 changes: 2 additions & 0 deletions src/router/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function Footer() {
title="licence MIT - nouvelle fenêtre"
href="https://github.com/InseeFrLab/stromae-dsfr/blob/main/LICENSE"
target="_blank"
rel="noreferrer"
>
licence MIT
</a>
Expand All @@ -29,6 +30,7 @@ export function Footer() {
href="https://github.com/etalab/licence-ouverte/blob/master/LO.md"
title="licence etalab-2.0 - nouvelle fenêtre"
target="_blank"
rel="noreferrer"
>
licence etalab-2.0
</a>
Expand Down
19 changes: 15 additions & 4 deletions src/router/Layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { Badge } from '@codegouvfr/react-dsfr/Badge'
import { headerFooterDisplayItem } from '@codegouvfr/react-dsfr/Display'
import { Header as DsfrHeader } from '@codegouvfr/react-dsfr/Header'
import { useMatchRoute, useSearch } from '@tanstack/react-router'
import logoInsee from 'assets/logo-insee.png'
import { useOidc } from 'oidc'
import { collectPath } from 'pages/Collect/route'
import { executePreLogoutActions } from 'shared/hooks/prelogout'
import { useLogoutUrl } from 'shared/hooks/useLogoutUrl'

export function Header() {
const { isUserLoggedIn, logout } = useOidc()

const logoutUrl = useLogoutUrl()
/**
* There is an issue with this part of code, search is not will type inferred with isCollectRoute, waiting for better solution
*/
const matchRoute = useMatchRoute()
const isCollectRoute = !!matchRoute({ to: collectPath })
const search = useSearch({ strict: false })

return (
<DsfrHeader
brandTop={
Expand All @@ -29,7 +36,10 @@ export function Header() {
{
iconId: 'fr-icon-mail-fill',
linkProps: {
href: 'mailto:mail@assistance.fr',
href: collectPath
? `${import.meta.env.VITE_PORTAIL_URL}${(search as any)['pathAssistance'] ?? ''}`
: '',
disabled: isCollectRoute,
},
text: "Contacter l'assistance",
},
Expand All @@ -43,9 +53,10 @@ export function Header() {
await executePreLogoutActions()
logout({
redirectTo: 'specific url',
url: logoutUrl,
url: `${import.meta.env.VITE_PORTAIL_URL}${(search as any)['pathLogout'] ?? ''}`,
})
},
disabled: !isCollectRoute,
},
text: 'Se déconnecter',
} as const,
Expand Down
13 changes: 5 additions & 8 deletions src/router/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { PropsWithChildren } from 'react'
import { LogoutPathProvider } from 'shared/hooks/useLogoutUrl'
import { Footer } from './Footer'
import { Header } from './Header'

Expand All @@ -9,13 +8,11 @@ export function Layout(props: PropsWithChildren) {
<div
style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column' }}
>
<LogoutPathProvider>
<Header />
<main id="contenu" role="main">
{children}
</main>
<Footer />
</LogoutPathProvider>
<Header />
<main id="contenu" role="main">
{children}
</main>
<Footer />
</div>
)
}
44 changes: 0 additions & 44 deletions src/shared/hooks/useLogoutUrl.tsx

This file was deleted.

0 comments on commit 4532dd1

Please sign in to comment.