feat: typeing AppIntlProvider

This commit is contained in:
Ahmed Bouhuolia
2024-10-13 16:51:04 +02:00
parent 68a0db91ee
commit e873198238
3 changed files with 66 additions and 43 deletions

View File

@@ -1,5 +1,4 @@
// @ts-nocheck // @ts-nocheck
import { defaultTheme, ThemeProvider } from '@xstyled/emotion';
import { lazy, Suspense } from 'react'; import { lazy, Suspense } from 'react';
import { Router, Switch, Route } from 'react-router'; import { Router, Switch, Route } from 'react-router';
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
@@ -37,12 +36,6 @@ const PaymentPortalPage = lazy(
() => import('@/containers/PaymentPortal/PaymentPortalPage'), () => import('@/containers/PaymentPortal/PaymentPortalPage'),
); );
const theme = {
...defaultTheme,
bpPrefix: 'bp4',
}
/** /**
* App inner. * App inner.
*/ */
@@ -50,14 +43,10 @@ function AppInsider({ history }) {
return ( return (
<div className="App"> <div className="App">
<DashboardThemeProvider> <DashboardThemeProvider>
<ThemeProvider theme={theme}>
<Suspense fallback={'Loading...'}> <Suspense fallback={'Loading...'}>
<Router history={history}> <Router history={history}>
<Switch> <Switch>
<Route <Route path={'/one_click_demo'} children={<OneClickDemoPage />} />
path={'/one_click_demo'}
children={<OneClickDemoPage />}
/>
<Route path={'/auth/register/verify'}> <Route path={'/auth/register/verify'}>
<EnsureAuthenticated> <EnsureAuthenticated>
<EnsureUserEmailNotVerified> <EnsureUserEmailNotVerified>
@@ -81,7 +70,6 @@ function AppInsider({ history }) {
</Suspense> </Suspense>
<GlobalErrors /> <GlobalErrors />
</ThemeProvider>
</DashboardThemeProvider> </DashboardThemeProvider>
</div> </div>
); );

View File

@@ -1,12 +1,31 @@
// @ts-nocheck // @ts-nocheck
import React, { createContext } from 'react'; import React, { createContext } from 'react';
const AppIntlContext = createContext(); interface AppIntlContextValue {
currentLocale: string;
direction: 'rtl' | 'ltr';
isRTL: boolean;
isLTR: boolean;
}
const AppIntlContext = createContext<AppIntlContextValue>(
{} as AppIntlContextValue,
);
interface AppIntlProviderProps {
currentLocale: string;
isRTL: boolean;
children: React.ReactNode;
}
/** /**
* Application intl provider. * Application intl provider.
*/ */
function AppIntlProvider({ currentLocale, isRTL, children }) { function AppIntlProvider({
currentLocale,
isRTL,
children,
}: AppIntlProviderProps) {
const provider = { const provider = {
currentLocale, currentLocale,
isRTL, isRTL,
@@ -21,6 +40,7 @@ function AppIntlProvider({ currentLocale, isRTL, children }) {
); );
} }
const useAppIntlContext = () => React.useContext(AppIntlContext); const useAppIntlContext = () =>
React.useContext<AppIntlContextValue>(AppIntlContext);
export { AppIntlProvider, useAppIntlContext }; export { AppIntlProvider, useAppIntlContext };

View File

@@ -1,9 +1,20 @@
// @ts-nocheck
import React from 'react'; import React from 'react';
import { ThemeProvider, StyleSheetManager } from 'styled-components'; import {
ThemeProvider as StyleComponentsThemeProvider,
StyleSheetManager,
} from 'styled-components';
import rtlcss from 'stylis-rtlcss'; import rtlcss from 'stylis-rtlcss';
import {
defaultTheme,
ThemeProvider as XStyledEmotionThemeProvider,
} from '@xstyled/emotion';
import { useAppIntlContext } from '../AppIntlProvider'; import { useAppIntlContext } from '../AppIntlProvider';
const theme = {
...defaultTheme,
bpPrefix: 'bp4',
};
interface DashboardThemeProviderProps { interface DashboardThemeProviderProps {
children: React.ReactNode; children: React.ReactNode;
} }
@@ -17,7 +28,11 @@ export function DashboardThemeProvider({
<StyleSheetManager <StyleSheetManager
{...(direction === 'rtl' ? { stylisPlugins: [rtlcss] } : {})} {...(direction === 'rtl' ? { stylisPlugins: [rtlcss] } : {})}
> >
<ThemeProvider theme={{ dir: direction }}>{children}</ThemeProvider> <StyleComponentsThemeProvider theme={{ dir: direction }}>
<XStyledEmotionThemeProvider theme={theme}>
{children}
</XStyledEmotionThemeProvider>
</StyleComponentsThemeProvider>
</StyleSheetManager> </StyleSheetManager>
); );
} }