@open-tender/utils 0.5.58 → 0.5.59

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.
@@ -107,6 +107,32 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
107
107
  }
108
108
  }
109
109
  }, [loading, error]);
110
+ const validateRequiredFields = (values) => {
111
+ var _a, _b, _c, _d, _e, _f;
112
+ const validationErrors = {};
113
+ // Check non-optional fields from CustomerCreate
114
+ if (!((_a = values.first_name) === null || _a === void 0 ? void 0 : _a.trim())) {
115
+ validationErrors.first_name = 'First name is required';
116
+ }
117
+ if (!((_b = values.last_name) === null || _b === void 0 ? void 0 : _b.trim())) {
118
+ validationErrors.last_name = 'Last name is required';
119
+ }
120
+ if (!((_c = values.email) === null || _c === void 0 ? void 0 : _c.trim())) {
121
+ validationErrors.email = 'Email is required';
122
+ }
123
+ if (!((_d = values.phone) === null || _d === void 0 ? void 0 : _d.trim())) {
124
+ validationErrors.phone = 'Phone is required';
125
+ }
126
+ // Check password if not hidden
127
+ if (!((_e = values.password) === null || _e === void 0 ? void 0 : _e.trim())) {
128
+ validationErrors.password = 'Password is required';
129
+ }
130
+ // Check company if required
131
+ if (companyRequired && !((_f = values.company) === null || _f === void 0 ? void 0 : _f.trim())) {
132
+ validationErrors.company = 'Company is required';
133
+ }
134
+ return validationErrors;
135
+ };
110
136
  const handleChange = (name, value) => {
111
137
  const inputValue = name === 'phone'
112
138
  ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : ''))
@@ -128,10 +154,12 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
128
154
  if (values.birth_date) {
129
155
  values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
130
156
  }
157
+ const validationErrors = validateRequiredFields(values);
131
158
  if (require_home_store && !data.home_store) {
132
- setErrors({
133
- home_store: 'Please select a home store'
134
- });
159
+ validationErrors.home_store = 'Please select a home store';
160
+ }
161
+ if (Object.keys(validationErrors).length > 0) {
162
+ setErrors(validationErrors);
135
163
  return;
136
164
  }
137
165
  const loginToken = includeLoginRecaptcha
@@ -78,6 +78,28 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
78
78
  : value;
79
79
  setData(Object.assign(Object.assign({}, data), { [name]: val }));
80
80
  };
81
+ const validateRequiredFields = (values) => {
82
+ var _a, _b, _c, _d, _e;
83
+ const validationErrors = {};
84
+ // Check non-optional fields from CustomerCreate
85
+ if (!((_a = values.first_name) === null || _a === void 0 ? void 0 : _a.trim())) {
86
+ validationErrors.first_name = 'First name is required';
87
+ }
88
+ if (!((_b = values.last_name) === null || _b === void 0 ? void 0 : _b.trim())) {
89
+ validationErrors.last_name = 'Last name is required';
90
+ }
91
+ if (!((_c = values.email) === null || _c === void 0 ? void 0 : _c.trim())) {
92
+ validationErrors.email = 'Email is required';
93
+ }
94
+ if (!((_d = values.phone) === null || _d === void 0 ? void 0 : _d.trim())) {
95
+ validationErrors.phone = 'Phone is required';
96
+ }
97
+ // Check password if not Thanx (password is removed for Thanx)
98
+ if (!((_e = values.password) === null || _e === void 0 ? void 0 : _e.trim())) {
99
+ validationErrors.password = 'Password is required';
100
+ }
101
+ return validationErrors;
102
+ };
81
103
  const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
82
104
  var _a, _b, _c;
83
105
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -87,10 +109,14 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
87
109
  if (values.birth_date) {
88
110
  values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
89
111
  }
112
+ // Validate required fields
113
+ const validationErrors = validateRequiredFields(values);
90
114
  if (require_home_store && !data.home_store) {
91
- setErrors({
92
- home_store: 'Please select a home store'
93
- });
115
+ validationErrors.home_store = 'Please select a home store';
116
+ }
117
+ // If there are validation errors, set them and return early
118
+ if (Object.keys(validationErrors).length > 0) {
119
+ setErrors(validationErrors);
94
120
  return;
95
121
  }
96
122
  const loginToken = includeLoginRecaptcha
@@ -104,6 +104,32 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
104
104
  }
105
105
  }
106
106
  }, [loading, error]);
