shopify-chatbot-widget 0.9.2 → 0.9.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.
package/package.json
CHANGED
package/src/Chatbot/Chatbot.tsx
CHANGED
|
@@ -39,6 +39,8 @@ const Chatbot: React.FC = () => {
|
|
|
39
39
|
const antIcon = <LoadingOutlined style={{ fontSize: 24, color: colorCode||'#7F28F8' }} spin />;
|
|
40
40
|
|
|
41
41
|
const handleNewSessionClick = () => {
|
|
42
|
+
console.log(disableForm)
|
|
43
|
+
console.log(HasInfo)
|
|
42
44
|
if (!disableForm && !HasInfo) {
|
|
43
45
|
setViewMode('create');
|
|
44
46
|
return;
|
|
@@ -100,16 +102,31 @@ const Chatbot: React.FC = () => {
|
|
|
100
102
|
const onMessage = (e: MessageEvent) => {
|
|
101
103
|
const msg = (e.data || {}) as any;
|
|
102
104
|
if (msg.type !== 'JAWEB_CHAT') return;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
|
|
106
|
+
switch (msg.action) {
|
|
107
|
+
case 'open-ready':
|
|
108
|
+
setOpen(true);
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'closed':
|
|
112
|
+
setOpen(false);
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 'start-session':
|
|
116
|
+
console.log('[Chatbot] start-session message received');
|
|
117
|
+
handleNewSessionClick(); // 👈 Trigger new session automatically
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
break;
|
|
108
122
|
}
|
|
109
123
|
};
|
|
124
|
+
|
|
110
125
|
window.addEventListener('message', onMessage);
|
|
111
126
|
return () => window.removeEventListener('message', onMessage);
|
|
112
127
|
}, []);
|
|
128
|
+
|
|
129
|
+
|
|
113
130
|
|
|
114
131
|
const requestOpen = () => {
|
|
115
132
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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">
|