mirror of
https://github.com/betagouv/mon-entreprise
synced 2025-02-09 01:45:03 +00:00
* Ajout de storybook Ajout d'un Switch oui/non * Fix lint * Add react-router and fix type * Fix lint * Resolution du conflit de version de prettier avec storybook * Fix storybook * Reduce Storybook bundle size Refacto css in QuickLinks Remove useless comment Add default theme to CSS prop * Déploiement de Storybook * Fix déploiement * Fix déploiement storybook url * Fix Switch style * Remplace les oui/non radio bouton par un Switch * Filter aria props + react props in Storybook controls Sort props in Storybook Add global style in Storybook decorator * Update Storybook packages * Ajout d'un debounce dans OuiNonInput * Fix du Switch * Refacto des alias * Fix lint error avec Storybook * Fix eslint error * Refacto deploy for Storybook * ✨Ajout de type pour les yaml d'economie collaborative ✨Ajout de type sur les fonction du locale storage + Autre fix de type * Deploy storybook in dist dir in prod * Fix focus on Switch * Fix cy test * ✨ Remplace l'alias ~ par @ * ✨ Refacto du Switch * Remplace la checkbox par un Switch dans ChiffreAffairesActivitéMixte * Ajout des stories RadioGroup et ToggleGroup * Remplace le Switch oui/non par un ToggleGroup * Ajout d'un label dans le Switch Ajout du mode light sur le Switch * Fix autofocus * Fix cypress test * 🐛 Ajout du polyfill replaceAll * Test de deploiement * Ajout d'une redirection pour Storybook * Fix Storybook url * Fix du deploiement de Storybook
194 lines
5.5 KiB
TypeScript
194 lines
5.5 KiB
TypeScript
import { OverlayProvider } from '@react-aria/overlays'
|
|
import { ErrorBoundary } from '@sentry/react'
|
|
import { ThemeColorsProvider } from '@/components/utils/colors'
|
|
import { DisableAnimationOnPrintProvider } from '@/components/utils/DisableAnimationContext'
|
|
import { IsEmbeddedProvider } from '@/components/utils/embeddedContext'
|
|
import {
|
|
SitePathProvider,
|
|
SitePaths,
|
|
} from '@/components/utils/SitePathsContext'
|
|
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 { createBrowserHistory } from 'history'
|
|
import i18next from 'i18next'
|
|
import logo from '@/images/logo-monentreprise.svg'
|
|
import { useIframeResizer } from '@/hooks/useIframeResizer'
|
|
import { createContext, ReactNode, useMemo } from 'react'
|
|
import { HelmetProvider } from 'react-helmet-async'
|
|
import { I18nextProvider } from 'react-i18next'
|
|
import { Provider as ReduxProvider } from 'react-redux'
|
|
import { Router } from 'react-router-dom'
|
|
import reducers, { RootState } from '@/reducers/rootReducer'
|
|
import { composeWithDevToolsDevelopmentOnly } from '@redux-devtools/extension'
|
|
import {
|
|
applyMiddleware,
|
|
createStore,
|
|
Middleware,
|
|
PreloadedState,
|
|
Store,
|
|
} from 'redux'
|
|
|
|
// ATInternet Tracking
|
|
import { TrackingContext } from './ATInternetTracking'
|
|
import { createTracker } from './ATInternetTracking/Tracker'
|
|
import * as safeLocalStorage from './storage/safeLocalStorage'
|
|
import { inIframe } from './utils'
|
|
|
|
if (
|
|
!import.meta.env.SSR &&
|
|
import.meta.env.MODE === 'production' &&
|
|
'serviceWorker' in navigator &&
|
|
!inIframe()
|
|
) {
|
|
window.addEventListener('load', () => {
|
|
navigator.serviceWorker
|
|
.register('/sw.js')
|
|
.then((registration) => {
|
|
// eslint-disable-next-line no-console
|
|
console.log('SW registered: ', registration)
|
|
})
|
|
.catch((registrationError) => {
|
|
// eslint-disable-next-line no-console
|
|
console.log('SW registration failed: ', registrationError)
|
|
})
|
|
})
|
|
}
|
|
|
|
type SiteName = 'mon-entreprise' | 'infrance' | 'publicodes'
|
|
|
|
export const SiteNameContext = createContext<SiteName | null>(null)
|
|
|
|
const composeEnhancers = composeWithDevToolsDevelopmentOnly(
|
|
import.meta.env.VITE_REDUX_TRACE ? { trace: true, traceLimit: 25 } : {}
|
|
)
|
|
|
|
export type ProviderProps = {
|
|
basename: SiteName
|
|
children: ReactNode
|
|
sitePaths?: SitePaths
|
|
initialStore?: PreloadedState<RootState>
|
|
onStoreCreated?: (store: Store) => void
|
|
reduxMiddlewares?: Array<Middleware>
|
|
}
|
|
|
|
export default function Provider({
|
|
basename,
|
|
reduxMiddlewares = [],
|
|
initialStore,
|
|
onStoreCreated,
|
|
children,
|
|
sitePaths = {} as SitePaths,
|
|
}: ProviderProps): JSX.Element {
|
|
const storeEnhancer = composeEnhancers(applyMiddleware(...reduxMiddlewares))
|
|
|
|
// Hack: useMemo is used to persist the store across hot reloads.
|
|
const store = useMemo(() => {
|
|
return createStore(reducers, initialStore, storeEnhancer)
|
|
}, [])
|
|
onStoreCreated?.(store)
|
|
|
|
useIframeResizer()
|
|
|
|
return (
|
|
<DesignSystemThemeProvider>
|
|
<GlobalStyle />
|
|
<ErrorBoundary
|
|
showDialog
|
|
fallback={
|
|
<Container>
|
|
<Link href={sitePaths.index}>
|
|
<img
|
|
src={logo}
|
|
alt="logo service mon-entreprise urssaf"
|
|
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>
|
|
}
|
|
>
|
|
<OverlayProvider>
|
|
<ReduxProvider store={store}>
|
|
<IsEmbeddedProvider>
|
|
<ThemeColorsProvider>
|
|
<DisableAnimationOnPrintProvider>
|
|
<SiteNameContext.Provider value={basename}>
|
|
<SitePathProvider value={sitePaths}>
|
|
<I18nextProvider i18n={i18next}>
|
|
<BrowserRouterProvider basename={basename}>
|
|
<>{children}</>
|
|
</BrowserRouterProvider>
|
|
</I18nextProvider>
|
|
</SitePathProvider>
|
|
</SiteNameContext.Provider>
|
|
</DisableAnimationOnPrintProvider>
|
|
</ThemeColorsProvider>
|
|
</IsEmbeddedProvider>
|
|
</ReduxProvider>
|
|
</OverlayProvider>
|
|
</ErrorBoundary>
|
|
</DesignSystemThemeProvider>
|
|
)
|
|
}
|
|
|
|
function BrowserRouterProvider({
|
|
children,
|
|
basename,
|
|
}: {
|
|
children: ReactNode
|
|
basename: string
|
|
}) {
|
|
// The server rouer is only provided in the entry-server file
|
|
if (import.meta.env.SSR) {
|
|
return <>{children}</>
|
|
}
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
const history = useMemo(
|
|
() =>
|
|
createBrowserHistory({
|
|
basename: import.meta.env.MODE === 'production' ? '' : basename,
|
|
}),
|
|
[basename]
|
|
)
|
|
|
|
const ATTracker = createTracker(
|
|
import.meta.env.VITE_AT_INTERNET_SITE_ID,
|
|
safeLocalStorage.getItem('tracking:do_not_track') === '1' ||
|
|
navigator.doNotTrack === '1'
|
|
)
|
|
|
|
return (
|
|
<HelmetProvider>
|
|
<TrackingContext.Provider
|
|
value={
|
|
new ATTracker({
|
|
language: i18next.language as 'fr' | 'en',
|
|
})
|
|
}
|
|
>
|
|
<Router history={history}>
|
|
<>{children}</>
|
|
</Router>
|
|
</TrackingContext.Provider>
|
|
</HelmetProvider>
|
|
)
|
|
}
|