@datlv-trustshop/shopify-inapp-components 0.3.2 → 0.3.4

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.
Files changed (33) hide show
  1. package/dist/components/FloatingCard.d.ts +3 -3
  2. package/dist/components/FloatingCard.d.ts.map +1 -1
  3. package/dist/components/FloatingCard.js +62 -95
  4. package/dist/components/FloatingCard.js.map +1 -1
  5. package/dist/components/MarketingCampaignCard.d.ts +44 -0
  6. package/dist/components/MarketingCampaignCard.d.ts.map +1 -0
  7. package/dist/components/MarketingCampaignCard.js +235 -0
  8. package/dist/components/MarketingCampaignCard.js.map +1 -0
  9. package/dist/components/index.d.ts +1 -0
  10. package/dist/components/index.d.ts.map +1 -1
  11. package/dist/components/index.js +1 -0
  12. package/dist/components/index.js.map +1 -1
  13. package/dist/config/component-defaults.d.ts +1 -1
  14. package/dist/config/component-defaults.js +1 -1
  15. package/dist/config/component-defaults.js.map +1 -1
  16. package/dist/config/internal-config.d.ts.map +1 -1
  17. package/dist/config/internal-config.js +4 -0
  18. package/dist/config/internal-config.js.map +1 -1
  19. package/dist/core/SDKManager.d.ts +2 -2
  20. package/dist/core/SDKManager.d.ts.map +1 -1
  21. package/dist/core/SDKManager.js +7 -0
  22. package/dist/core/SDKManager.js.map +1 -1
  23. package/dist/hooks/useFloatingCards.d.ts.map +1 -1
  24. package/dist/hooks/useFloatingCards.js +16 -3
  25. package/dist/hooks/useFloatingCards.js.map +1 -1
  26. package/dist/hooks/usePartnerIntegration.d.ts.map +1 -1
  27. package/dist/hooks/usePartnerIntegration.js +5 -1
  28. package/dist/hooks/usePartnerIntegration.js.map +1 -1
  29. package/dist/index.d.ts +4 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -50
  32. package/dist/index.js.map +1 -1
  33. package/package.json +1 -1
