react-native-srschat 0.1.52 → 0.1.54
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/lib/commonjs/components/email.js +43 -8
- package/lib/commonjs/components/email.js.map +1 -1
- package/lib/commonjs/components/header.js +1 -1
- package/lib/commonjs/components/header.js.map +1 -1
- package/lib/commonjs/components/productCard.js +59 -53
- package/lib/commonjs/components/productCard.js.map +1 -1
- package/lib/commonjs/contexts/AppContext.js +8 -4
- package/lib/commonjs/contexts/AppContext.js.map +1 -1
- package/lib/commonjs/layout/welcome.js +1 -1
- package/lib/commonjs/layout/welcome.js.map +1 -1
- package/lib/module/components/email.js +43 -8
- package/lib/module/components/email.js.map +1 -1
- package/lib/module/components/header.js +1 -1
- package/lib/module/components/header.js.map +1 -1
- package/lib/module/components/productCard.js +59 -53
- package/lib/module/components/productCard.js.map +1 -1
- package/lib/module/contexts/AppContext.js +8 -4
- package/lib/module/contexts/AppContext.js.map +1 -1
- package/lib/module/layout/welcome.js +1 -1
- package/lib/module/layout/welcome.js.map +1 -1
- package/lib/typescript/components/email.d.ts.map +1 -1
- package/lib/typescript/components/productCard.d.ts.map +1 -1
- package/lib/typescript/contexts/AppContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/email.js +44 -8
- package/src/components/header.js +1 -1
- package/src/components/productCard.js +69 -59
- package/src/contexts/AppContext.js +8 -4
- package/src/layout/welcome.js +1 -1
package/src/components/email.js
CHANGED
|
@@ -32,6 +32,18 @@ export const EmailForm = ({ panHandlers }) => {
|
|
|
32
32
|
const messageInputRef = useRef(null);
|
|
33
33
|
const emailInputRef = useRef(null);
|
|
34
34
|
|
|
35
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
36
|
+
|
|
37
|
+
const validateEmail = (email) => {
|
|
38
|
+
if (!email) {
|
|
39
|
+
return "Email address is required";
|
|
40
|
+
}
|
|
41
|
+
if (!emailRegex.test(email)) {
|
|
42
|
+
return "Please enter a valid email address";
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
};
|
|
46
|
+
|
|
35
47
|
const handleComposeEmail = async () => {
|
|
36
48
|
setIsComposing(true);
|
|
37
49
|
setError("");
|
|
@@ -59,13 +71,13 @@ export const EmailForm = ({ panHandlers }) => {
|
|
|
59
71
|
};
|
|
60
72
|
|
|
61
73
|
const handleSubmit = async () => {
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
const emailError = validateEmail(userEmail);
|
|
75
|
+
if (emailError) {
|
|
76
|
+
setError(emailError);
|
|
64
77
|
return;
|
|
65
78
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setError("Please enter a valid email address");
|
|
79
|
+
if (!subject || !message) {
|
|
80
|
+
setError("Please fill in all fields");
|
|
69
81
|
return;
|
|
70
82
|
}
|
|
71
83
|
|
|
@@ -138,19 +150,36 @@ export const EmailForm = ({ panHandlers }) => {
|
|
|
138
150
|
ref={emailInputRef}
|
|
139
151
|
style={styles.input}
|
|
140
152
|
value={userEmail}
|
|
141
|
-
onChangeText={
|
|
153
|
+
onChangeText={(text) => {
|
|
154
|
+
setUserEmail(text);
|
|
155
|
+
const emailValidationError = validateEmail(text);
|
|
156
|
+
if (emailValidationError) {
|
|
157
|
+
setError(emailValidationError);
|
|
158
|
+
} else if (error === "Please enter a valid email address" || error === "Email address is required") {
|
|
159
|
+
setError("");
|
|
160
|
+
}
|
|
161
|
+
}}
|
|
142
162
|
placeholder="Your Email"
|
|
143
163
|
onFocus={() =>
|
|
144
164
|
scrollViewRef.current?.scrollToFocusedInput(
|
|
145
165
|
findNodeHandle(emailInputRef.current)
|
|
146
166
|
)
|
|
147
167
|
}
|
|
168
|
+
keyboardType="email-address"
|
|
169
|
+
autoCapitalize="none"
|
|
148
170
|
/>
|
|
149
171
|
<TextInput
|
|
150
172
|
ref={subjectInputRef}
|
|
151
173
|
style={styles.input}
|
|
152
174
|
value={subject}
|
|
153
|
-
onChangeText={
|
|
175
|
+
onChangeText={(text) => {
|
|
176
|
+
setSubject(text);
|
|
177
|
+
if (error && !validateEmail(userEmail) && !message) {
|
|
178
|
+
setError("");
|
|
179
|
+
} else if (error === "Please fill in all fields" && text && message) {
|
|
180
|
+
setError("");
|
|
181
|
+
}
|
|
182
|
+
}}
|
|
154
183
|
placeholder="Subject"
|
|
155
184
|
onFocus={() =>
|
|
156
185
|
scrollViewRef.current?.scrollToFocusedInput(
|
|
@@ -162,7 +191,14 @@ export const EmailForm = ({ panHandlers }) => {
|
|
|
162
191
|
ref={messageInputRef}
|
|
163
192
|
style={styles.textArea}
|
|
164
193
|
value={message}
|
|
165
|
-
onChangeText={
|
|
194
|
+
onChangeText={(text) => {
|
|
195
|
+
setMessage(text);
|
|
196
|
+
if (error && !validateEmail(userEmail) && !subject) {
|
|
197
|
+
setError("");
|
|
198
|
+
} else if (error === "Please fill in all fields" && text && subject) {
|
|
199
|
+
setError("");
|
|
200
|
+
}
|
|
201
|
+
}}
|
|
166
202
|
placeholder="Message"
|
|
167
203
|
multiline
|
|
168
204
|
onFocus={() =>
|
package/src/components/header.js
CHANGED
|
@@ -49,13 +49,7 @@ export const ProductCard = ({ prod, onFocusQuantityInput, messageId }) => {
|
|
|
49
49
|
|
|
50
50
|
const currentMinPackQtyForSelectedUom = getMinPackQtyForUom(selectedUom);
|
|
51
51
|
|
|
52
|
-
const [quantity, setQuantity] = useState(
|
|
53
|
-
if (valid) {
|
|
54
|
-
// Initial quantity is min pack, not limited by maxQuantity
|
|
55
|
-
return currentMinPackQtyForSelectedUom;
|
|
56
|
-
}
|
|
57
|
-
return 0;
|
|
58
|
-
});
|
|
52
|
+
const [quantity, setQuantity] = useState(0);
|
|
59
53
|
|
|
60
54
|
// Add keyboard listeners to detect when keyboard appears/disappears
|
|
61
55
|
useEffect(() => {
|
|
@@ -170,52 +164,76 @@ export const ProductCard = ({ prod, onFocusQuantityInput, messageId }) => {
|
|
|
170
164
|
});
|
|
171
165
|
};
|
|
172
166
|
|
|
173
|
-
const validateMinPackQty = () => {
|
|
174
|
-
if (quantity % currentMinPackQtyForSelectedUom !== 0) {
|
|
175
|
-
Alert.alert(
|
|
176
|
-
"Invalid Quantity",
|
|
177
|
-
`Please enter a quantity that is a multiple of the min pack qty (${currentMinPackQtyForSelectedUom}).`
|
|
178
|
-
);
|
|
179
|
-
setQuantity(currentMinPackQtyForSelectedUom);
|
|
180
|
-
return false; // Indicates validation failed
|
|
181
|
-
}
|
|
182
|
-
return true; // Indicates validation passed
|
|
183
|
-
}
|
|
184
|
-
|
|
185
167
|
const handleAddToCart = () => {
|
|
186
|
-
if (!
|
|
187
|
-
|
|
168
|
+
if (!valid || quantity <= 0) {
|
|
169
|
+
if (quantity <= 0 && valid) {
|
|
170
|
+
// Optionally, alert the user that quantity must be greater than 0
|
|
171
|
+
// Alert.alert("Invalid Quantity", "Please enter a quantity greater than 0.");
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
188
174
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
175
|
+
|
|
176
|
+
const executeAddToCartLogic = (qtyToAdd) => {
|
|
177
|
+
try {
|
|
178
|
+
const discount = discountsString ? discountsString : (Array.isArray(discountsArray) ? discountsArray.join(", ") : "");
|
|
179
|
+
const payload = {
|
|
180
|
+
product_name: prod.product_details.product_name,
|
|
181
|
+
time_stamp: new Date().toISOString(),
|
|
182
|
+
user_id: data.user_id,
|
|
183
|
+
session_id: sessionId,
|
|
184
|
+
quantity: qtyToAdd,
|
|
185
|
+
uom: selectedUom,
|
|
186
|
+
is_sale: isOnSale,
|
|
187
|
+
discount_string: discount,
|
|
188
|
+
message_id: messageId
|
|
189
|
+
};
|
|
190
|
+
console.log("add to cart payload", payload);
|
|
191
|
+
axios.post(ADD_TO_CART_URL, payload)
|
|
192
|
+
.then(response => {
|
|
193
|
+
console.log("log addToCart response", response);
|
|
194
|
+
})
|
|
195
|
+
.catch(error => {
|
|
196
|
+
console.log("log addToCart error", error);
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.log("log addToCart error", error);
|
|
202
200
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
onAddToCartClick({
|
|
202
|
+
selectedUom: selectedUom,
|
|
203
|
+
quantity: qtyToAdd,
|
|
204
|
+
product: prod
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (currentMinPackQtyForSelectedUom > 1 && quantity % currentMinPackQtyForSelectedUom !== 0) {
|
|
209
|
+
const roundedResult = Math.ceil(quantity / currentMinPackQtyForSelectedUom) * currentMinPackQtyForSelectedUom;
|
|
210
|
+
|
|
211
|
+
Alert.alert(
|
|
212
|
+
`Item #${prod.part_number} is sold in multiples of ${currentMinPackQtyForSelectedUom} ${selectedUom}`,
|
|
213
|
+
`The quantity will be rounded up to ${roundedResult} ${selectedUom} in your cart. Do you want to proceed?`,
|
|
214
|
+
[
|
|
215
|
+
{
|
|
216
|
+
text: 'Cancel',
|
|
217
|
+
onPress: () => {
|
|
218
|
+
setQuantity(0); // Reset quantity to 0
|
|
219
|
+
},
|
|
220
|
+
style: 'cancel',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
text: 'Proceed',
|
|
224
|
+
onPress: () => {
|
|
225
|
+
setQuantity(roundedResult); // Set quantity to the adjusted amount
|
|
226
|
+
executeAddToCartLogic(roundedResult); // Proceed with adding to cart
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
{ cancelable: true } // User can dismiss the alert by tapping outside on Android
|
|
231
|
+
);
|
|
232
|
+
} else {
|
|
233
|
+
// No rounding needed, or item is sold individually (min pack <= 1)
|
|
234
|
+
// Proceed with the current quantity (which is > 0 at this point)
|
|
235
|
+
executeAddToCartLogic(quantity);
|
|
213
236
|
}
|
|
214
|
-
onAddToCartClick({
|
|
215
|
-
selectedUom: selectedUom,
|
|
216
|
-
quantity: quantity,
|
|
217
|
-
product: prod
|
|
218
|
-
});
|
|
219
237
|
};
|
|
220
238
|
|
|
221
239
|
const handleProductClick = () => {
|
|
@@ -228,18 +246,10 @@ export const ProductCard = ({ prod, onFocusQuantityInput, messageId }) => {
|
|
|
228
246
|
};
|
|
229
247
|
|
|
230
248
|
const handleUomChange = (newUom) => {
|
|
231
|
-
const newMinPack = getMinPackQtyForUom(newUom);
|
|
232
|
-
const isProductCurrentlyValid = prod.inventory_info?.is_valid || false;
|
|
233
|
-
|
|
234
249
|
setSelectedUom(newUom);
|
|
235
250
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
qtyToSet = newMinPack;
|
|
239
|
-
} else {
|
|
240
|
-
qtyToSet = 0;
|
|
241
|
-
}
|
|
242
|
-
setQuantity(qtyToSet);
|
|
251
|
+
// Always set quantity to 0 when UOM changes
|
|
252
|
+
setQuantity(0);
|
|
243
253
|
};
|
|
244
254
|
|
|
245
255
|
const openUomPicker = () => {
|
|
@@ -78,11 +78,15 @@ export const AppProvider = ({ data, onProductCardClick, onAddToCartClick, uiConf
|
|
|
78
78
|
if (uiConfig.toggleChat === false){
|
|
79
79
|
setShowModal("Icon");
|
|
80
80
|
}else{
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
setShowModal("Welcome");
|
|
81
|
+
if (!disclaimer){
|
|
82
|
+
setShowModal("Form")
|
|
84
83
|
}else{
|
|
85
|
-
|
|
84
|
+
if ((uiConfig.showWelcome === true || cachedState.showWelcome === true) && (messages.length <2)){
|
|
85
|
+
// console.log("showWelcome", uiConfig.showWelcome, cachedState.showWelcome)
|
|
86
|
+
setShowModal("Welcome");
|
|
87
|
+
}else{
|
|
88
|
+
setShowModal("ChatWindow");
|
|
89
|
+
}
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
|
package/src/layout/welcome.js
CHANGED
|
@@ -31,7 +31,7 @@ export const Welcome = ({ panHandlers }) => {
|
|
|
31
31
|
{/* Logo container with absolute positioning */}
|
|
32
32
|
<View style={styles.logoContainer}>
|
|
33
33
|
<CloudinaryImage
|
|
34
|
-
cldImg="
|
|
34
|
+
cldImg="logos/HPSG_HPlus_Logo_White"
|
|
35
35
|
imageStyle={{ width: 150, height: 35 }}
|
|
36
36
|
/>
|
|
37
37
|
</View>
|