-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSettingsPage.tsx
More file actions
64 lines (58 loc) · 1.73 KB
/
SettingsPage.tsx
File metadata and controls
64 lines (58 loc) · 1.73 KB
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
import { FetchView, IOutlet, OutletView, getErrorMessage } from "react-declarative";
import FeaturePage from "./pages/FeaturePage";
import { ISettingsDto } from "../../../lib/services/db/SettingsDbService";
import VisibilityPage from "./pages/VisibilityPage";
import hasRouteMatch from "../../../utils/hasRouteMatch";
import ioc from "../../../lib/ioc";
const routes: IOutlet[] = [
{
id: "features",
element: FeaturePage,
isActive: (pathname) => hasRouteMatch(["/settings", "/settings/features"], pathname),
},
{
id: "visibility",
element: VisibilityPage,
isActive: (pathname) => hasRouteMatch(["/settings/visibility"], pathname),
},
];
export const SettingsPage = () => {
const handleSubmit = async (data: ISettingsDto) => {
let isOk = true;
try {
await ioc.settingsViewService.setValue(data);
ioc.alertService.notify("Saved");
} catch (error) {
isOk = false;
const msg = getErrorMessage(error);
ioc.alertService.notify(msg);
} finally {
return isOk;
}
};
const fetchState = async () =>
[
await ioc.settingsViewService.getValue(),
] as const;
return (
<FetchView
state={fetchState}
fallback={ioc.errorService.handleGlobalError}
>
{async ([settings]) => (
<OutletView
history={ioc.routerService}
onLoadStart={() => ioc.layoutService.setAppbarLoader(true)}
onLoadEnd={() => ioc.layoutService.setAppbarLoader(false)}
routes={routes}
initialData={{
features: settings.features || null,
visibility: settings.visibility || null,
}}
onSubmit={handleSubmit}
/>
)}
</FetchView>
);
};
export default SettingsPage;