shopify-chatbot-widget 0.9.1 → 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
package/src/Chatbot/Chatbot.tsx
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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">
|