@datlv-trustshop/shopify-inapp-components 0.1.11 → 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/dist/core/global-manager.js +33 -13
- 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) {
|
|
@@ -47,11 +47,20 @@ export class GlobalDashboardManager {
|
|
|
47
47
|
if (config && !this.configEquals(this.lastConfig, config)) {
|
|
48
48
|
this.updateGlobalConfig(config);
|
|
49
49
|
}
|
|
50
|
-
// Check if we
|
|
51
|
-
|
|
50
|
+
// Check if we need to initialize due to pending locale refresh
|
|
51
|
+
// This handles the case where all providers have autoInit=false but want locale refresh
|
|
52
|
+
if (this.pendingLocaleRefresh && autoRefreshOnLocaleChange) {
|
|
52
53
|
const locale = this.pendingLocaleRefresh;
|
|
53
54
|
this.pendingLocaleRefresh = null;
|
|
54
|
-
|
|
55
|
+
// Force initialization with the new locale if not initialized
|
|
56
|
+
if (!this.engine || !this.engine.isInitialized()) {
|
|
57
|
+
if (this.lastConfig) {
|
|
58
|
+
this.init({ ...this.lastConfig, locale }).catch(console.error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.engine.setLocale(locale).catch(console.error);
|
|
63
|
+
}
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
/**
|
|
@@ -109,13 +118,17 @@ export class GlobalDashboardManager {
|
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
120
|
else {
|
|
112
|
-
// Engine not initialized yet
|
|
121
|
+
// Engine not initialized yet
|
|
113
122
|
this.engine.updateLocale(config.locale);
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
if (shouldRefresh
|
|
123
|
+
// If any provider wants refresh, force initialization NOW
|
|
124
|
+
// This is critical for autoInit=false providers
|
|
125
|
+
if (shouldRefresh) {
|
|
117
126
|
this.init(config).catch(console.error);
|
|
118
127
|
}
|
|
128
|
+
else {
|
|
129
|
+
// Mark for later refresh when a provider initializes
|
|
130
|
+
this.pendingLocaleRefresh = config.locale;
|
|
131
|
+
}
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
}
|
|
@@ -220,13 +233,17 @@ export class GlobalDashboardManager {
|
|
|
220
233
|
if (this.lastConfig) {
|
|
221
234
|
this.lastConfig = { ...this.lastConfig, locale };
|
|
222
235
|
}
|
|
236
|
+
// Check if any provider wants auto-refresh
|
|
237
|
+
const shouldRefresh = Array.from(this.providers.values()).some(p => p.autoRefreshOnLocaleChange);
|
|
223
238
|
if (!this.engine) {
|
|
224
|
-
// No engine yet,
|
|
225
|
-
this.
|
|
226
|
-
// If we have providers, initialize with the new locale
|
|
227
|
-
if (this.providers.size > 0 && this.lastConfig) {
|
|
239
|
+
// No engine yet, but if any provider wants refresh, initialize NOW
|
|
240
|
+
if (shouldRefresh && this.lastConfig) {
|
|
228
241
|
await this.init({ ...this.lastConfig, locale });
|
|
229
242
|
}
|
|
243
|
+
else {
|
|
244
|
+
// Mark locale for refresh when engine is created
|
|
245
|
+
this.pendingLocaleRefresh = locale;
|
|
246
|
+
}
|
|
230
247
|
return;
|
|
231
248
|
}
|
|
232
249
|
// Engine exists, update locale
|
|
@@ -234,9 +251,12 @@ export class GlobalDashboardManager {
|
|
|
234
251
|
await this.engine.setLocale(locale);
|
|
235
252
|
}
|
|
236
253
|
else {
|
|
237
|
-
// Engine not initialized
|
|
254
|
+
// Engine exists but not initialized
|
|
238
255
|
this.engine.updateLocale(locale);
|
|
239
|
-
|
|
256
|
+
// If any provider wants refresh, initialize now
|
|
257
|
+
if (shouldRefresh) {
|
|
258
|
+
await this.init();
|
|
259
|
+
}
|
|
240
260
|
}
|
|
241
261
|
}
|
|
242
262
|
/**
|