@datlv-trustshop/shopify-inapp-components 0.1.24 → 0.1.25

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.
@@ -9,7 +9,7 @@ export function useFloatingCards(options = {}) {
9
9
  const dashboardContext = useDashboardContext();
10
10
  const contextLocale = dashboardContext?.locale;
11
11
  // Use props locale if provided, otherwise use context locale, fallback to 'en'
12
- const locale = propsLocale || contextLocale || 'en';
12
+ const locale = propsLocale || contextLocale || "en";
13
13
  const [cards, setCards] = useState([]);
14
14
  const [loading, setLoading] = useState(false);
15
15
  const [error, setError] = useState(null);
@@ -23,7 +23,6 @@ export function useFloatingCards(options = {}) {
23
23
  setError(null);
24
24
  try {
25
25
  const id = shopId;
26
- // Use proxy in development
27
26
  const apiUrl = typeof window !== "undefined" &&
28
27
  window.location.hostname === "localhost"
29
28
  ? `/api/campaigns?shop_id=${id}&locale=${locale}`
@@ -41,7 +40,6 @@ export function useFloatingCards(options = {}) {
41
40
  }
42
41
  const data = await response.json();
43
42
  if (data.success && Array.isArray(data.data)) {
44
- // Transform the API response to match our FloatingCardData interface
45
43
  const transformedCards = data.data.map((card) => ({
46
44
  ...card,
47
45
  // Ensure date format
@@ -138,19 +136,36 @@ export function useVisibleFloatingCards(options = {}) {
138
136
  return false;
139
137
  }
140
138
  // Check display_pages logic
141
- if (card.display_pages !== undefined) {
139
+ if (card.display_pages !== undefined && card.display_pages !== null) {
142
140
  // If display_pages is empty array, show on all pages
143
141
  if (card.display_pages.length === 0) {
144
142
  return true;
145
143
  }
146
144
  // If display_pages has values, check if current route matches
147
- if (currentRoute) {
148
- // Extract the page key from the route (e.g., "/settings" -> "settings")
149
- const currentPage = currentRoute.replace(/^\//, '').split('/')[0];
145
+ if (currentRoute !== undefined) {
146
+ // Extract the page key from the route
147
+ // Special handling: "/" or "" should map to "dashboard"
148
+ let currentPage = currentRoute.replace(/^\//, "").split("/")[0];
149
+ // Map root route to dashboard (in-app convention)
150
+ if (!currentPage || currentPage === "" || currentRoute === "/") {
151
+ currentPage = "dashboard";
152
+ }
153
+ // Debug log for development
154
+ if (typeof window !== "undefined" &&
155
+ window.location.hostname === "localhost") {
156
+ console.log("[FloatingCard] Route matching:", {
157
+ cardId: card.id,
158
+ currentRoute,
159
+ currentPage,
160
+ display_pages: card.display_pages,
161
+ matches: card.display_pages.includes(currentPage),
162
+ });
163
+ }
164
+ // Check if current page is in display_pages
150
165
  return card.display_pages.includes(currentPage);
151
166
  }
152
- // If no current route provided, don't show the card
153
- return false;
167
+ // If no current route provided, assume dashboard
168
+ return card.display_pages.includes("dashboard");
154
169
  }
155
170
  // If display_pages is not defined, show on all pages (backward compatibility)
156
171
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datlv-trustshop/shopify-inapp-components",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "private": false,
5
5
  "description": "React TypeScript components for Shopify in-app dashboard content",
6
6
  "main": "dist/index.js",