forked from marmelab/admin-on-rest-demo
-
Notifications
You must be signed in to change notification settings - Fork 30
/
App.tsx
88 lines (73 loc) · 2.42 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
import React, { useState, useEffect } from 'react';
import { Admin, Resource } from 'react-admin';
import polyglotI18nProvider from 'ra-i18n-polyglot';
import './App.css';
import authProvider from './authProvider';
import themeReducer from './themeReducer';
import { Login, Layout } from './layout';
import { Dashboard } from './dashboard';
import customRoutes from './routes';
import englishMessages from './i18n/en';
import visitors from './visitors';
import orders from './orders';
import products from './products';
import invoices from './invoices';
import categories from './categories';
import reviews from './reviews';
import dataProviderFactory from './dataProvider';
import fakeServerFactory from './fakeServer';
const i18nProvider = polyglotI18nProvider(locale => {
if (locale === 'fr') {
return import('./i18n/fr').then(messages => messages.default);
}
// Always fallback on english
return englishMessages;
}, 'en');
const App = () => {
const [dataProvider, setDataProvider] = useState(null);
useEffect(() => {
let restoreFetch;
const fetchDataProvider = async () => {
restoreFetch = await fakeServerFactory(
process.env.REACT_APP_DATA_PROVIDER
);
setDataProvider(
await dataProviderFactory(process.env.REACT_APP_DATA_PROVIDER)
);
};
fetchDataProvider();
return restoreFetch;
}, []);
if (!dataProvider) {
return (
<div className="loader-container">
<div className="loader">Loading...</div>
</div>
);
}
return (
<Admin
title=""
dataProvider={dataProvider}
customReducers={{ theme: themeReducer }}
customRoutes={customRoutes}
authProvider={authProvider}
dashboard={Dashboard}
loginPage={Login}
layout={Layout}
i18nProvider={i18nProvider}
>
<Resource name="customers" {...visitors} />
<Resource
name="commands"
{...orders}
options={{ label: 'Orders' }}
/>
<Resource name="invoices" {...invoices} />
<Resource name="products" {...products} />
<Resource name="categories" {...categories} />
<Resource name="reviews" {...reviews} />
</Admin>
);
};
export default App;