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 SideNav from 'components/layout/SideNav';
import styles from './layout.module.css';
import SettingsContext from './SettingsContext';
export default function SettingsLayout({ children }) {
const { user } = useUser();
@ -25,17 +24,7 @@ export default function SettingsLayout({ children }) {
return null;
}
const hostUrl = process.env.hostUrl || location.origin;
const config = {
settingsUrl: '/settings/websites',
shareUrl: hostUrl,
trackingCodeUrl: hostUrl,
websitesUrl: `/websites`,
};
return (
<SettingsContext.Provider value={config}>
<div className={styles.layout}>
{!cloudMode && (
<div className={styles.menu}>
@ -44,6 +33,5 @@ export default function SettingsLayout({ children }) {
)}
<div className={styles.content}>{children}</div>
</div>
</SettingsContext.Provider>
);
}

View File

@ -64,7 +64,7 @@ export function Realtime({ websiteId }) {
}
return arr;
}, [])
.reduce((arr, { country }) => {
.reduce((arr: { x: any; y: number }[], { country }: any) => {
if (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 { ReactBasicsProvider } from 'react-basics';
import ErrorBoundary from 'components/common/ErrorBoundary';
import SettingsContext from 'app/(main)/settings/SettingsContext';
import useLocale from 'components/hooks/useLocale';
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 }) {
return (
<MessagesProvider>
<SettingsProvider>
<QueryClientProvider client={client}>
<ReactBasicsProvider>
<ErrorBoundary>{children}</ErrorBoundary>
</ReactBasicsProvider>
</QueryClientProvider>
</SettingsProvider>
</MessagesProvider>
);
}