107
+ const validateRequiredFields = (values) => {
108
+ var _a, _b, _c, _d, _e, _f;
109
+ const validationErrors = {};
110
+ // Check non-optional fields from CustomerCreate
111
+ if (!((_a = values.first_name) === null || _a === void 0 ? void 0 : _a.trim())) {
112
+ validationErrors.first_name = 'First name is required';
113
+ }
114
+ if (!((_b = values.last_name) === null || _b === void 0 ? void 0 : _b.trim())) {
115
+ validationErrors.last_name = 'Last name is required';
116
+ }
117
+ if (!((_c = values.email) === null || _c === void 0 ? void 0 : _c.trim())) {
118
+ validationErrors.email = 'Email is required';
119
+ }
120
+ if (!((_d = values.phone) === null || _d === void 0 ? void 0 : _d.trim())) {
121
+ validationErrors.phone = 'Phone is required';
122
+ }
123
+ // Check password if not hidden
124
+ if (!((_e = values.password) === null || _e === void 0 ? void 0 : _e.trim())) {
125
+ validationErrors.password = 'Password is required';
126
+ }
127
+ // Check company if required
128
+ if (companyRequired && !((_f = values.company) === null || _f === void 0 ? void 0 : _f.trim())) {
129
+ validationErrors.company = 'Company is required';
130
+ }
131
+ return validationErrors;
132
+ };
107
133
  const handleChange = (name, value) => {
108
134
  const inputValue = name === 'phone'
109
135
  ? makePhone((value !== null && value !== void 0 ? value : ''))
@@ -125,10 +151,12 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
125
151
  if (values.birth_date) {
126
152
  values.birth_date = slashesToDashes(values.birth_date);
127
153
  }
154
+ const validationErrors = validateRequiredFields(values);
128
155
  if (require_home_store && !data.home_store) {
129
- setErrors({
130
- home_store: 'Please select a home store'
131
- });
156
+ validationErrors.home_store = 'Please select a home store';
157
+ }
158
+ if (Object.keys(validationErrors).length > 0) {
159
+ setErrors(validationErrors);
132
160
  return;
133
161
  }
134
162
  const loginToken = includeLoginRecaptcha
@@ -75,6 +75,28 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
75
75
  : value;
76
76
  setData(Object.assign(Object.assign({}, data), { [name]: val }));
77
77
  };
78
+ const validateRequiredFields = (values) => {
79
+ var _a, _b, _c, _d, _e;
80
+ const validationErrors = {};
81
+ // Check non-optional fields from CustomerCreate
82
+ if (!((_a = values.first_name) === null || _a === void 0 ? void 0 : _a.trim())) {
83
+ validationErrors.first_name = 'First name is required';
84
+ }
85
+ if (!((_b = values.last_name) === null || _b === void 0 ? void 0 : _b.trim())) {
86
+ validationErrors.last_name = 'Last name is required';
87
+ }
88
+ if (!((_c = values.email) === null || _c === void 0 ? void 0 : _c.trim())) {
89
+ validationErrors.email = 'Email is required';
90
+ }
91
+ if (!((_d = values.phone) === null || _d === void 0 ? void 0 : _d.trim())) {
92
+ validationErrors.phone = 'Phone is required';
93
+ }
94
+ // Check password if not Thanx (password is removed for Thanx)
95
+ if (!((_e = values.password) === null || _e === void 0 ? void 0 : _e.trim())) {
96
+ validationErrors.password = 'Password is required';
97
+ }
98
+ return validationErrors;
99
+ };
78
100
  const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
79
101
  var _a, _b, _c;
80
102
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -84,10 +106,14 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
84
106
  if (values.birth_date) {
85
107
  values.birth_date = slashesToDashes(values.birth_date);
86
108
  }
109
+ // Validate required fields
110
+ const validationErrors = validateRequiredFields(values);
87
111
  if (require_home_store && !data.home_store) {
88
- setErrors({
89
- home_store: 'Please select a home store'
90
- });
112
+ validationErrors.home_store = 'Please select a home store';
113
+ }
114
+ // If there are validation errors, set them and return early
115
+ if (Object.keys(validationErrors).length > 0) {
116
+ setErrors(validationErrors);
91
117
  return;
92
118
  }
93
119
  const loginToken = includeLoginRecaptcha
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.58",
3
+ "version": "0.5.59",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -57,7 +57,7 @@
57
57
  "typescript": "^4.8.2"
58
58
  },
59
59
  "peerDependencies": {
60
- "@open-tender/types": "^0.4.171",
60
+ "@open-tender/types": "^0.4.172",
61
61
  "@reduxjs/toolkit": "^1.8.5",
62
62
  "react": "^18.2.0"
63
63
  },