-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_app.tsx
154 lines (139 loc) · 5.98 KB
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React, { useEffect, useState } from 'react';
import { SessionProvider } from 'next-auth/react';
import { NextAdapter } from 'next-query-params';
import App, { AppContext, AppInitialProps, AppProps } from 'next/app';
import Head from 'next/head';
import { useRouter } from 'next/router';
import { QueryParamProvider } from 'use-query-params';
import type { EuiSideNavItemType } from '@elastic/eui';
import { EuiProvider, EuiThemeColorMode } from '@elastic/eui';
import {
ColorModes,
ConfirmationDialogContextWrapper,
OrchestratorConfig,
OrchestratorConfigProvider,
StoreProvider,
WfoAuth,
WfoErrorBoundary,
WfoMenuItemLink,
WfoPageTemplate,
WfoToastsList,
defaultOrchestratorTheme,
} from '@orchestrator-ui/orchestrator-ui-components';
import { getAppLogo } from '@/components/AppLogo/AppLogo';
import { getInitialOrchestratorConfig } from '@/configuration';
import { TranslationsProvider } from '@/translations/translationsProvider';
import '../font/inter.css';
type AppOwnProps = { orchestratorConfig: OrchestratorConfig };
function CustomApp({
Component,
pageProps,
orchestratorConfig,
}: AppProps & AppOwnProps) {
const router = useRouter();
const [themeMode, setThemeMode] = useState<EuiThemeColorMode>(
ColorModes.LIGHT,
);
const handleThemeSwitch = (newThemeMode: EuiThemeColorMode) => {
setThemeMode(newThemeMode);
localStorage.setItem('themeMode', newThemeMode);
};
useEffect(() => {
// Initialize theme mode from localStorage or set it to 'light' if not present
const storedTheme = localStorage.getItem('themeMode');
if (
!storedTheme ||
(storedTheme !== ColorModes.LIGHT &&
storedTheme !== ColorModes.DARK)
) {
handleThemeSwitch(ColorModes.LIGHT);
}
}, []);
const addMenuItems = (
defaultMenuItems: EuiSideNavItemType<object>[],
): EuiSideNavItemType<object>[] => [
...defaultMenuItems,
{
name: 'Example form',
id: '10',
isSelected: router.pathname === '/example-form',
href: '/example-form',
renderItem: () => (
<WfoMenuItemLink
path={'/example-form'}
translationString="Example form"
isSelected={router.pathname === '/example-form'}
/>
),
},
];
return (
<WfoErrorBoundary>
<OrchestratorConfigProvider
initialOrchestratorConfig={orchestratorConfig}
>
<StoreProvider initialOrchestratorConfig={orchestratorConfig}>
<SessionProvider session={pageProps.session}>
<WfoAuth>
<EuiProvider
colorMode={themeMode}
modify={defaultOrchestratorTheme}
>
<TranslationsProvider>
<Head>
<link
rel="icon"
href="/favicon.png"
/>
<title>
Welcome to
example-orchestrator-ui!
</title>
</Head>
<main className="app">
<ConfirmationDialogContextWrapper>
<WfoPageTemplate
getAppLogo={getAppLogo}
onThemeSwitch={
handleThemeSwitch
}
overrideMenuItems={
addMenuItems
}
>
<QueryParamProvider
adapter={NextAdapter}
options={{
removeDefaultsFromUrl:
false,
enableBatching:
true,
}}
>
<Component
{...pageProps}
/>
</QueryParamProvider>
</WfoPageTemplate>
<WfoToastsList />
</ConfirmationDialogContextWrapper>
</main>
</TranslationsProvider>
</EuiProvider>
</WfoAuth>
</SessionProvider>
</StoreProvider>
</OrchestratorConfigProvider>
</WfoErrorBoundary>
);
}
CustomApp.getInitialProps = async (
context: AppContext,
): Promise<AppOwnProps & AppInitialProps> => {
const ctx = await App.getInitialProps(context);
return {
...ctx,
orchestratorConfig: getInitialOrchestratorConfig(),
};
};
export default CustomApp;