shopify-chatbot-widget 0.9.2 → 0.9.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "0.9.2",
4
+ "version": "0.9.3",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -12,7 +12,7 @@ import { motion, AnimatePresence } from 'framer-motion';
12
12
  import CartLayout from './components/Cart/Index';
13
13
 
14
14
  const Chatbot: React.FC = () => {
15
- const [open, setOpen] = useState(true);
15
+ const [open, setOpen] = useState(false);
16
16
  const [viewMode, setViewMode] = useState<'sessions' | 'create' | 'messenger' | 'cartView' >('sessions');
17
17
  const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
18
18
  const [HasInfo, setHasInfo] = useState(false);
@@ -100,16 +100,31 @@ const Chatbot: React.FC = () => {
100
100
  const onMessage = (e: MessageEvent) => {
101
101
  const msg = (e.data || {}) as any;
102
102
  if (msg.type !== 'JAWEB_CHAT') return;
103
-
104
- if (msg.action === 'open-ready') {
105
- setOpen(true);
106
- } else if (msg.action === 'closed') {
107
- setOpen(false);
103
+
104
+ switch (msg.action) {
105
+ case 'open-ready':
106
+ setOpen(true);
107
+ break;
108
+
109
+ case 'closed':
110
+ setOpen(false);
111
+ break;
112
+
113
+ case 'start-session':
114
+ console.log('[Chatbot] start-session message received');
115
+ handleNewSessionClick(); // 👈 Trigger new session automatically
116
+ break;
117
+
118
+ default:
119
+ break;
108
120
  }
109
121
  };
122
+
110
123
  window.addEventListener('message', onMessage);
111
124
  return () => window.removeEventListener('message', onMessage);
112
125
  }, []);
126
+
127
+
113
128
 
114
129
  const requestOpen = () => {
115
130
  window.parent?.postMessage({ type: 'JAWEB_CHAT', action: 'open' }, '*');
@@ -37,10 +37,10 @@ const SallaProductCarousel: FC<Props> = ({
37
37
  groupedProducts,
38
38
  selectedVariants,
39
39
  setSelectedVariants,
40
- // counts,
41
- // setCounts,
42
- // handleAddToCart,
43
- // handleRemoveFromCart,
40
+ counts,
41
+ setCounts,
42
+ handleAddToCart,
43
+ handleRemoveFromCart,
44
44
  colorCode = '#7F28F8',
45
45
  shortenName,
46
46
  sliderRef,
@@ -72,7 +72,7 @@ const SallaProductCarousel: FC<Props> = ({
72
72
 
73
73
  if (!currentVariant) return null;
74
74
 
75
- // const count = counts[currentVariant.variant_id] || 0;
75
+ const count = counts[currentVariant.variant_id] || 0;
76
76
 
77
77
  // Build unique, cleaned list of options (exclude empty/'none')
78
78
  const options = Array.from(
@@ -94,25 +94,25 @@ const SallaProductCarousel: FC<Props> = ({
94
94
  }
95
95
  };
96
96
 
97
- // const increment = async () => {
98
- // setCounts(prev => ({
99
- // ...prev,
100
- // [currentVariant.variant_id]: (prev[currentVariant.variant_id] || 0) + 1,
101
- // }));
102
- // await handleAddToCart(currentVariant.variant_id, currentVariant.name, 1);
103
- // };
104
-
105
- // const decrement = async () => {
106
- // if (count === 0) return;
107
- // setCounts(prev => ({
108
- // ...prev,
109
- // [currentVariant.variant_id]: Math.max(
110
- // 0,
111
- // (prev[currentVariant.variant_id] || 0) - 1
112
- // ),
113
- // }));
114
- // await handleRemoveFromCart(currentVariant.variant_id, 1);
115
- // };
97
+ const increment = async () => {
98
+ setCounts(prev => ({
99
+ ...prev,
100
+ [currentVariant.variant_id]: (prev[currentVariant.variant_id] || 0) + 1,
101
+ }));
102
+ await handleAddToCart(currentVariant.variant_id, currentVariant.name,currentVariant.image,currentVariant.price, 1);
103
+ };
104
+
105
+ const decrement = async () => {
106
+ if (count === 0) return;
107
+ setCounts(prev => ({
108
+ ...prev,
109
+ [currentVariant.variant_id]: Math.max(
110
+ 0,
111
+ (prev[currentVariant.variant_id] || 0) - 1
112
+ ),
113
+ }));
114
+ await handleRemoveFromCart(currentVariant.variant_id, 1);
115
+ };
116
116
 
117
117
  // Ensure the select has a stable value (fallback to first option)
118
118
 
@@ -180,8 +180,39 @@ const SallaProductCarousel: FC<Props> = ({
180
180
  </div>
181
181
  )}
182
182
 
183
-
184
- <Button
183
+ <div className="flex items-center justify-between w-full space-x-4">
184
+
185
+ <div className="sallaX-cta" aria-label="Quantity controls">
186
+ <button
187
+ type="button"
188
+ className="sallaX-qty sallaX-qty--minus"
189
+ onClick={decrement}
190
+ aria-label="Decrease quantity"
191
+ disabled={count === 0}
192
+ >
193
+
194
+ </button>
195
+ <output
196
+ className="sallaX-qtyCount"
197
+ aria-live="polite"
198
+ aria-atomic="true"
199
+ >
200
+ {count}
201
+ </output>
202
+ <button
203
+ type="button"
204
+ className="sallaX-qty sallaX-qty--plus"
205
+ onClick={increment}
206
+ aria-label="Increase quantity"
207
+ >
208
+ +
209
+ </button>
210
+ </div>
211
+
212
+
213
+ {/* Try On toggle button (kept) */}
214
+
215
+ <Button
185
216
  style={{ backgroundColor: colorCode, color: "white" }}
186
217
  className="px-6 py-2 rounded-lg shadow-md transition"
187
218
  onClick={() =>
@@ -189,27 +220,9 @@ const SallaProductCarousel: FC<Props> = ({
189
220
  }
190
221
  >
191
222
  {isTryOnOpen ? "Close Try On" : "Try On"}
192
- </Button>
193
- {/* <button
194
- type="button"
195
- className="sallaX-qty sallaX-qty--minus"
196
- onClick={decrement}
197
- aria-label="Decrease quantity"
198
- disabled={count === 0}
199
- >
200
-
201
- </button>
202
- <output className="sallaX-qtyCount" aria-live="polite" aria-atomic="true">
203
- {count}
204
- </output>
205
- <button
206
- type="button"
207
- className="sallaX-qty sallaX-qty--plus"
208
- onClick={increment}
209
- aria-label="Increase quantity"
210
- >
211
- +
212
- </button> */}
223
+ </Button>
224
+
225
+ </div>
213
226
 
214
227
  { isTryOnOpen && (
215
228
  <div className="mt-4">
@@ -22,6 +22,8 @@ export const useCartAPI = () => {
22
22
 
23
23
  if (data?.checkoutUrl) {
24
24
  // Open in parent frame for embedded chatbots
25
+ // window.open(data.checkoutUrl, '_blank'); // ✅ opens in new tab
26
+
25
27
  window.parent?.postMessage(
26
28
  {
27
29
  type: 'JAWEB_CHAT',