1
|
1 |
|
import "react-toastify/dist/ReactToastify.css"; |
2
|
|
|
|
3
|
1 |
|
import React from "react"; |
4
|
|
|
|
5
|
|
|
import { AppConfig, Theme } from "../../types"; |
6
|
|
|
|
7
|
1 |
|
import { Provider } from "react-redux"; |
8
|
|
|
import { History } from "history"; |
9
|
|
|
import { Store } from "@reduxjs/toolkit"; |
10
|
|
|
|
11
|
1 |
|
import ErrorBoundary from "../AppErrorBoundary"; |
12
|
1 |
|
import { parseThemeField } from "../../utils"; |
13
|
1 |
|
import { defaultTheme } from "../../constants/default-configs"; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Modular main app, rendered at the end of the init process. |
17
|
|
|
* |
18
|
|
|
* @param {Store} store redux store, used to drive app components (enhanced with `modular-engine`) |
19
|
|
|
* @param {History} history history object, used for routing logic |
20
|
|
|
* @param {AppConfig} config app config, to determine which components will be rendered and where |
21
|
|
|
* @param {{ ui?: boolean; modal?: boolean }} engine app engine config, the same config file passed to modular-engine initStore function |
22
|
|
|
* @param {Theme} theme app custom theme, to customize some UI parts |
23
|
|
|
* |
24
|
|
|
* @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo> |
25
|
|
|
* |
26
|
|
|
* @copyright 2022 Cataldo Cianciaruso |
27
|
|
|
*/ |
28
|
1 |
|
const MainApp = ({ |
29
|
5 |
|
store, |
30
|
5 |
|
history, |
31
|
5 |
|
engine, |
32
|
5 |
|
config, |
33
|
5 |
|
theme, |
34
|
|
|
}: { |
35
|
|
|
store: Store; |
36
|
|
|
history: History; |
37
|
|
|
engine: { ui?: boolean; modal?: boolean }; |
38
|
|
|
config: AppConfig; |
39
|
|
|
theme: Theme; |
40
|
|
|
}) => { |
41
|
5 |
|
const CustomContent = config.content; |
42
|
5 |
|
const HeaderContent = config.header; |
43
|
5 |
|
const FooterContent = config.footer; |
44
|
5 |
|
const DrawerContent = config.drawer?.content; |
45
|
5 |
|
const DrawerLogo = config.drawer?.logo; |
46
|
5 |
|
const Preloader = config.preloader; |
47
|
5 |
|
const ThemedContainer = React.lazy(() => import("../ThemedContainer")); |
48
|
5 |
|
const AppDrawer = React.lazy(() => import("../AppDrawer")); |
49
|
6 |
|
const AppModal = React.lazy(() => import("../AppModal")); |
50
|
5 |
|
const AppRouter = React.lazy(() => import("../AppRouter")); |
51
|
6 |
|
const ToastContainer = React.lazy(() => import("../ToastContainer")); |
52
|
|
|
|
53
|
5 |
|
return ( |
54
|
|
|
<React.Suspense fallback={Preloader ? <Preloader /> : null}> |
55
|
|
|
<Provider store={store}> |
56
|
|
|
<ErrorBoundary fallback={config.error}> |
57
|
|
|
{engine.ui && <ToastContainer />} |
58
|
|
|
{engine.modal && <AppModal modals={config.modals || {}} />} |
59
|
|
|
{engine.ui && config.drawer && ( |
60
|
|
|
<AppDrawer |
61
|
|
|
theme={parseThemeField(theme.drawer, defaultTheme.drawer)} |
62
|
|
|
logo={DrawerLogo} |
63
|
|
|
position={config.drawer.position} |
64
|
|
|
> |
65
|
|
|
{DrawerContent && <DrawerContent />} |
66
|
|
|
</AppDrawer> |
67
|
|
|
)} |
68
|
|
|
<div |
69
|
|
|
id="app-container" |
70
|
|
|
style={{ |
71
|
|
|
height: "100vh", |
72
|
|
|
width: "100vw", |
73
|
|
|
display: "flex", |
74
|
|
|
flexDirection: "column", |
75
|
|
|
alignItems: "center", |
76
|
|
|
}} |
77
|
|
|
> |
78
|
|
|
{HeaderContent && ( |
79
|
|
|
<ThemedContainer |
80
|
|
|
theme={parseThemeField(theme.header, defaultTheme.header)} |
81
|
|
|
wrapper="header" |
82
|
|
|
style={{ |
83
|
|
|
width: "100%", |
84
|
|
|
overflow: "hidden", |
85
|
|
|
}} |
86
|
|
|
> |
87
|
|
|
<HeaderContent /> |
88
|
|
|
</ThemedContainer> |
89
|
|
|
)} |
90
|
|
|
{config.pagesRendering && ( |
91
|
|
|
<AppRouter |
92
|
|
|
renderCallback={config.pagesRendering} |
93
|
|
|
history={history} |
94
|
|
|
theme={parseThemeField(theme.router, defaultTheme.router)} |
95
|
|
|
/> |
96
|
|
|
)} |
97
|
|
|
{CustomContent && <CustomContent />} |
98
|
|
|
{FooterContent && ( |
99
|
|
|
<ThemedContainer |
100
|
|
|
theme={parseThemeField(theme.footer, defaultTheme.footer)} |
101
|
|
|
wrapper="footer" |
102
|
|
|
style={{ |
103
|
|
|
overflow: "hidden", |
104
|
|
|
width: "100%", |
105
|
|
|
}} |
106
|
|
|
> |
107
|
|
|
<FooterContent /> |
108
|
|
|
</ThemedContainer> |
109
|
|
|
)} |
110
|
|
|
</div> |
111
|
|
|
</ErrorBoundary> |
112
|
|
|
</Provider> |
113
|
|
|
</React.Suspense> |
114
|
|
|
); |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
export default MainApp; |
118
|
|
|
|