shopify-chatbot-widget 1.0.6 → 1.0.8

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": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -269,6 +269,8 @@ const [viewMode, setViewMode] = useState<'sessions' | 'create' | 'messenger' | '
269
269
  handleRemoveFromCart={handleRemoveFromCart}
270
270
  counts={counts}
271
271
  setCounts={setCounts}
272
+ addToCart={disbleCheckout}
273
+ userType={userType}
272
274
  />
273
275
  </motion.div>
274
276
  )}
@@ -1,10 +1,9 @@
1
- import React,{useState} from 'react';
1
+ import React from 'react';
2
2
  import type { FC } from 'react';
3
3
  import 'keen-slider/keen-slider.min.css';
4
4
  import type { KeenSliderInstance } from 'keen-slider/react';
5
5
  import './SallaSwiper.css';
6
6
  import { Button } from 'antd';
7
- import TryOnBox from "./TryOn";
8
7
 
9
8
  interface ProductVariant {
10
9
  variant_id: string;
@@ -31,25 +30,22 @@ interface Props {
31
30
  sliderInstance: React.MutableRefObject<KeenSliderInstance | null>;
32
31
  currentSlide: number;
33
32
  totalSlides: number;
33
+ onTryOnSelect: (product: ProductVariant) => void;
34
+ enableTry:boolean;
34
35
  }
35
36
 
36
37
  const SallaProductCarousel: FC<Props> = ({
37
38
  groupedProducts,
38
39
  selectedVariants,
39
40
  setSelectedVariants,
40
- counts,
41
- setCounts,
42
- handleAddToCart,
43
- handleRemoveFromCart,
44
41
  colorCode = '#7F28F8',
45
42
  shortenName,
46
43
  sliderRef,
47
- // sliderInstance, // currently unused
48
- // currentSlide, // currently unused
49
44
  totalSlides,
45
+ onTryOnSelect,
46
+ enableTry
50
47
  }) => {
51
48
  if (!totalSlides || totalSlides === 0) return null;
52
- const [openTryOn, setOpenTryOn] = useState<string | null>(null);
53
49
 
54
50
  return (
55
51
  <section
@@ -72,8 +68,6 @@ const SallaProductCarousel: FC<Props> = ({
72
68
 
73
69
  if (!currentVariant) return null;
74
70
 
75
- const count = counts[currentVariant.variant_id] || 0;
76
-
77
71
  // Build unique, cleaned list of options (exclude empty/'none')
78
72
  const options = Array.from(
79
73
  new Set(
@@ -94,29 +88,9 @@ const SallaProductCarousel: FC<Props> = ({
94
88
  }
95
89
  };
96
90
 
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
91
 
117
92
  // Ensure the select has a stable value (fallback to first option)
118
93
 
119
- const isTryOnOpen = openTryOn === currentVariant.variant_id;
120
94
 
121
95
  const selectValue = (currentVariant.option ?? options[0] ?? '');
122
96
 
@@ -179,56 +153,27 @@ const SallaProductCarousel: FC<Props> = ({
179
153
  </select>
180
154
  </div>
181
155
  )}
182
-
183
- <div className="flex items-center justify-between w-full space-x-4">
156
+
157
+ <div className="flex items-center justify-between w-full space-x-4">
184
158
 
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}
159
+ {enableTry?
160
+ <Button
161
+ style={{ backgroundColor: colorCode, color: "white" }}
162
+ className="px-6 py-2 rounded-lg shadow-md transition"
163
+ onClick={() => {
164
+ onTryOnSelect(currentVariant);
165
+ }}
192
166
  >
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
216
- style={{ backgroundColor: colorCode, color: "white" }}
217
- className="px-6 py-2 rounded-lg shadow-md transition"
218
- onClick={() =>
219
- setOpenTryOn(isTryOnOpen ? null : currentVariant.variant_id)
220
- }
221
- >
222
- {isTryOnOpen ? "Close Try On" : "Try On"}
223
- </Button>
167
+ Try On
168
+ </Button>
169
+ :<></>
170
+ }
171
+
172
+
224
173
 
225
174
  </div>
226
175
 
227
- { isTryOnOpen && (
228
- <div className="mt-4">
229
- <TryOnBox productID={currentVariant.variant_id} productImage={currentVariant.image} />
230
- </div>
231
- )}
176
+
232
177
 
233
178
  </div>
234
179
  </article>
@@ -1,10 +1,10 @@
1
- import React,{useState} from 'react';
1
+ import React from 'react';
2
2
  import type { FC } from 'react';
3
3
  import 'keen-slider/keen-slider.min.css';
4
4
  import type { KeenSliderInstance } from 'keen-slider/react';
5
5
  import { Button } from 'antd';
6
6
  import './SallaSwiper.css';
7
- import TryOnBox from "./TryOn";
7
+
8
8
 
9
9
  interface ProductVariant {
10
10
  variant_id: string;
@@ -31,6 +31,8 @@ interface Props {
31
31
  sliderInstance: React.MutableRefObject<KeenSliderInstance | null>;
32
32
  currentSlide: number;
33
33
  totalSlides: number;
34
+ onTryOnSelect: (product: ProductVariant) => void;
35
+ enableTry:boolean;
34
36
  }
35
37
 
36
38
 
@@ -39,19 +41,14 @@ const ZidProductCarousel: FC<Props> = ({
39
41
  groupedProducts,
40
42
  selectedVariants,
41
43
  setSelectedVariants,
42
- // counts,
43
- // setCounts,
44
- // handleAddToCart,
45
- // handleRemoveFromCart,
46
44
  colorCode = '#7F28F8',
47
45
  shortenName,
48
46
  sliderRef,
49
- // sliderInstance, // currently unused
50
- // currentSlide, // currently unused
51
47
  totalSlides,
48
+ onTryOnSelect,
49
+ enableTry
52
50
  }) => {
53
51
 
54
- const [openTryOn, setOpenTryOn] = useState<string | null>(null);
55
52
 
56
53
  if (!totalSlides || totalSlides === 0) return null;
57
54
 
@@ -118,7 +115,6 @@ const ZidProductCarousel: FC<Props> = ({
118
115
  // await handleRemoveFromCart(currentVariant.variant_id, 1);
119
116
  // };
120
117
 
121
- const isTryOnOpen = openTryOn === currentVariant.variant_id;
122
118
 
123
119
  // Ensure the select has a stable value (fallback to first option)
124
120
  const selectValue = (currentVariant.option ?? options[0] ?? '');
@@ -185,44 +181,20 @@ const ZidProductCarousel: FC<Props> = ({
185
181
 
186
182
 
187
183
 
188
- <Button
189
- style={{ backgroundColor: colorCode, color: "white" }}
190
- className="px-6 py-2 rounded-lg shadow-md transition"
191
- onClick={() =>
192
- setOpenTryOn(isTryOnOpen ? null : currentVariant.variant_id)
193
- }
194
- >
195
- {isTryOnOpen ? "Close Try On" : "Try On"}
196
- </Button>
197
-
198
-
199
- {/* <div className="sallaX-cta" aria-label="Quantity controls">
200
- <button
201
- type="button"
202
- className="sallaX-qty sallaX-qty--minus"
203
- onClick={decrement}
204
- aria-label="Decrease quantity"
205
- disabled={count === 0}
206
- >
207
-
208
- </button>
209
- <output className="sallaX-qtyCount" aria-live="polite" aria-atomic="true">
210
- {count}
211
- </output>
212
- <button
213
- type="button"
214
- className="sallaX-qty sallaX-qty--plus"
215
- onClick={increment}
216
- aria-label="Increase quantity"
217
- >
218
- +
219
- </button>
220
- </div> */}
221
- { isTryOnOpen && (
222
- <div className="mt-4">
223
- <TryOnBox productID={currentVariant.variant_id} productImage={currentVariant.image} />
224
- </div>
225
- )}
184
+ {enableTry?
185
+ <Button
186
+ style={{ backgroundColor: colorCode, color: "white" }}
187
+ className="px-6 py-2 rounded-lg shadow-md transition"
188
+ onClick={() => {
189
+ onTryOnSelect(currentVariant);
190
+ }}
191
+ >
192
+ Try On
193
+ </Button>
194
+ :<></>
195
+ }
196
+
197
+
226
198
 
227
199
  </div>
228
200
  </article>
@@ -270,6 +270,8 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
270
270
  colorCode={colorCode}
271
271
  handleAddToCart={handleAddToCart}
272
272
  handleRemoveFromCart={handleRemoveFromCart}
273
+ onTryOnSelect={onTryOnSelect}
274
+ enableTry={enableTry}
273
275
  // enableTry={enableTry}
274
276
 
275
277
  />
@@ -279,6 +281,8 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
279
281
  colorCode={colorCode}
280
282
  handleAddToCart={handleAddToCart}
281
283
  handleRemoveFromCart={handleRemoveFromCart}
284
+ onTryOnSelect={onTryOnSelect}
285
+ enableTry={enableTry}
282
286
  // enableTry={enableTry}
283
287
 
284
288
  />
@@ -22,7 +22,8 @@ interface AssistantMessageProps {
22
22
  isBusiness?: boolean;
23
23
  handleAddToCart: (variantId: string, name: string,variantImage:string,price:string, qty?: number) => Promise<void>;
24
24
  handleRemoveFromCart: (variantId: string, qty?: number) => Promise<void>;
25
-
25
+ onTryOnSelect: (product: any) => void; // Add this
26
+ enableTry:boolean;
26
27
  }
27
28
 
28
29
  const SallaAsssiatnt: FC<AssistantMessageProps> = ({
@@ -30,6 +31,8 @@ const SallaAsssiatnt: FC<AssistantMessageProps> = ({
30
31
  colorCode,
31
32
  handleAddToCart,
32
33
  handleRemoveFromCart,
34
+ onTryOnSelect,
35
+ enableTry
33
36
  }) => {
34
37
  const [counts, setCounts] = useState<Record<string, number>>({});
35
38
  const [selectedVariants, setSelectedVariants] = useState<Record<string, string>>({});
@@ -185,6 +188,8 @@ const SallaAsssiatnt: FC<AssistantMessageProps> = ({
185
188
  currentSlide={currentSlide}
186
189
  totalSlides={totalSlides}
187
190
  sliderRef={sliderRef}
191
+ onTryOnSelect={onTryOnSelect}
192
+ enableTry={enableTry}
188
193
 
189
194
  />
190
195
  </div>
@@ -22,7 +22,8 @@ interface AssistantMessageProps {
22
22
  isBusiness?: boolean;
23
23
  handleAddToCart: (variantId: string, name: string,variantImage:string,price:string, qty?: number) => Promise<void>;
24
24
  handleRemoveFromCart: (variantId: string, qty?: number) => Promise<void>;
25
-
25
+ onTryOnSelect: (product: any) => void; // Add this
26
+ enableTry:boolean;
26
27
  }
27
28
 
28
29
  const SallaAsssiatnt: FC<AssistantMessageProps> = ({
@@ -30,6 +31,8 @@ const SallaAsssiatnt: FC<AssistantMessageProps> = ({
30
31
  colorCode,
31
32
  handleAddToCart,
32
33
  handleRemoveFromCart,
34
+ onTryOnSelect,
35
+ enableTry
33
36
 
34
37
  }) => {
35
38
  const [counts, setCounts] = useState<Record<string, number>>({});
@@ -186,6 +189,8 @@ const SallaAsssiatnt: FC<AssistantMessageProps> = ({
186
189
  currentSlide={currentSlide}
187
190
  totalSlides={totalSlides}
188
191
  sliderRef={sliderRef}
192
+ onTryOnSelect={onTryOnSelect}
193
+ enableTry={enableTry}
189
194
 
190
195
  />
191
196
  </div>
@@ -31,6 +31,8 @@ interface TryOnProps {
31
31
  counts: Record<string, number>;
32
32
  setCounts: React.Dispatch<React.SetStateAction<Record<string, number>>>;
33
33
  visitorId?: string;
34
+ addToCart?:boolean
35
+ userType: string;
34
36
  }
35
37
 
36
38
  interface UploadResponse {
@@ -55,6 +57,9 @@ const TryOnLayout: React.FC<TryOnProps> = ({
55
57
  handleRemoveFromCart,
56
58
  counts,
57
59
  setCounts,
60
+ addToCart,
61
+ userType
62
+
58
63
  }) => {
59
64
  const [isGenerating, setIsGenerating] = useState(false);
60
65
  const [generatedImage, setGeneratedImage] = useState<string | null>(null);
@@ -297,7 +302,9 @@ const TryOnLayout: React.FC<TryOnProps> = ({
297
302
  </>
298
303
  );
299
304
 
300
- const showCartControls = currentState === 'generated' && !isGenerating;
305
+ const hideCart = ['zid', 'email', 'salla'].includes(userType);
306
+ const showCartControls = !addToCart && !hideCart && currentState === 'generated' && !isGenerating;
307
+
301
308
 
302
309
  return (
303
310
  <div style={{
@@ -353,7 +360,7 @@ const TryOnLayout: React.FC<TryOnProps> = ({
353
360
  </div>
354
361
 
355
362
  {/* +/- stepper (only after try-on generated) */}
356
- {showCartControls ? (
363
+ {showCartControls ? (
357
364
  <div style={{
358
365
  display: 'flex', alignItems: 'center', background: '#f5f5f7',
359
366
  borderRadius: 12, padding: 4, flexShrink: 0, animation: 'slideUp 0.3s ease',
@@ -387,11 +394,11 @@ const TryOnLayout: React.FC<TryOnProps> = ({
387
394
  aria-label="Increase quantity"
388
395
  >+</button>
389
396
  </div>
390
- ) : (
397
+ ) : (!addToCart && !hideCart) ? (
391
398
  <div style={{ fontSize: 11, color: '#bbb', textAlign: 'right', lineHeight: 1.3, flexShrink: 0 }}>
392
399
  Try it on first,<br/>then add to cart
393
400
  </div>
394
- )}
401
+ ) : null}
395
402
  </div>
396
403
  </div>
397
404