powr-sdk-web 4.2.6 → 4.2.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/dist/auth/index.js +61 -34
- package/dist/comments/index.js +3 -3
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -32,7 +32,9 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
32
32
|
appLogo = _ref.appLogo,
|
|
33
33
|
_ref$mode = _ref.mode,
|
|
34
34
|
mode = _ref$mode === void 0 ? 'toggle' : _ref$mode,
|
|
35
|
-
projectId = _ref.projectId
|
|
35
|
+
projectId = _ref.projectId,
|
|
36
|
+
_ref$fieldType = _ref.fieldType,
|
|
37
|
+
fieldType = _ref$fieldType === void 0 ? 'both' : _ref$fieldType;
|
|
36
38
|
var _useState = (0, _react.useState)(function () {
|
|
37
39
|
switch (mode) {
|
|
38
40
|
case 'login':
|
|
@@ -48,7 +50,8 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
48
50
|
isLogin = _useState2[0],
|
|
49
51
|
setIsLogin = _useState2[1];
|
|
50
52
|
var _useState3 = (0, _react.useState)({
|
|
51
|
-
|
|
53
|
+
phone: '',
|
|
54
|
+
email: '',
|
|
52
55
|
password: '',
|
|
53
56
|
confirmPassword: '',
|
|
54
57
|
fullName: ''
|
|
@@ -233,14 +236,12 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
233
236
|
return emailRegex.test(email);
|
|
234
237
|
};
|
|
235
238
|
var isValidPhone = function isValidPhone(phone) {
|
|
236
|
-
// Remove all non-digit characters
|
|
237
239
|
var cleanPhone = phone.replace(/\D/g, '');
|
|
238
|
-
// Check if it's a valid phone number (7-15 digits)
|
|
239
240
|
return cleanPhone.length >= 7 && cleanPhone.length <= 15;
|
|
240
241
|
};
|
|
241
242
|
var handleSubmit = /*#__PURE__*/function () {
|
|
242
243
|
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e) {
|
|
243
|
-
var errors,
|
|
244
|
+
var errors, endpoint, phoneOrEmail, payload, _yield$apiCall, data, ok, _t3;
|
|
244
245
|
return _regenerator().w(function (_context4) {
|
|
245
246
|
while (1) switch (_context4.p = _context4.n) {
|
|
246
247
|
case 0:
|
|
@@ -249,16 +250,20 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
249
250
|
setError('');
|
|
250
251
|
setSuccess('');
|
|
251
252
|
setFieldErrors({});
|
|
252
|
-
errors = {};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
errors = {}; // Validation for phone/email fields
|
|
254
|
+
if (fieldType === 'phone' || fieldType === 'both') {
|
|
255
|
+
if (!formData.phone.trim()) {
|
|
256
|
+
errors.phone = 'Phone is required';
|
|
257
|
+
} else if (!isValidPhone(formData.phone)) {
|
|
258
|
+
errors.phone = 'Please enter a valid phone number';
|
|
259
|
+
}
|
|
257
260
|
}
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
if (fieldType === 'email' || fieldType === 'both') {
|
|
262
|
+
if (!formData.email.trim()) {
|
|
263
|
+
errors.email = 'Email is required';
|
|
264
|
+
} else if (!isValidEmail(formData.email)) {
|
|
265
|
+
errors.email = 'Please enter a valid email address';
|
|
266
|
+
}
|
|
262
267
|
}
|
|
263
268
|
if (!formData.password.trim()) {
|
|
264
269
|
errors.password = 'Password is required';
|
|
@@ -268,10 +273,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
268
273
|
if (!isLogin && !formData.fullName.trim()) {
|
|
269
274
|
errors.fullName = 'Full name is required';
|
|
270
275
|
}
|
|
271
|
-
if (!isLogin &&
|
|
272
|
-
errors.confirmPassword = 'Passwords do not match';
|
|
273
|
-
}
|
|
274
|
-
if (!isLogin && !otpVerified) {
|
|
276
|
+
if (!isLogin && fieldType === 'phone' && !otpVerified) {
|
|
275
277
|
errors.otp = 'Please verify OTP before signing up';
|
|
276
278
|
}
|
|
277
279
|
if (!(Object.keys(errors).length > 0)) {
|
|
@@ -284,12 +286,20 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
284
286
|
case 1:
|
|
285
287
|
_context4.p = 1;
|
|
286
288
|
endpoint = isLogin ? "/auth/login" : "/auth/register";
|
|
289
|
+
phoneOrEmail = '';
|
|
290
|
+
if (fieldType === 'phone') {
|
|
291
|
+
phoneOrEmail = formData.phone;
|
|
292
|
+
} else if (fieldType === 'email') {
|
|
293
|
+
phoneOrEmail = formData.email;
|
|
294
|
+
} else if (fieldType === 'both') {
|
|
295
|
+
phoneOrEmail = formData.phone || formData.email;
|
|
296
|
+
}
|
|
287
297
|
payload = isLogin ? {
|
|
288
|
-
phoneOrEmail:
|
|
298
|
+
phoneOrEmail: phoneOrEmail,
|
|
289
299
|
password: formData.password
|
|
290
300
|
} : {
|
|
291
301
|
fullName: formData.fullName,
|
|
292
|
-
phoneOrEmail:
|
|
302
|
+
phoneOrEmail: phoneOrEmail,
|
|
293
303
|
password: formData.password
|
|
294
304
|
};
|
|
295
305
|
_context4.n = 2;
|
|
@@ -309,7 +319,8 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
309
319
|
onRegister(data);
|
|
310
320
|
}
|
|
311
321
|
setFormData({
|
|
312
|
-
|
|
322
|
+
phone: '',
|
|
323
|
+
email: '',
|
|
313
324
|
password: '',
|
|
314
325
|
confirmPassword: '',
|
|
315
326
|
fullName: ''
|
|
@@ -465,26 +476,26 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
465
476
|
required: true
|
|
466
477
|
}), fieldErrors.fullName && /*#__PURE__*/_react["default"].createElement("div", {
|
|
467
478
|
style: styles.fieldError
|
|
468
|
-
}, fieldErrors.fullName)), /*#__PURE__*/_react["default"].createElement("div", {
|
|
479
|
+
}, fieldErrors.fullName)), (fieldType === 'phone' || fieldType === 'both') && /*#__PURE__*/_react["default"].createElement("div", {
|
|
469
480
|
style: styles.formGroup
|
|
470
481
|
}, /*#__PURE__*/_react["default"].createElement("label", {
|
|
471
|
-
htmlFor: "
|
|
482
|
+
htmlFor: "phone",
|
|
472
483
|
style: styles.label
|
|
473
|
-
}, "Phone
|
|
484
|
+
}, "Phone"), /*#__PURE__*/_react["default"].createElement("input", {
|
|
474
485
|
type: "text",
|
|
475
|
-
id: "
|
|
476
|
-
name: "
|
|
477
|
-
value: formData.
|
|
486
|
+
id: "phone",
|
|
487
|
+
name: "phone",
|
|
488
|
+
value: formData.phone,
|
|
478
489
|
onChange: handleInputChange,
|
|
479
|
-
style: _objectSpread(_objectSpread({}, styles.input), fieldErrors.
|
|
480
|
-
placeholder: "Enter your phone
|
|
481
|
-
required:
|
|
482
|
-
}), fieldErrors.
|
|
490
|
+
style: _objectSpread(_objectSpread({}, styles.input), fieldErrors.phone ? styles.inputError : {}),
|
|
491
|
+
placeholder: "Enter your phone number",
|
|
492
|
+
required: fieldType === 'phone' || fieldType === 'both'
|
|
493
|
+
}), fieldErrors.phone && /*#__PURE__*/_react["default"].createElement("div", {
|
|
483
494
|
style: styles.fieldError
|
|
484
|
-
}, fieldErrors.
|
|
495
|
+
}, fieldErrors.phone), !isLogin && isValidPhone(formData.phone) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !firebaseOtpSent ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("button", {
|
|
485
496
|
type: "button",
|
|
486
497
|
onClick: function onClick() {
|
|
487
|
-
return sendFirebaseOtp(formatPhone(formData.
|
|
498
|
+
return sendFirebaseOtp(formatPhone(formData.phone));
|
|
488
499
|
},
|
|
489
500
|
style: styles.otpButton,
|
|
490
501
|
disabled: otpLoading
|
|
@@ -514,7 +525,23 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
514
525
|
color: '#16a34a',
|
|
515
526
|
marginBottom: 8
|
|
516
527
|
}
|
|
517
|
-
}, "OTP verified! Now set your password and sign up."))), /*#__PURE__*/_react["default"].createElement("div", {
|
|
528
|
+
}, "OTP verified! Now set your password and sign up."))), (fieldType === 'email' || fieldType === 'both') && /*#__PURE__*/_react["default"].createElement("div", {
|
|
529
|
+
style: styles.formGroup
|
|
530
|
+
}, /*#__PURE__*/_react["default"].createElement("label", {
|
|
531
|
+
htmlFor: "email",
|
|
532
|
+
style: styles.label
|
|
533
|
+
}, "Email"), /*#__PURE__*/_react["default"].createElement("input", {
|
|
534
|
+
type: "email",
|
|
535
|
+
id: "email",
|
|
536
|
+
name: "email",
|
|
537
|
+
value: formData.email,
|
|
538
|
+
onChange: handleInputChange,
|
|
539
|
+
style: _objectSpread(_objectSpread({}, styles.input), fieldErrors.email ? styles.inputError : {}),
|
|
540
|
+
placeholder: "Enter your email",
|
|
541
|
+
required: fieldType === 'email' || fieldType === 'both'
|
|
542
|
+
}), fieldErrors.email && /*#__PURE__*/_react["default"].createElement("div", {
|
|
543
|
+
style: styles.fieldError
|
|
544
|
+
}, fieldErrors.email)), /*#__PURE__*/_react["default"].createElement("div", {
|
|
518
545
|
style: styles.formGroup
|
|
519
546
|
}, /*#__PURE__*/_react["default"].createElement("label", {
|
|
520
547
|
htmlFor: "password",
|
package/dist/comments/index.js
CHANGED
|
@@ -106,9 +106,9 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
|
|
|
106
106
|
_yield$apiCall = _context.v;
|
|
107
107
|
data = _yield$apiCall.data;
|
|
108
108
|
ok = _yield$apiCall.ok;
|
|
109
|
-
if (ok && data.success) {
|
|
110
|
-
if (Array.isArray(data.
|
|
111
|
-
sortedComments = data.
|
|
109
|
+
if (ok && data !== null && data !== void 0 && data.success) {
|
|
110
|
+
if (Array.isArray(data === null || data === void 0 ? void 0 : data.data)) {
|
|
111
|
+
sortedComments = data.data.sort(function (a, b) {
|
|
112
112
|
return new Date(a.createdAt) - new Date(b.createdAt);
|
|
113
113
|
});
|
|
114
114
|
setComments(sortedComments);
|