@@ -6,7 +6,7 @@ export interface FloatingCardData {
6
6
  priority: number;
7
7
  title: string;
8
8
  description: string;
9
- date: string;
9
+ date?: string | null;
10
10
  tag?: {
11
11
  label: string;
12
12
  tone: "success" | "info" | "warning" | "critical" | "new";
@@ -38,8 +38,8 @@ interface FloatingCardProps {
38
38
  onDismiss?: () => void;
39
39
  onPrimaryAction?: (data: FloatingCardData) => void;
40
40
  onSecondaryAction?: (data: FloatingCardData) => void;
41
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
42
- animationType?: 'slide' | 'fade';
41
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
42
+ animationType?: "slide" | "fade";
43
43
  showCloseButton?: boolean;
44
44
  }
45
45
  export declare const FloatingCard: React.FC<FloatingCardProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"FloatingCard.d.ts","sourceRoot":"","sources":["../../src/components/FloatingCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAa7C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC;KAC3D,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,SAAS,GAAG,WAAW,CAAC;KAClC,CAAC;IACF,gBAAgB,CAAC,EAAE;QACjB,KAAK,EAAE,MA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CAAC;IACjC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA2OpD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -3,125 +3,91 @@ import React from "react";
3
3
  import { Card, BlockStack, InlineStack, Text, Badge, Button, Box, } from "@shopify/polaris";
4
4
  import { useCampaignTracking } from "../hooks/useCampaignTracking";
5
5
  import { useSDK } from "../core/SDKManager";
6
- export const FloatingCard = ({ data, shopId: propsShopId, onDismiss, onPrimaryAction, onSecondaryAction, position = 'bottom-right', showCloseButton = true, }) => {
7
- // Get shopId from SDK shopInfo if not provided via props
6
+ import { ExternalIcon } from "@shopify/polaris-icons";
7
+ export const FloatingCard = ({ data, shopId: propsShopId, onDismiss, onPrimaryAction, onSecondaryAction, position = "bottom-right", showCloseButton = true, }) => {
8
8
  const sdk = useSDK({});
9
9
  const contextShopId = sdk.shopInfo?.id;
10
10
  const shopId = propsShopId || contextShopId;
11
- // Early return if no data
12
11
  if (!data) {
13
12
  return null;
14
13
  }
15
- // Use the campaign ID from data or fallback to regular id
16
14
  const campaignId = data.campaign_id || data.id;
17
- // Set up campaign tracking
18
- const tracking = shopId && campaignId ? useCampaignTracking({
19
- shopId,
20
- campaignId,
21
- threshold: 0.5, // Track when 50% visible
22
- visibilityDuration: 1000, // Track view after 1 second
23
- metadata: {
24
- card_type: data.type,
25
- card_key: data.key,
26
- },
27
- }) : null;
15
+ const tracking = shopId && campaignId
16
+ ? useCampaignTracking({
17
+ shopId,
18
+ campaignId,
19
+ threshold: 0.5,
20
+ visibilityDuration: 1000,
21
+ metadata: {
22
+ card_type: data.type,
23
+ card_key: data.key,
24
+ },
25
+ })
26
+ : null;
28
27
  const handlePrimaryAction = () => {
29
- // Track the click
30
28
  tracking?.trackPrimaryAction();
31
29
  if (data.primary_action) {
32
- const url = data.primary_action.url;
33
- // Check if it's an external URL
34
- if (data.primary_action.external) {
35
- window.open(url, "_blank");
36
- }
37
- // Check if it's a modal trigger
38
- else if (url === "modal" || url === "/pricing") {
39
- // Pass the full card data to the handler for modal handling
40
- onPrimaryAction?.(data);
41
- }
42
- // Check if it's an internal route
43
- else if (url?.startsWith("/")) {
44
- // Pass the full card data for internal navigation
45
- onPrimaryAction?.(data);
46
- }
47
- // Default: just call the handler
48
- else {
49
- onPrimaryAction?.(data);
50
- }
30
+ onPrimaryAction?.(data);
51
31
  }
52
32
  };
53
33
  const handleSecondaryAction = () => {
54
- // Track the click
55
34
  tracking?.trackSecondaryAction();
56
35
  if (data.secondary_action) {
57
- const url = data.secondary_action.url;
58
- if (data.secondary_action.external) {
59
- window.open(url, "_blank");
60
- }
61
- else if (url?.startsWith("/") || url === "modal") {
62
- // Pass the full card data for internal handling
63
- onSecondaryAction?.(data);
64
- }
65
- else {
66
- onSecondaryAction?.(data);
67
- }
36
+ onSecondaryAction?.(data);
68
37
  }
69
38
  };
70
39
  const handleDismiss = () => {
71
- // Track the dismiss
72
40
  tracking?.trackDismiss();
73
41
  onDismiss?.();
74
42
  };
75
- // CSS-in-JS styles - no external CSS file needed
76
43
  const floatingCardStyles = {
77
- position: 'fixed',
44
+ position: "fixed",
78
45
  zIndex: 9999,
79
- width: '300px',
80
- display: 'flex',
81
- flexDirection: 'column',
82
- alignItems: 'flex-start',
83
- borderRadius: '8px',
84
- boxShadow: '0 4px 26px 0 rgba(0, 0, 0, 0.10)',
85
- overflow: 'hidden',
86
- animation: 'slideInUp 0.3s ease-out',
87
- ...(position === 'bottom-right' && { bottom: '20px', right: '20px' }),
88
- ...(position === 'bottom-left' && { bottom: '20px', left: '20px' }),
89
- ...(position === 'top-right' && { top: '20px', right: '20px' }),
90
- ...(position === 'top-left' && { top: '20px', left: '20px' }),
46
+ width: "300px",
47
+ display: "flex",
48
+ flexDirection: "column",
49
+ alignItems: "flex-start",
50
+ borderRadius: "8px",
51
+ boxShadow: "0 4px 26px 0 rgba(0, 0, 0, 0.10)",
52
+ overflow: "hidden",
53
+ animation: "slideInUp 0.3s ease-out",
54
+ ...(position === "bottom-right" && { bottom: "20px", right: "20px" }),
55
+ ...(position === "bottom-left" && { bottom: "20px", left: "20px" }),
56
+ ...(position === "top-right" && { top: "20px", right: "20px" }),
57
+ ...(position === "top-left" && { top: "20px", left: "20px" }),
91
58
  };
92
59
  const closeButtonStyles = {
93
- display: 'flex',
94
- padding: '4px 2px',
95
- justifyContent: 'center',
96
- alignItems: 'center',
97
- gap: '2px',
98
- position: 'absolute',
99
- right: '7px',
100
- top: '7px',
101
- borderRadius: '8px',
102
- background: 'rgba(255, 255, 255, 0.10)',
103
- border: 'none',
104
- cursor: 'pointer',
105
- transition: 'background 0.2s ease',
60
+ display: "flex",
61
+ height: "28px",
62
+ width: "28px",
63
+ padding: "8.75px",
64
+ justifyContent: "center",
65
+ alignItems: "center",
66
+ gap: "8.75px",
67
+ position: "absolute",
68
+ right: "7px",
69
+ top: "7px",
70
+ borderRadius: "7875px",
71
+ border: "1.167px solid rgba(0, 0, 0, 0.08)",
72
+ background: "#FFF",
73
+ cursor: "pointer",
74
+ transition: "all 0.2s ease",
106
75
  zIndex: 10,
107
- backdropFilter: 'blur(10px)',
108
- WebkitBackdropFilter: 'blur(10px)',
76
+ boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
109
77
  };
110
78
  const imageContainerStyles = {
111
- position: 'relative',
112
- height: '168.75px',
113
- aspectRatio: '16/9',
114
- width: '100%',
115
- overflow: 'hidden',
116
- borderRadius: '8px 8px 0 0',
117
- backgroundColor: '#f5f5f5',
79
+ position: "relative",
80
+ height: "168.75px",
81
+ aspectRatio: "16/9",
82
+ width: "100%",
83
+ overflow: "hidden",
84
+ borderRadius: "8px 8px 0 0",
85
+ backgroundColor: "#f5f5f5",
118
86
  };
119
- // Add keyframe animation dynamically
120
87
  React.useEffect(() => {
121
- // Check if animation already exists
122
- const styleId = 'floating-card-animations';
88
+ const styleId = "floating-card-animations";
123
89
  if (!document.getElementById(styleId)) {
124
- const style = document.createElement('style');
90
+ const style = document.createElement("style");
125
91
  style.id = styleId;
126
92
  style.innerHTML = `
127
93
  @keyframes slideInUp {
@@ -142,10 +108,7 @@ export const FloatingCard = ({ data, shopId: propsShopId, onDismiss, onPrimaryAc
142
108
  document.head.appendChild(style);
143
109
  }
144
110
  }, []);
145
- return (_jsx("div", { ref: tracking?.elementRef, style: floatingCardStyles, children: _jsxs(Card, { padding: "0", roundedAbove: "sm", children: [(showCloseButton && data.dismissible !== false) && (_jsx("button", { style: closeButtonStyles, onClick: handleDismiss, "aria-label": "Close", children: _jsx("div", { style: {
146
- width: "20px",
147
- height: "20ox"
148
- }, children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", children: _jsx("path", { d: "M6.71967 7.78033C7.01256 8.07322 7.48744 8.07322 7.78033 7.78033C8.07322 7.48744 8.07322 7.01256 7.78033 6.71967L5.06066 4L7.78033 1.28033C8.07322 0.987437 8.07322 0.512563 7.78033 0.21967C7.48744 -0.073223 7.01256 -0.073223 6.71967 0.21967L4 2.93934L1.28033 0.21967C0.987437 -0.0732233 0.512564 -0.0732233 0.21967 0.21967C-0.0732225 0.512563 -0.0732226 0.987437 0.21967 1.28033L2.93934 4L0.21967 6.71967C-0.0732233 7.01256 -0.0732233 7.48744 0.21967 7.78033C0.512563 8.07322 0.987437 8.07322 1.28033 7.78033L4 5.06066L6.71967 7.78033Z", fill: "white", fillOpacity: "0.6" }) }) }) })), _jsxs(BlockStack, { gap: "0", children: [data.img_url && (_jsx("div", { style: imageContainerStyles, children: _jsx("img", { src: data.img_url, alt: data.image_alt || data.title, style: {
111
+ return (_jsx("div", { ref: tracking?.elementRef, style: floatingCardStyles, children: _jsxs(Card, { padding: "0", roundedAbove: "sm", children: [showCloseButton && data.dismissible !== false && (_jsx("button", { style: closeButtonStyles, onClick: handleDismiss, "aria-label": "Close", children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "10", height: "10", viewBox: "0 0 10 10", fill: "#111111", children: _jsx("path", { d: "M8.06721 8.99529C8.32349 9.25157 8.73901 9.25157 8.99529 8.99529C9.25157 8.73901 9.25157 8.32349 8.99529 8.06721L5.52183 4.59375L8.99529 1.12029C9.25157 0.864008 9.25157 0.448493 8.99529 0.192212C8.73901 -0.06407 8.32349 -0.06407 8.06721 0.192212L4.59375 3.66567L1.12029 0.192211C0.864007 -0.0640704 0.448493 -0.0640704 0.192211 0.192211C-0.0640704 0.448493 -0.0640705 0.864007 0.192211 1.12029L3.66567 4.59375L0.192212 8.06721C-0.06407 8.32349 -0.06407 8.73901 0.192212 8.99529C0.448493 9.25157 0.864008 9.25157 1.12029 8.99529L4.59375 5.52183L8.06721 8.99529Z", fill: "#111111" }) }) })), _jsxs(BlockStack, { gap: "0", children: [data.img_url && (_jsx("div", { style: imageContainerStyles, children: _jsx("img", { src: data.img_url, alt: data.image_alt || data.title, style: {
149
112
  width: "100%",
150
113
  height: "100%",
151
114
  objectFit: "cover",
@@ -158,10 +121,14 @@ export const FloatingCard = ({ data, shopId: propsShopId, onDismiss, onPrimaryAc
158
121
  gap: "6px",
159
122
  }, children: [_jsxs("div", { style: {
160
123
  display: "flex",
161
- flexDirection: "row",
124
+ flexDirection: "column",
162
125
  gap: "6px",
163
- alignItems: "start"
164
- }, children: [_jsx(Text, { as: "h2", variant: "bodyLg", fontWeight: "semibold", children: data.title }), data.tag && (_jsx(Badge, { tone: data.tag.tone || "success", children: data.tag.label }))] }), _jsx(Text, { as: "p", variant: "bodySm", children: data.date })] }), _jsx(Text, { as: "p", variant: "bodyMd", children: data.description })] }), _jsxs(InlineStack, { gap: "200", children: [data.primary_action && (_jsx(Button, { variant: data.primary_action.variant === "primary"
126
+ alignItems: "start",
127
+ }, children: [data.tag && (_jsx(Badge
128
+ // tone={data.tag.tone || "success"}
129
+ , {
130
+ // tone={data.tag.tone || "success"}
131
+ tone: "success", children: data.tag.label })), _jsx(Text, { as: "h2", variant: "bodyLg", fontWeight: "semibold", children: data.title })] }), data.date && (_jsx(Text, { as: "p", variant: "bodySm", children: data.date }))] }), _jsx(Text, { as: "p", variant: "bodyMd", children: data.description })] }), _jsxs(InlineStack, { gap: "200", children: [data.primary_action && (_jsx(Button, { icon: ExternalIcon, variant: data.primary_action.variant === "primary"
165
132
  ? "primary"
166
133
  : "plain", onClick: handlePrimaryAction, children: data.primary_action.label })), data.secondary_action && (_jsx(Button, { variant: "tertiary", onClick: handleSecondaryAction, children: data.secondary_action.label }))] })] }) })] })] }) }));
167
134
  };
@@ -1 +1 @@
1
- {"version":3,"file":"FloatingCard.js","sourceRoot":"","sources":["../../src/components/FloatingCard.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,IAAI,EACJ,UAAU,EACV,WAAW,EACX,IAAI,EACJ,KAAK,EACL,MAAM,EACN,GAAG,GACJ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA+C5C,MAAM,CAAC,MAAM,YAAY,GAAgC,CAAC,EACxD,IAAI,EACJ,MAAM,EAAE,WAAW,EACnB,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,QAAQ,GAAG,cAAc,EACzB,eAAe,GAAG,IAAI,GACvB,EAAE,EAAE;IACH,yDAAyD;IACzD,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACvB,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,WAAW,IAAI,aAAa,CAAC;IAE5C,0BAA0B;IAC1B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,EAAE,CAAC;IAE/C,2BAA2B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EAAE,QAAQ;oDACvB,GAAG,EAAE,KAAK;iDACX,aAED,eAAK,KAAK,EAAE;4DACV,OAAO,EAAE,MAAM;4DACf,aAAa,EAAE,KAAK;4DACpB,GAAG,EAAE,KAAK;4DACV,UAAU,EAAE,OAAO;yDACpB,aACC,KAAC,IAAI,IAAC,EAAE,EAAC,IAAI,EAAC,OAAO,EAAC,QAAQ,EAAC,UAAU,EAAC,UAAU,YACjD,IAAI,CAAC,KAAK,GACN,EACN,IAAI,CAAC,GAAG,IAAI,CACX,KAAC,KAAK,IAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS,YACpC,IAAI,CAAC,GAAG,CAAC,KAAK,GACT,CACT,IACG,EAEN,KAAC,IAAI,IAAC,EAAE,EAAC,GAAG,EAAC,OAAO,EAAC,QAAQ,YAC1B,IAAI,CAAC,IAAI,GACL,IACH,EAEN,KAAC,IAAI,IAAC,EAAE,EAAC,GAAG,EAAC,OAAO,EAAC,QAAQ,YAC1B,IAAI,CAAC,WAAW,GACZ,IACI,EACb,MAAC,WAAW,IAAC,GAAG,EAAC,KAAK,aACnB,IAAI,CAAC,cAAc,IAAI,CACtB,KAAC,MAAM,IACL,OAAO,EACL,IAAI,CAAC,cAAc,CAAC,OAAO,KAAK,SAAS;oDACvC,CAAC,CAAC,SAAS;oDACX,CAAC,CAAC,OAAO,EAEb,OAAO,EAAE,mBAAmB,YAE3B,IAAI,CAAC,cAAc,CAAC,KAAK,GACnB,CACV,EACA,IAAI,CAAC,gBAAgB,IAAI,CACxB,KAAC,MAAM,IAAC,OAAO,EAAC,UAAU,EAAC,OAAO,EAAE,qBAAqB,YACtD,IAAI,CAAC,gBAAgB,CAAC,KAAK,GACrB,CACV,IACW,IACH,GACT,IACK,IACR,GACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import React, { CSSProperties } from \"react\";\nimport {\n Card,\n BlockStack,\n InlineStack,\n Text,\n Badge,\n Button,\n Box,\n} from \"@shopify/polaris\";\nimport { useCampaignTracking } from \"../hooks/useCampaignTracking\";\nimport { useSDK } from \"../core/SDKManager\";\n\nexport interface FloatingCardData {\n id: number;\n key: string;\n type: string;\n priority: number;\n title: string;\n description: string;\n date: string;\n tag?: {\n label: string;\n tone: \"success\" | \"info\" | \"warning\" | \"critical\" | \"new\";\n };\n img_url: string;\n image_alt?: string | null;\n image_type: string;\n primary_action?: {\n label: string;\n url: string;\n external: boolean;\n variant: \"primary\" | \"secondary\";\n };\n secondary_action?: {\n label: string;\n url: string;\n external: boolean;\n variant: \"primary\" | \"secondary\";\n };\n dismissible: boolean;\n auto_close_after?: number | null;\n reappear_interval?: number | null;\n display_pages?: string[];\n campaign_id?: string | number; // Added for tracking purposes\n}\n\ninterface FloatingCardProps {\n data: FloatingCardData;\n shopId?: string; // Required for tracking\n onDismiss?: () => void;\n onPrimaryAction?: (data: FloatingCardData) => void;\n onSecondaryAction?: (data: FloatingCardData) => void;\n position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';\n animationType?: 'slide' | 'fade';\n showCloseButton?: boolean;\n}\n\nexport const FloatingCard: React.FC<FloatingCardProps> = ({\n data,\n shopId: propsShopId,\n onDismiss,\n onPrimaryAction,\n onSecondaryAction,\n position = 'bottom-right',\n showCloseButton = true,\n}) => {\n // Get shopId from SDK shopInfo if not provided via props\n const sdk = useSDK({});\n const contextShopId = sdk.shopInfo?.id;\n const shopId = propsShopId || contextShopId;\n \n // Early return if no data\n if (!data) {\n return null;\n }\n \n // Use the campaign ID from data or fallback to regular id\n const campaignId = data.campaign_id || data.id;\n \n // Set up campaign tracking\n const tracking = shopId && campaignId ? useCampaignTracking({\n shopId,\n campaignId,\n threshold: 0.5, // Track when 50% visible\n visibilityDuration: 1000, // Track view after 1 second\n metadata: {\n card_type: data.type,\n card_key: data.key,\n },\n }) : null;\n const handlePrimaryAction = () => {\n // Track the click\n tracking?.trackPrimaryAction();\n \n if (data.primary_action) {\n const url = data.primary_action.url;\n \n // Check if it's an external URL\n if (data.primary_action.external) {\n window.open(url, \"_blank\");\n } \n // Check if it's a modal trigger\n else if (url === \"modal\" || url === \"/pricing\") {\n // Pass the full card data to the handler for modal handling\n onPrimaryAction?.(data);\n }\n // Check if it's an internal route\n else if (url?.startsWith(\"/\")) {\n // Pass the full card data for internal navigation\n onPrimaryAction?.(data);\n }\n // Default: just call the handler\n else {\n onPrimaryAction?.(data);\n }\n }\n };\n\n const handleSecondaryAction = () => {\n // Track the click\n tracking?.trackSecondaryAction();\n \n if (data.secondary_action) {\n const url = data.secondary_action.url;\n \n if (data.secondary_action.external) {\n window.open(url, \"_blank\");\n } else if (url?.startsWith(\"/\") || url === \"modal\") {\n // Pass the full card data for internal handling\n onSecondaryAction?.(data);\n } else {\n onSecondaryAction?.(data);\n }\n }\n };\n \n const handleDismiss = () => {\n // Track the dismiss\n tracking?.trackDismiss();\n onDismiss?.();\n };\n\n // CSS-in-JS styles - no external CSS file needed\n const floatingCardStyles: CSSProperties = {\n position: 'fixed',\n zIndex: 9999,\n width: '300px',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'flex-start',\n borderRadius: '8px',\n boxShadow: '0 4px 26px 0 rgba(0, 0, 0, 0.10)',\n overflow: 'hidden',\n animation: 'slideInUp 0.3s ease-out',\n ...(position === 'bottom-right' && { bottom: '20px', right: '20px' }),\n ...(position === 'bottom-left' && { bottom: '20px', left: '20px' }),\n ...(position === 'top-right' && { top: '20px', right: '20px' }),\n ...(position === 'top-left' && { top: '20px', left: '20px' }),\n };\n\n const closeButtonStyles: CSSProperties = {\n display: 'flex',\n padding: '4px 2px',\n justifyContent: 'center',\n alignItems: 'center',\n gap: '2px',\n position: 'absolute',\n right: '7px',\n top: '7px',\n borderRadius: '8px',\n background: 'rgba(255, 255, 255, 0.10)',\n border: 'none',\n cursor: 'pointer',\n transition: 'background 0.2s ease',\n zIndex: 10,\n backdropFilter: 'blur(10px)',\n WebkitBackdropFilter: 'blur(10px)',\n };\n\n const imageContainerStyles: CSSProperties = {\n position: 'relative',\n height: '168.75px',\n aspectRatio: '16/9',\n width: '100%',\n overflow: 'hidden',\n borderRadius: '8px 8px 0 0',\n backgroundColor: '#f5f5f5',\n };\n\n // Add keyframe animation dynamically\n React.useEffect(() => {\n // Check if animation already exists\n const styleId = 'floating-card-animations';\n if (!document.getElementById(styleId)) {\n const style = document.createElement('style');\n style.id = styleId;\n style.innerHTML = `\n @keyframes slideInUp {\n from {\n transform: translateY(100%);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n }\n @keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n `;\n document.head.appendChild(style);\n }\n }, []);\n\n return (\n <div ref={tracking?.elementRef} style={floatingCardStyles}>\n <Card padding=\"0\" roundedAbove=\"sm\">\n {(showCloseButton && data.dismissible !== false) && (\n <button\n style={closeButtonStyles}\n onClick={handleDismiss}\n aria-label=\"Close\"\n >\n <div style={{\n width: \"20px\",\n height: \"20ox\"\n }}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"8\" height=\"8\" viewBox=\"0 0 8 8\" fill=\"none\">\n <path d=\"M6.71967 7.78033C7.01256 8.07322 7.48744 8.07322 7.78033 7.78033C8.07322 7.48744 8.07322 7.01256 7.78033 6.71967L5.06066 4L7.78033 1.28033C8.07322 0.987437 8.07322 0.512563 7.78033 0.21967C7.48744 -0.073223 7.01256 -0.073223 6.71967 0.21967L4 2.93934L1.28033 0.21967C0.987437 -0.0732233 0.512564 -0.0732233 0.21967 0.21967C-0.0732225 0.512563 -0.0732226 0.987437 0.21967 1.28033L2.93934 4L0.21967 6.71967C-0.0732233 7.01256 -0.0732233 7.48744 0.21967 7.78033C0.512563 8.07322 0.987437 8.07322 1.28033 7.78033L4 5.06066L6.71967 7.78033Z\" fill=\"white\" fillOpacity=\"0.6\"/>\n </svg>\n </div>\n </button>\n )}\n\n <BlockStack gap=\"0\">\n {data.img_url && (\n <div style={imageContainerStyles}>\n <img\n src={data.img_url}\n alt={data.image_alt || data.title}\n style={{\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n }}\n onError={(e) => {\n console.error(\"Image failed to load:\", data.img_url);\n (e.target as HTMLImageElement).style.display = \"none\";\n }}\n />\n </div>\n )}\n\n <Box padding=\"400\">\n <BlockStack gap=\"500\">\n <BlockStack gap=\"300\">\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"6px\",\n }}\n >\n <div style={{\n display: \"flex\",\n flexDirection: \"row\",\n gap: \"6px\",\n alignItems: \"start\"\n }}>\n <Text as=\"h2\" variant=\"bodyLg\" fontWeight=\"semibold\">\n {data.title}\n </Text>\n {data.tag && (\n <Badge tone={data.tag.tone || \"success\"}>\n {data.tag.label}\n </Badge>\n )}\n </div>\n\n <Text as=\"p\" variant=\"bodySm\">\n {data.date}\n </Text>\n </div>\n\n <Text as=\"p\" variant=\"bodyMd\">\n {data.description}\n </Text>\n </BlockStack>\n <InlineStack gap=\"200\">\n {data.primary_action && (\n <Button\n variant={\n data.primary_action.variant === \"primary\"\n ? \"primary\"\n : \"plain\"\n }\n onClick={handlePrimaryAction}\n >\n {data.primary_action.label}\n </Button>\n )}\n {data.secondary_action && (\n <Button variant=\"tertiary\" onClick={handleSecondaryAction}>\n {data.secondary_action.label}\n </Button>\n )}\n </InlineStack>\n </BlockStack>\n </Box>\n </BlockStack>\n </Card>\n </div>\n );\n};\n\nexport default FloatingCard;\n"]}
1
+ {"version":3,"file":"FloatingCard.js","sourceRoot":"","sources":["../../src/components/FloatingCard.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,IAAI,EACJ,UAAU,EACV,WAAW,EACX,IAAI,EACJ,KAAK,EACL,MAAM,EACN,GAAG,GACJ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,oB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I,IAAC,EAAE,EAAC,GAAG,EAAC,OAAO,EAAC,QAAQ,YAC1B,IAAI,CAAC,WAAW,GACZ,IACI,EACb,MAAC,WAAW,IAAC,GAAG,EAAC,KAAK,aACnB,IAAI,CAAC,cAAc,IAAI,CACtB,KAAC,MAAM,IACL,IAAI,EAAE,YAAY,EAClB,OAAO,EACL,IAAI,CAAC,cAAc,CAAC,OAAO,KAAK,SAAS;oDACvC,CAAC,CAAC,SAAS;oDACX,CAAC,CAAC,OAAO,EAEb,OAAO,EAAE,mBAAmB,YAE3B,IAAI,CAAC,cAAc,CAAC,KAAK,GACnB,CACV,EACA,IAAI,CAAC,gBAAgB,IAAI,CACxB,KAAC,MAAM,IAAC,OAAO,EAAC,UAAU,EAAC,OAAO,EAAE,qBAAqB,YACtD,IAAI,CAAC,gBAAgB,CAAC,KAAK,GACrB,CACV,IACW,IACH,GACT,IACK,IACR,GACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import React, { CSSProperties } from \"react\";\nimport {\n Card,\n BlockStack,\n InlineStack,\n Text,\n Badge,\n Button,\n Box,\n} from \"@shopify/polaris\";\nimport { useCampaignTracking } from \"../hooks/useCampaignTracking\";\nimport { useSDK } from \"../core/SDKManager\";\nimport { ExternalIcon } from \"@shopify/polaris-icons\";\n\nexport interface FloatingCardData {\n id: number;\n key: string;\n type: string;\n priority: number;\n title: string;\n description: string;\n date?: string | null;\n tag?: {\n label: string;\n tone: \"success\" | \"info\" | \"warning\" | \"critical\" | \"new\";\n };\n img_url: string;\n image_alt?: string | null;\n image_type: string;\n primary_action?: {\n label: string;\n url: string;\n external: boolean;\n variant: \"primary\" | \"secondary\";\n };\n secondary_action?: {\n label: string;\n url: string;\n external: boolean;\n variant: \"primary\" | \"secondary\";\n };\n dismissible: boolean;\n auto_close_after?: number | null;\n reappear_interval?: number | null;\n display_pages?: string[];\n campaign_id?: string | number;\n}\n\ninterface FloatingCardProps {\n data: FloatingCardData;\n shopId?: string;\n onDismiss?: () => void;\n onPrimaryAction?: (data: FloatingCardData) => void;\n onSecondaryAction?: (data: FloatingCardData) => void;\n position?: \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\";\n animationType?: \"slide\" | \"fade\";\n showCloseButton?: boolean;\n}\n\nexport const FloatingCard: React.FC<FloatingCardProps> = ({\n data,\n shopId: propsShopId,\n onDismiss,\n onPrimaryAction,\n onSecondaryAction,\n position = \"bottom-right\",\n showCloseButton = true,\n}) => {\n const sdk = useSDK({});\n const contextShopId = sdk.shopInfo?.id;\n const shopId = propsShopId || contextShopId;\n\n if (!data) {\n return null;\n }\n\n const campaignId = data.campaign_id || data.id;\n\n const tracking =\n shopId && campaignId\n ? useCampaignTracking({\n shopId,\n campaignId,\n threshold: 0.5,\n visibilityDuration: 1000,\n metadata: {\n card_type: data.type,\n card_key: data.key,\n },\n })\n : null;\n const handlePrimaryAction = () => {\n tracking?.trackPrimaryAction();\n\n if (data.primary_action) {\n onPrimaryAction?.(data);\n }\n };\n\n const handleSecondaryAction = () => {\n tracking?.trackSecondaryAction();\n if (data.secondary_action) {\n onSecondaryAction?.(data);\n }\n };\n\n const handleDismiss = () => {\n tracking?.trackDismiss();\n onDismiss?.();\n };\n\n const floatingCardStyles: CSSProperties = {\n position: \"fixed\",\n zIndex: 9999,\n width: \"300px\",\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"flex-start\",\n borderRadius: \"8px\",\n boxShadow: \"0 4px 26px 0 rgba(0, 0, 0, 0.10)\",\n overflow: \"hidden\",\n animation: \"slideInUp 0.3s ease-out\",\n ...(position === \"bottom-right\" && { bottom: \"20px\", right: \"20px\" }),\n ...(position === \"bottom-left\" && { bottom: \"20px\", left: \"20px\" }),\n ...(position === \"top-right\" && { top: \"20px\", right: \"20px\" }),\n ...(position === \"top-left\" && { top: \"20px\", left: \"20px\" }),\n };\n\n const closeButtonStyles: CSSProperties = {\n display: \"flex\",\n height: \"28px\",\n width: \"28px\",\n padding: \"8.75px\",\n justifyContent: \"center\",\n alignItems: \"center\",\n gap: \"8.75px\",\n position: \"absolute\",\n right: \"7px\",\n top: \"7px\",\n borderRadius: \"7875px\",\n border: \"1.167px solid rgba(0, 0, 0, 0.08)\",\n background: \"#FFF\",\n cursor: \"pointer\",\n transition: \"all 0.2s ease\",\n zIndex: 10,\n boxShadow: \"0 2px 4px rgba(0, 0, 0, 0.1)\",\n };\n\n const imageContainerStyles: CSSProperties = {\n position: \"relative\",\n height: \"168.75px\",\n aspectRatio: \"16/9\",\n width: \"100%\",\n overflow: \"hidden\",\n borderRadius: \"8px 8px 0 0\",\n backgroundColor: \"#f5f5f5\",\n };\n\n React.useEffect(() => {\n const styleId = \"floating-card-animations\";\n if (!document.getElementById(styleId)) {\n const style = document.createElement(\"style\");\n style.id = styleId;\n style.innerHTML = `\n @keyframes slideInUp {\n from {\n transform: translateY(100%);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n }\n @keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n `;\n document.head.appendChild(style);\n }\n }, []);\n\n return (\n <div ref={tracking?.elementRef} style={floatingCardStyles}>\n <Card padding=\"0\" roundedAbove=\"sm\">\n {showCloseButton && data.dismissible !== false && (\n <button\n style={closeButtonStyles}\n onClick={handleDismiss}\n aria-label=\"Close\"\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"10\"\n height=\"10\"\n viewBox=\"0 0 10 10\"\n fill=\"#111111\"\n >\n <path\n d=\"M8.06721 8.99529C8.32349 9.25157 8.73901 9.25157 8.99529 8.99529C9.25157 8.73901 9.25157 8.32349 8.99529 8.06721L5.52183 4.59375L8.99529 1.12029C9.25157 0.864008 9.25157 0.448493 8.99529 0.192212C8.73901 -0.06407 8.32349 -0.06407 8.06721 0.192212L4.59375 3.66567L1.12029 0.192211C0.864007 -0.0640704 0.448493 -0.0640704 0.192211 0.192211C-0.0640704 0.448493 -0.0640705 0.864007 0.192211 1.12029L3.66567 4.59375L0.192212 8.06721C-0.06407 8.32349 -0.06407 8.73901 0.192212 8.99529C0.448493 9.25157 0.864008 9.25157 1.12029 8.99529L4.59375 5.52183L8.06721 8.99529Z\"\n fill=\"#111111\"\n />\n </svg>\n </button>\n )}\n\n <BlockStack gap=\"0\">\n {data.img_url && (\n <div style={imageContainerStyles}>\n <img\n src={data.img_url}\n alt={data.image_alt || data.title}\n style={{\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n }}\n onError={(e) => {\n console.error(\"Image failed to load:\", data.img_url);\n (e.target as HTMLImageElement).style.display = \"none\";\n }}\n />\n </div>\n )}\n\n <Box padding=\"400\">\n <BlockStack gap=\"500\">\n <BlockStack gap=\"300\">\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"6px\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"6px\",\n alignItems: \"start\",\n }}\n >\n {data.tag && (\n <Badge\n // tone={data.tag.tone || \"success\"}\n tone=\"success\"\n >\n {data.tag.label}\n </Badge>\n )}\n <Text as=\"h2\" variant=\"bodyLg\" fontWeight=\"semibold\">\n {data.title}\n </Text>\n </div>\n\n {data.date && (\n <Text as=\"p\" variant=\"bodySm\">\n {data.date}\n </Text>\n )}\n </div>\n\n <Text as=\"p\" variant=\"bodyMd\">\n {data.description}\n </Text>\n </BlockStack>\n <InlineStack gap=\"200\">\n {data.primary_action && (\n <Button\n icon={ExternalIcon}\n variant={\n data.primary_action.variant === \"primary\"\n ? \"primary\"\n : \"plain\"\n }\n onClick={handlePrimaryAction}\n >\n {data.primary_action.label}\n </Button>\n )}\n {data.secondary_action && (\n <Button variant=\"tertiary\" onClick={handleSecondaryAction}>\n {data.secondary_action.label}\n </Button>\n )}\n </InlineStack>\n </BlockStack>\n </Box>\n </BlockStack>\n </Card>\n </div>\n );\n};\n\nexport default FloatingCard;\n"]}
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ export interface MarketingCampaignData {
3
+ id: number;
4
+ key: string;
5
+ type: string;
6
+ priority: number;
7
+ title: string;
8
+ subtitle?: string;
9
+ description: string;
10
+ badge_text?: string;
11
+ badge_tone?: "success" | "info" | "warning" | "critical" | "new";
12
+ tag?: {
13
+ label: string;
14
+ tone?: "success" | "info" | "warning" | "critical" | "new" | "primary";
15
+ };
16
+ highlight_text?: string;
17
+ img_url: string;
18
+ image_alt?: string | null;
19
+ image_type: string;
20
+ primary_action?: {
21
+ label: string;
22
+ url: string;
23
+ external: boolean;
24
+ variant?: "primary" | "secondary";
25
+ };
26
+ secondary_action?: {
27
+ label: string;
28
+ url: string;
29
+ external: boolean;
30
+ variant?: "primary" | "secondary";
31
+ };
32
+ dismissible: boolean;
33
+ campaign_id?: string | number;
34
+ }
35
+ export interface MarketingCampaignCardProps {
36
+ shopId?: string;
37
+ locale?: string;
38
+ onDismiss?: (data: MarketingCampaignData) => void;
39
+ onPrimaryAction?: (data: MarketingCampaignData) => void;
40
+ onSecondaryAction?: (data: MarketingCampaignData) => void;
41
+ }
42
+ export declare const MarketingCampaignCard: React.FC<MarketingCampaignCardProps>;
43
+ export default MarketingCampaignCard;
44
+ //# sourceMappingURL=MarketingCampaignCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarketingCampaignCard.d.ts","sourceRoot":"","sources":["../../src/components/MarketingCampaignCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAkBnD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,GAA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xs } from "react/jsx-runtime";
2
+ import React, { useState, useEffect } from "react";
3
+ import { Card, BlockStack, InlineGrid, Text, Button, Box, Badge, InlineStack, Icon, Popover, ActionList, } from "@shopify/polaris";
4
+ import { MenuHorizontalIcon, XIcon } from "@shopify/polaris-icons";
5
+ import { useCampaignTracking } from "../hooks/useCampaignTracking";
6
+ import { useSDK } from "../core/SDKManager";
7
+ export const MarketingCampaignCard = ({ shopId: propsShopId, locale = "en", onDismiss, onPrimaryAction, onSecondaryAction, }) => {
8
+ const [campaignData, setCampaignData] = useState(null);
9
+ const [loading, setLoading] = useState(true);
10
+ const [isDismissed, setIsDismissed] = useState(false);
11
+ const [isHovered, setIsHovered] = useState(false);
12
+ const [popoverActive, setPopoverActive] = useState(false);
13
+ const sdk = useSDK({});
14
+ const contextShopId = sdk.shopInfo?.id;
15
+ const shopId = propsShopId || contextShopId;
16
+ const currentLocale = locale || sdk.locale || "en";
17
+ const tracking = useCampaignTracking(shopId && campaignData
18
+ ? {
19
+ shopId,
20
+ campaignId: campaignData.campaign_id || campaignData.id,
21
+ threshold: 0.5,
22
+ visibilityDuration: 1000,
23
+ metadata: {
24
+ card_type: campaignData.type,
25
+ card_key: campaignData.key,
26
+ },
27
+ }
28
+ : {
29
+ shopId: "",
30
+ campaignId: "",
31
+ threshold: 0.5,
32
+ visibilityDuration: 1000,
33
+ });
34
+ useEffect(() => {
35
+ const fetchCampaignData = async () => {
36
+ if (!shopId) {
37
+ setLoading(false);
38
+ return;
39
+ }
40
+ try {
41
+ setLoading(true);
42
+ let baseUrl;
43
+ if (sdk.config?.apiUrl) {
44
+ const configUrl = sdk.config.apiUrl;
45
+ if (configUrl.includes("/dashboard")) {
46
+ baseUrl = configUrl.replace("/dashboard", "");
47
+ }
48
+ else {
49
+ baseUrl = configUrl;
50
+ }
51
+ }
52
+ else {
53
+ baseUrl =
54
+ typeof window !== "undefined" &&
55
+ window.location.hostname === "localhost"
56
+ ? "/api"
57
+ : "https://ops.trustshop.io/api";
58
+ }
59
+ const apiUrl = `${baseUrl}/campaigns?shop_id=${shopId}&locale=${currentLocale}`;
60
+ const response = await fetch(apiUrl, {
61
+ method: "GET",
62
+ headers: {
63
+ Accept: "application/json",
64
+ "Content-Type": "application/json",
65
+ "Accept-Language": currentLocale,
66
+ ...(sdk.config?.headers || {}),
67
+ },
68
+ credentials: "include",
69
+ });
70
+ if (!response.ok) {
71
+ throw new Error(`Failed to fetch campaigns: ${response.statusText}`);
72
+ }
73
+ const data = await response.json();
74
+ if (data.success && Array.isArray(data.data) && data.data.length > 0) {
75
+ const marketingCampaigns = data.data.filter((campaign) => campaign.type === "marketing-card");
76
+ if (marketingCampaigns.length > 0) {
77
+ const campaign = marketingCampaigns[0];
78
+ const dismissKey = `trustshop_marketing_campaign_dismissed_${campaign.key || campaign.id}`;
79
+ try {
80
+ const dismissedData = localStorage.getItem(dismissKey);
81
+ if (dismissedData) {
82
+ const parsed = JSON.parse(dismissedData);
83
+ const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
84
+ if (parsed.timestamp > sevenDaysAgo) {
85
+ setIsDismissed(true);
86
+ return;
87
+ }
88
+ }
89
+ }
90
+ catch (error) {
91
+ console.error("Failed to check dismiss state:", error);
92
+ }
93
+ setCampaignData(campaign);
94
+ }
95
+ }
96
+ }
97
+ catch (err) {
98
+ console.error("Failed to fetch marketing campaign:", err);
99
+ }
100
+ finally {
101
+ setLoading(false);
102
+ }
103
+ };
104
+ fetchCampaignData();
105
+ const handleCampaignsRefresh = (event) => {
106
+ if (event.detail?.data && Array.isArray(event.detail.data)) {
107
+ const marketingCampaigns = event.detail.data.filter((campaign) => campaign.type === "marketing-card");
108
+ if (marketingCampaigns.length > 0) {
109
+ setCampaignData(marketingCampaigns[0]);
110
+ }
111
+ }
112
+ };
113
+ window.addEventListener("trustshop-campaigns-refresh", handleCampaignsRefresh);
114
+ return () => {
115
+ window.removeEventListener("trustshop-campaigns-refresh", handleCampaignsRefresh);
116
+ };
117
+ }, [shopId, currentLocale, sdk.config]);
118
+ const handlePrimaryAction = () => {
119
+ tracking?.trackPrimaryAction();
120
+ if (campaignData?.primary_action) {
121
+ onPrimaryAction?.(campaignData);
122
+ }
123
+ };
124
+ const handleSecondaryAction = () => {
125
+ tracking?.trackSecondaryAction();
126
+ if (campaignData?.secondary_action) {
127
+ onSecondaryAction?.(campaignData);
128
+ }
129
+ };
130
+ const handleDismiss = () => {
131
+ tracking?.trackDismiss();
132
+ setIsDismissed(true);
133
+ setPopoverActive(false);
134
+ if (campaignData) {
135
+ const dismissKey = `trustshop_marketing_campaign_dismissed_${campaignData.key || campaignData.id}`;
136
+ const dismissData = {
137
+ timestamp: Date.now(),
138
+ dismissed: true,
139
+ campaignId: campaignData.id,
140
+ campaignKey: campaignData.key,
141
+ };
142
+ try {
143
+ localStorage.setItem(dismissKey, JSON.stringify(dismissData));
144
+ }
145
+ catch (error) {
146
+ console.error("Failed to save dismiss state:", error);
147
+ }
148
+ }
149
+ onDismiss?.(campaignData);
150
+ };
151
+ const togglePopoverActive = () => setPopoverActive((active) => !active);
152
+ React.useEffect(() => {
153
+ const styleId = "marketing-campaign-responsive";
154
+ if (!document.getElementById(styleId)) {
155
+ const style = document.createElement("style");
156
+ style.id = styleId;
157
+ style.innerHTML = `
158
+ @media (max-width: 768px) {
159
+ .marketing-campaign-grid {
160
+ display: flex !important;
161
+ flex-direction: column !important;
162
+ }
163
+ .marketing-campaign-content {
164
+ order: 2;
165
+ }
166
+ .marketing-campaign-image {
167
+ order: 1;
168
+ padding: 16px 16px 0 16px !important;
169
+ }
170
+ }
171
+ `;
172
+ document.head.appendChild(style);
173
+ }
174
+ return () => {
175
+ const existingStyle = document.getElementById(styleId);
176
+ if (existingStyle &&
177
+ document.querySelectorAll(".marketing-campaign-grid").length === 0) {
178
+ existingStyle.remove();
179
+ }
180
+ };
181
+ }, []);
182
+ if (loading || !campaignData || isDismissed) {
183
+ return null;
184
+ }
185
+ return (_jsx("div", { ref: tracking?.elementRef, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), style: { position: "relative" }, children: _jsx(Card, { children: _jsx("div", { className: "marketing-campaign-grid", children: _jsxs(InlineGrid, { columns: {
186
+ xs: 1,
187
+ sm: 1,
188
+ md: ["twoThirds", "oneThird"],
189
+ lg: ["twoThirds", "oneThird"],
190
+ xl: ["twoThirds", "oneThird"],
191
+ }, gap: "1000", children: [_jsx("div", { className: "marketing-campaign-content", children: _jsx(Box, { paddingInline: { xs: "200", sm: "200", md: "300" }, children: _jsxs(BlockStack, { gap: "300", children: [_jsxs(BlockStack, { gap: "100", children: [_jsx(Box, { children: campaignData.tag?.label && (_jsx(Badge, { tone: campaignData.tag.tone === "primary"
192
+ ? "success"
193
+ : campaignData.tag.tone || "success", children: campaignData.tag.label })) }), _jsxs(BlockStack, { gap: "100", children: [_jsx(Text, { as: "h2", variant: "headingLg", fontWeight: "bold", children: campaignData.title }), campaignData.subtitle && (_jsx(Text, { as: "p", variant: "headingXl", fontWeight: "bold", children: campaignData.subtitle })), _jsx(Text, { as: "p", variant: "bodyMd", tone: "subdued", children: campaignData.description })] })] }), _jsxs(InlineStack, { gap: "200", children: [campaignData.primary_action && (_jsx(Button, { variant: "primary", onClick: handlePrimaryAction, children: campaignData.primary_action.label })), campaignData.secondary_action && (_jsx(Button, { onClick: handleSecondaryAction, children: campaignData.secondary_action.label }))] })] }) }) }), _jsx("div", { className: "marketing-campaign-image", children: _jsxs(Box, { padding: "0", position: "relative", minHeight: "200", children: [campaignData.dismissible && isHovered && (_jsx("div", { style: {
194
+ position: "absolute",
195
+ right: "-5px",
196
+ top: "-5px",
197
+ zIndex: 10,
198
+ }, children: _jsx(Popover, { active: popoverActive, activator: _jsx(Button, { size: "slim", icon: _jsx(Icon, { source: MenuHorizontalIcon }), onClick: togglePopoverActive, accessibilityLabel: "More actions" }), onClose: togglePopoverActive, preferredPosition: "below", preferredAlignment: "right", children: _jsx(ActionList, { items: [
199
+ {
200
+ content: "Dismiss",
201
+ icon: XIcon,
202
+ onAction: handleDismiss,
203
+ },
204
+ ] }) }) })), _jsxs("div", { style: {
205
+ width: "100%",
206
+ height: "100%",
207
+ display: "flex",
208
+ alignItems: "center",
209
+ justifyContent: "center",
210
+ position: "relative",
211
+ }, children: [campaignData.img_url && (_jsx("img", { src: campaignData.img_url, alt: campaignData.image_alt || campaignData.title, style: {
212
+ width: "100%",
213
+ maxWidth: "300px",
214
+ height: "auto",
215
+ objectFit: "contain",
216
+ margin: "0 auto",
217
+ }, onError: (e) => {
218
+ console.error("Image failed to load:", campaignData.img_url);
219
+ e.target.style.display = "none";
220
+ } })), campaignData.highlight_text && (_jsx("div", { style: {
221
+ position: "absolute",
222
+ top: "20px",
223
+ right: "40px",
224
+ background: "#00B251",
225
+ color: "white",
226
+ padding: "12px 24px",
227
+ borderRadius: "8px",
228
+ fontWeight: "bold",
229
+ fontSize: "24px",
230
+ transform: "rotate(-5deg)",
231
+ boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)",
232
+ }, children: campaignData.highlight_text }))] })] }) })] }) }) }) }));
233
+ };
234
+ export default MarketingCampaignCard;
235
+ //# sourceMappingURL=MarketingCampaignCard.js.map