2022-03-03 13:37:53 +00:00
|
|
|
import { ThemeColorsProvider } from '@/components/utils/colors'
|
|
|
|
import { DisableAnimationOnPrintProvider } from '@/components/utils/DisableAnimationContext'
|
|
|
|
import { IsEmbeddedProvider } from '@/components/utils/embeddedContext'
|
|
|
|
import { GlobalStyle } from '@/design-system/global-style'
|
|
|
|
import { Container } from '@/design-system/layout'
|
|
|
|
import DesignSystemThemeProvider from '@/design-system/root'
|
|
|
|
import { H1 } from '@/design-system/typography/heading'
|
|
|
|
import { Link } from '@/design-system/typography/link'
|
|
|
|
import { Body, Intro } from '@/design-system/typography/paragraphs'
|
|
|
|
import { useIframeResizer } from '@/hooks/useIframeResizer'
|
2022-06-22 10:27:23 +00:00
|
|
|
import logo from '@/images/logo-monentreprise.svg'
|
|
|
|
import { OverlayProvider } from '@react-aria/overlays'
|
|
|
|
import { ErrorBoundary } from '@sentry/react'
|
|
|
|
import i18next from 'i18next'
|
|
|
|
import { createContext, ReactNode } from 'react'
|
2021-10-26 15:27:48 +00:00
|
|
|
import { HelmetProvider } from 'react-helmet-async'
|
2020-05-08 10:04:00 +00:00
|
|
|
import { I18nextProvider } from 'react-i18next'
|
2019-02-04 09:22:24 +00:00
|
|
|
import { Provider as ReduxProvider } from 'react-redux'
|
2022-06-22 10:27:23 +00:00
|
|
|
import { BrowserRouter } from 'react-router-dom'
|
2022-06-30 17:32:57 +00:00
|
|
|
import { ServiceWorker } from './ServiceWorker'
|
2022-04-06 09:34:13 +00:00
|
|
|
import * as safeLocalStorage from './storage/safeLocalStorage'
|
2022-06-22 10:27:23 +00:00
|
|
|
import { store } from './store'
|
|
|
|
import { inIframe } from './utils'
|
2022-02-08 15:37:43 +00:00
|
|
|
|
2021-02-10 17:11:10 +00:00
|
|
|
// ATInternet Tracking
|
|
|
|
import { TrackingContext } from './ATInternetTracking'
|
|
|
|
import { createTracker } from './ATInternetTracking/Tracker'
|
2018-05-24 16:28:37 +00:00
|
|
|
|
2020-04-16 14:30:53 +00:00
|
|
|
type SiteName = 'mon-entreprise' | 'infrance' | 'publicodes'
|
|
|
|
|
|
|
|
export const SiteNameContext = createContext<SiteName | null>(null)
|
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
export type ProviderProps = {
|
2020-04-16 14:30:53 +00:00
|
|
|
basename: SiteName
|
2022-02-09 09:26:56 +00:00
|
|
|
children: ReactNode
|
2019-11-10 15:57:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
export default function Provider({
|
|
|
|
basename,
|
2020-05-08 10:04:00 +00:00
|
|
|
children,
|
2022-02-09 09:26:56 +00:00
|
|
|
}: ProviderProps): JSX.Element {
|
2022-02-08 15:37:43 +00:00
|
|
|
useIframeResizer()
|
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
return (
|
2022-01-26 09:38:58 +00:00
|
|
|
<DesignSystemThemeProvider>
|
|
|
|
<GlobalStyle />
|
|
|
|
<ErrorBoundary
|
|
|
|
showDialog
|
|
|
|
fallback={
|
2021-12-29 17:21:02 +00:00
|
|
|
<Container>
|
2022-07-28 18:04:44 +00:00
|
|
|
<Link href="/">
|
2021-12-29 17:21:02 +00:00
|
|
|
<img
|
|
|
|
src={logo}
|
2022-09-23 09:23:03 +00:00
|
|
|
alt="Logo mon-entreprise"
|
2021-12-29 17:21:02 +00:00
|
|
|
style={{
|
|
|
|
maxWidth: '200px',
|
|
|
|
width: '100%',
|
|
|
|
marginTop: '1rem',
|
|
|
|
}}
|
|
|
|
></img>
|
|
|
|
</Link>
|
|
|
|
<H1>Une erreur est survenue</H1>
|
|
|
|
<Intro>
|
|
|
|
L'équipe technique mon-entreprise a été automatiquement prévenue.
|
|
|
|
</Intro>
|
|
|
|
<Body>
|
|
|
|
Vous pouvez également nous contacter directement à l'adresse{' '}
|
|
|
|
<Link href="mailto:contact@mon-entreprise.beta.gouv.fr">
|
|
|
|
contact@mon-entreprise.beta.gouv.fr
|
|
|
|
</Link>{' '}
|
|
|
|
si vous souhaitez partager une remarque. Veuillez nous excuser
|
|
|
|
pour la gêne occasionnée.
|
|
|
|
</Body>
|
|
|
|
</Container>
|
2022-01-26 09:38:58 +00:00
|
|
|
}
|
|
|
|
>
|
2022-06-30 17:32:57 +00:00
|
|
|
{!import.meta.env.SSR &&
|
|
|
|
import.meta.env.MODE === 'production' &&
|
|
|
|
'serviceWorker' in navigator &&
|
|
|
|
!inIframe() && <ServiceWorker />}
|
2022-01-25 17:41:44 +00:00
|
|
|
<OverlayProvider>
|
2022-01-26 09:38:58 +00:00
|
|
|
<ReduxProvider store={store}>
|
|
|
|
<IsEmbeddedProvider>
|
|
|
|
<ThemeColorsProvider>
|
2021-12-29 17:21:02 +00:00
|
|
|
<DisableAnimationOnPrintProvider>
|
|
|
|
<SiteNameContext.Provider value={basename}>
|
2022-07-28 18:04:44 +00:00
|
|
|
<I18nextProvider i18n={i18next}>
|
|
|
|
<BrowserRouterProvider basename={basename}>
|
|
|
|
{children}
|
|
|
|
</BrowserRouterProvider>
|
|
|
|
</I18nextProvider>
|
2021-12-29 17:21:02 +00:00
|
|
|
</SiteNameContext.Provider>
|
|
|
|
</DisableAnimationOnPrintProvider>
|
2022-01-26 09:38:58 +00:00
|
|
|
</ThemeColorsProvider>
|
|
|
|
</IsEmbeddedProvider>
|
|
|
|
</ReduxProvider>
|
|
|
|
</OverlayProvider>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</DesignSystemThemeProvider>
|
2020-04-05 21:19:02 +00:00
|
|
|
)
|
2018-07-12 08:09:41 +00:00
|
|
|
}
|
2021-12-29 17:21:02 +00:00
|
|
|
|
|
|
|
function BrowserRouterProvider({
|
|
|
|
children,
|
|
|
|
basename,
|
|
|
|
}: {
|
2022-02-09 09:26:56 +00:00
|
|
|
children: ReactNode
|
2021-12-29 17:21:02 +00:00
|
|
|
basename: string
|
|
|
|
}) {
|
2022-07-25 09:02:08 +00:00
|
|
|
// The server router is only provided in the entry-server file
|
2021-12-29 17:21:02 +00:00
|
|
|
if (import.meta.env.SSR) {
|
|
|
|
return <>{children}</>
|
|
|
|
}
|
|
|
|
|
|
|
|
const ATTracker = createTracker(
|
|
|
|
import.meta.env.VITE_AT_INTERNET_SITE_ID,
|
|
|
|
safeLocalStorage.getItem('tracking:do_not_track') === '1' ||
|
|
|
|
navigator.doNotTrack === '1'
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2022-01-31 07:28:31 +00:00
|
|
|
<HelmetProvider>
|
|
|
|
<TrackingContext.Provider
|
|
|
|
value={
|
|
|
|
new ATTracker({
|
|
|
|
language: i18next.language as 'fr' | 'en',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
2022-06-22 10:27:23 +00:00
|
|
|
<BrowserRouter
|
|
|
|
basename={import.meta.env.MODE === 'production' ? '' : basename}
|
|
|
|
>
|
2022-07-25 09:02:08 +00:00
|
|
|
{children}
|
2022-06-22 10:27:23 +00:00
|
|
|
</BrowserRouter>
|
2022-01-31 07:28:31 +00:00
|
|
|
</TrackingContext.Provider>
|
|
|
|
</HelmetProvider>
|
2021-12-29 17:21:02 +00:00
|
|
|
)
|
|
|
|
}
|