ublo-lib 1.27.5 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Router from "next/router";
|
|
3
|
+
import { useUbloContext } from "ublo/with-ublo";
|
|
4
|
+
import { fetchZone, fetchMenus } from "ublo/fetcher";
|
|
5
|
+
import Dialog from "dt-design-system/es/dialog";
|
|
6
|
+
import styles from "./information.module.css";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const STORAGE_KEY = "information_viewed";
|
|
9
|
+
export default function Information({
|
|
10
|
+
source = "/popup",
|
|
11
|
+
zone = "content",
|
|
12
|
+
preventOpening
|
|
13
|
+
}) {
|
|
14
|
+
const [content, setContent] = React.useState();
|
|
15
|
+
const {
|
|
16
|
+
config,
|
|
17
|
+
lang
|
|
18
|
+
} = useUbloContext();
|
|
19
|
+
const {
|
|
20
|
+
ubloApi,
|
|
21
|
+
site
|
|
22
|
+
} = config;
|
|
23
|
+
const close = React.useCallback(() => {
|
|
24
|
+
sessionStorage.setItem(STORAGE_KEY, "true");
|
|
25
|
+
setContent(undefined);
|
|
26
|
+
}, []);
|
|
27
|
+
const getContent = React.useCallback(async () => {
|
|
28
|
+
const menus = await fetchMenus(ubloApi, site, lang, source, 1, true);
|
|
29
|
+
if (menus.length === 1) {
|
|
30
|
+
const content = await fetchZone(ubloApi, site, lang, source, zone);
|
|
31
|
+
if (!content) return;
|
|
32
|
+
setContent(content);
|
|
33
|
+
}
|
|
34
|
+
}, [lang, site, source, ubloApi, zone]);
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const alreadySeen = sessionStorage.getItem(STORAGE_KEY) || sessionStorage.getItem("cms_token");
|
|
37
|
+
if (!preventOpening && !alreadySeen) {
|
|
38
|
+
getContent();
|
|
39
|
+
}
|
|
40
|
+
}, [getContent, preventOpening]);
|
|
41
|
+
Router.ready(() => {
|
|
42
|
+
Router.events.on("routeChangeComplete", () => {
|
|
43
|
+
close();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return _jsx(Dialog, {
|
|
47
|
+
className: styles.information,
|
|
48
|
+
close: close,
|
|
49
|
+
isOpened: !!content,
|
|
50
|
+
children: _jsx("div", {
|
|
51
|
+
className: styles.inner,
|
|
52
|
+
dangerouslySetInnerHTML: {
|
|
53
|
+
__html: content
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
}
|