@datlv-trustshop/shopify-inapp-components 0.1.12 → 0.1.13
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.
- package/dist/components/TopBanner.js +29 -4
- package/package.json +1 -1
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
3
|
import { Banner, Button, Text, BlockStack, InlineStack, } from "@shopify/polaris";
|
|
4
4
|
import { ExternalIcon } from "@shopify/polaris-icons";
|
|
5
5
|
import { useTopBanner } from "../hooks/useBanner";
|
|
6
6
|
export const TopBanner = ({ className = "", onClose, onAction, closable = true, renderBanner, }) => {
|
|
7
7
|
const banner = useTopBanner();
|
|
8
|
-
const [
|
|
8
|
+
const [isDismissed, setIsDismissed] = useState(false);
|
|
9
|
+
const DISMISS_KEY = "ts-top-banner-dismissed";
|
|
10
|
+
const DISMISS_DURATION = 7 * 24 * 60 * 60 * 1000;
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const dismissedData = localStorage.getItem(DISMISS_KEY);
|
|
13
|
+
if (dismissedData) {
|
|
14
|
+
try {
|
|
15
|
+
const { timestamp } = JSON.parse(dismissedData);
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
if (now - timestamp < DISMISS_DURATION) {
|
|
18
|
+
setIsDismissed(true);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
localStorage.removeItem(DISMISS_KEY);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
localStorage.removeItem(DISMISS_KEY);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
9
29
|
const handleClose = () => {
|
|
10
|
-
|
|
30
|
+
const dismissData = {
|
|
31
|
+
timestamp: Date.now(),
|
|
32
|
+
dismissed: true,
|
|
33
|
+
};
|
|
34
|
+
localStorage.setItem(DISMISS_KEY, JSON.stringify(dismissData));
|
|
35
|
+
setIsDismissed(true);
|
|
11
36
|
onClose?.();
|
|
12
37
|
};
|
|
13
38
|
const handleAction = () => {
|
|
@@ -18,7 +43,7 @@ export const TopBanner = ({ className = "", onClose, onAction, closable = true,
|
|
|
18
43
|
onAction?.(banner);
|
|
19
44
|
}
|
|
20
45
|
};
|
|
21
|
-
if (!banner ||
|
|
46
|
+
if (!banner || isDismissed) {
|
|
22
47
|
return null;
|
|
23
48
|
}
|
|
24
49
|
if (renderBanner) {
|