Moved SettingsProvider to root Providers component.

This commit is contained in:
Mike Cao 2023-12-09 21:30:57 -08:00
parent 92a513e4d0
commit 44e243ad12
3 changed files with 30 additions and 26 deletions

View File

@ -4,7 +4,6 @@ import useUser from 'components/hooks/useUser';
import useMessages from 'components/hooks/useMessages'; import useMessages from 'components/hooks/useMessages';
import SideNav from 'components/layout/SideNav'; import SideNav from 'components/layout/SideNav';
import styles from './layout.module.css'; import styles from './layout.module.css';
import SettingsContext from './SettingsContext';
export default function SettingsLayout({ children }) { export default function SettingsLayout({ children }) {
const { user } = useUser(); const { user } = useUser();
@ -25,25 +24,14 @@ export default function SettingsLayout({ children }) {
return null; return null;
} }
const hostUrl = process.env.hostUrl || location.origin;
const config = {
settingsUrl: '/settings/websites',
shareUrl: hostUrl,
trackingCodeUrl: hostUrl,
websitesUrl: `/websites`,
};
return ( return (
<SettingsContext.Provider value={config}> <div className={styles.layout}>
<div className={styles.layout}> {!cloudMode && (
{!cloudMode && ( <div className={styles.menu}>
<div className={styles.menu}> <SideNav items={items} shallow={true} selectedKey={getKey()} />
<SideNav items={items} shallow={true} selectedKey={getKey()} /> </div>
</div> )}
)} <div className={styles.content}>{children}</div>
<div className={styles.content}>{children}</div> </div>
</div>
</SettingsContext.Provider>
); );
} }

View File

@ -64,7 +64,7 @@ export function Realtime({ websiteId }) {
} }
return arr; return arr;
}, []) }, [])
.reduce((arr, { country }) => { .reduce((arr: { x: any; y: number }[], { country }: any) => {
if (country) { if (country) {
const row = arr.find(({ x }) => x === country); const row = arr.find(({ x }) => x === country);

View File

@ -3,6 +3,7 @@ import { IntlProvider } from 'react-intl';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactBasicsProvider } from 'react-basics'; import { ReactBasicsProvider } from 'react-basics';
import ErrorBoundary from 'components/common/ErrorBoundary'; import ErrorBoundary from 'components/common/ErrorBoundary';
import SettingsContext from 'app/(main)/settings/SettingsContext';
import useLocale from 'components/hooks/useLocale'; import useLocale from 'components/hooks/useLocale';
import 'chartjs-adapter-date-fns'; import 'chartjs-adapter-date-fns';
@ -24,14 +25,29 @@ function MessagesProvider({ children }) {
); );
} }
function SettingsProvider({ children }) {
const hostUrl = process.env.hostUrl || location.origin;
const config = {
settingsUrl: '/settings/websites',
shareUrl: hostUrl,
trackingCodeUrl: hostUrl,
websitesUrl: `/websites`,
};
return <SettingsContext.Provider value={config}>{children}</SettingsContext.Provider>;
}
export function Providers({ children }) { export function Providers({ children }) {
return ( return (
<MessagesProvider> <MessagesProvider>
<QueryClientProvider client={client}> <SettingsProvider>
<ReactBasicsProvider> <QueryClientProvider client={client}>
<ErrorBoundary>{children}</ErrorBoundary> <ReactBasicsProvider>
</ReactBasicsProvider> <ErrorBoundary>{children}</ErrorBoundary>
</QueryClientProvider> </ReactBasicsProvider>
</QueryClientProvider>
</SettingsProvider>
</MessagesProvider> </MessagesProvider>
); );
} }