@bigbinary/neeto-commons-frontend 2.0.39 → 2.0.41

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/README.md CHANGED
@@ -64,6 +64,7 @@ Category
64
64
  - [IpRestriction](./docs/react/components.md#iprestriction)
65
65
  - [PublishBlock](./docs/react/components.md#publishblock)
66
66
  - [KeyboardShortcutsPane](./docs/react/components.md#keyboardshortcutspane)
67
+ - [ShareViaLink](./docs/react/components.md#sharevialink)
67
68
  - [withImmutableActions](./docs/react/utils.md#withimmutableactions)
68
69
  - [withTitle](./docs/react/utils.md#withtitle)
69
70
  - [registerBrowserNotifications](./docs/react/utils.md#registerbrowsernotifications)
package/configs/babel.js CHANGED
@@ -16,15 +16,20 @@ module.exports = function (api) {
16
16
 
17
17
  return {
18
18
  presets: [
19
- [
20
- "@babel/preset-env",
21
- {
22
- forceAllTransforms: isProductionEnv,
23
- useBuiltIns: "entry",
24
- corejs: "3.27.0",
25
- modules: false,
26
- },
27
- ],
19
+ isTestEnv
20
+ ? [
21
+ "@babel/preset-env",
22
+ { targets: { node: "current" }, modules: "commonjs" },
23
+ ]
24
+ : [
25
+ "@babel/preset-env",
26
+ {
27
+ forceAllTransforms: isProductionEnv,
28
+ useBuiltIns: "entry",
29
+ corejs: "3.27.0",
30
+ modules: false,
31
+ },
32
+ ],
28
33
  ["@babel/preset-react", { development: isDevelopmentEnv || isTestEnv }],
29
34
  ].filter(Boolean),
30
35
  plugins: [
@@ -50,5 +50,7 @@ declare namespace Cypress {
50
50
  selector: string;
51
51
  });
52
52
  globalState(key: string): Void;
53
+ ifExist(selector: string, callback: Function): Void;
54
+ ifNotExist(selector: string, callback: Function): Void;
53
55
  }
54
56
  }
@@ -170,7 +170,8 @@ var commonSelectors = {
170
170
  selectOption: ".neeto-ui-react-select__option",
171
171
  toastMessage: dataCy("toastr-message-container"),
172
172
  toastCloseButton: ".neeto-ui-toastr__close-button",
173
- windowAlert: "#alert-box"
173
+ windowAlert: "#alert-box",
174
+ body: "body"
174
175
  };
175
176
  var tableSelectors = {
176
177
  nthColumn: function nthColumn(n) {
@@ -299,6 +300,16 @@ Cypress.Commands.add("openInSameTabOnClick", function (_ref) {
299
300
  Cypress.Commands.add("globalState", function (key) {
300
301
  return cy.task("getGlobalState", key);
301
302
  });
303
+ Cypress.Commands.add("ifExist", function (selector, callback) {
304
+ cy.get(commonSelectors.body).then(function ($body) {
305
+ if ($body.find(selector).length) callback();
306
+ });
307
+ });
308
+ Cypress.Commands.add("ifNotExist", function (selector, callback) {
309
+ cy.get(commonSelectors.body).then(function ($body) {
310
+ if (!$body.find(selector).length) callback();
311
+ });
312
+ });
302
313
 
303
314
  var loginSelectors = {
304
315
  appleAuthenticationButton: dataCy("apple-authentication-button"),
@@ -344,7 +355,8 @@ var signUpSelectors = {
344
355
  profileSubmitButton: dataCy("signup-profile-submit-button"),
345
356
  signupViaEmailButton: dataCy("signup-via-email-button"),
346
357
  submitButton: dataCy("signup-email-submit-button"),
347
- subdomainNameTextField: dataCy("signup-organization-subdomain-text-field")
358
+ subdomainNameTextField: dataCy("signup-organization-subdomain-text-field"),
359
+ subdomainError: dataCy("subdomain-input-error")
348
360
  };
349
361
 
350
362
  var commonTexts = {
@@ -683,6 +695,36 @@ var memberUtils = {
683
695
  verifyMemberDetails: verifyMemberDetails
684
696
  };
685
697
 
698
+ var updateSubdmainIfExit = function updateSubdmainIfExit(subdomainName) {
699
+ cy.ifExist(signUpSelectors.subdomainError, function () {
700
+ var lastDigit = Number(subdomainName.charAt(subdomainName.length - 1));
701
+ var newOrganizationName = subdomainName.slice(0, -1) + (lastDigit + 1);
702
+ cy.intercept({
703
+ url: requestApis.subdomainAvailablity,
704
+ times: 1
705
+ }).as("subdomainRequest");
706
+ cy.clearAndType(signUpSelectors.subdomainNameTextField, newOrganizationName);
707
+ cy.wait("@subdomainRequest");
708
+ cy.ifNotExist(signUpSelectors.subdomainError, function () {
709
+ cy.task("updateGlobalState", {
710
+ key: "subdomainName",
711
+ value: newOrganizationName
712
+ });
713
+ cy.task("updateGlobalState", {
714
+ key: "businessName",
715
+ value: newOrganizationName
716
+ });
717
+ var baseUrl = Cypress.config("baseUrl");
718
+ var domain = baseUrl.split(".")[1];
719
+ var newBaseUrl = "https://".concat(newOrganizationName, ".").concat(domain, ".net");
720
+ Cypress.config("baseUrl", newBaseUrl);
721
+ cy.clearAndType(signUpSelectors.organizationNameTextField, newOrganizationName);
722
+ });
723
+ cy.ifExist(signUpSelectors.subdomainError, function () {
724
+ return updateSubdmainIfExit(newOrganizationName);
725
+ });
726
+ });
727
+ };
686
728
  var createOrganization = function createOrganization(_ref) {
687
729
  var email = _ref.email,
688
730
  businessName = _ref.businessName,
@@ -703,15 +745,14 @@ var createOrganization = function createOrganization(_ref) {
703
745
  cy.wait("@signupRequest");
704
746
  cy.get(signUpSelectors.otpTextBox).type(otp);
705
747
  cy.wait("@signupRequest");
706
- cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
707
748
  cy.intercept({
708
749
  url: requestApis.subdomainAvailablity,
709
750
  times: 1
710
751
  }).as("subdomainRequest");
752
+ cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
711
753
  cy.clearAndType(signUpSelectors.subdomainNameTextField, subdomainName);
712
754
  cy.wait("@subdomainRequest");
713
- cy.get(signUpSelectors.organizationNameTextField).should("have.value", businessName);
714
- cy.get(signUpSelectors.subdomainNameTextField).should("have.value", subdomainName);
755
+ updateSubdmainIfExit(subdomainName);
715
756
  cy.intercept({
716
757
  url: requestApis.signUp,
717
758
  times: 1
@@ -14,6 +14,7 @@ type CommonSelectors = {
14
14
  toastMessage: string;
15
15
  toastCloseButton: string;
16
16
  windowAlert: string;
17
+ body: string;
17
18
  };
18
19
 
19
20
  type MemberSelectors = {
@@ -62,6 +63,7 @@ type SignUpSelectors = {
62
63
  signupViaEmailButton: string;
63
64
  submitButton: string;
64
65
  subdomainNameTextField: string;
66
+ subdomainError: string;
65
67
  };
66
68
 
67
69
  // texts ------------------------------------------------
package/cypress-utils.js CHANGED
@@ -162,7 +162,8 @@ var commonSelectors = {
162
162
  selectOption: ".neeto-ui-react-select__option",
163
163
  toastMessage: dataCy("toastr-message-container"),
164
164
  toastCloseButton: ".neeto-ui-toastr__close-button",
165
- windowAlert: "#alert-box"
165
+ windowAlert: "#alert-box",
166
+ body: "body"
166
167
  };
167
168
  var tableSelectors = {
168
169
  nthColumn: function nthColumn(n) {
@@ -291,6 +292,16 @@ Cypress.Commands.add("openInSameTabOnClick", function (_ref) {
291
292
  Cypress.Commands.add("globalState", function (key) {
292
293
  return cy.task("getGlobalState", key);
293
294
  });
295
+ Cypress.Commands.add("ifExist", function (selector, callback) {
296
+ cy.get(commonSelectors.body).then(function ($body) {
297
+ if ($body.find(selector).length) callback();
298
+ });
299
+ });
300
+ Cypress.Commands.add("ifNotExist", function (selector, callback) {
301
+ cy.get(commonSelectors.body).then(function ($body) {
302
+ if (!$body.find(selector).length) callback();
303
+ });
304
+ });
294
305
 
295
306
  var loginSelectors = {
296
307
  appleAuthenticationButton: dataCy("apple-authentication-button"),
@@ -336,7 +347,8 @@ var signUpSelectors = {
336
347
  profileSubmitButton: dataCy("signup-profile-submit-button"),
337
348
  signupViaEmailButton: dataCy("signup-via-email-button"),
338
349
  submitButton: dataCy("signup-email-submit-button"),
339
- subdomainNameTextField: dataCy("signup-organization-subdomain-text-field")
350
+ subdomainNameTextField: dataCy("signup-organization-subdomain-text-field"),
351
+ subdomainError: dataCy("subdomain-input-error")
340
352
  };
341
353
 
342
354
  var commonTexts = {
@@ -675,6 +687,36 @@ var memberUtils = {
675
687
  verifyMemberDetails: verifyMemberDetails
676
688
  };
677
689
 
690
+ var updateSubdmainIfExit = function updateSubdmainIfExit(subdomainName) {
691
+ cy.ifExist(signUpSelectors.subdomainError, function () {
692
+ var lastDigit = Number(subdomainName.charAt(subdomainName.length - 1));
693
+ var newOrganizationName = subdomainName.slice(0, -1) + (lastDigit + 1);
694
+ cy.intercept({
695
+ url: requestApis.subdomainAvailablity,
696
+ times: 1
697
+ }).as("subdomainRequest");
698
+ cy.clearAndType(signUpSelectors.subdomainNameTextField, newOrganizationName);
699
+ cy.wait("@subdomainRequest");
700
+ cy.ifNotExist(signUpSelectors.subdomainError, function () {
701
+ cy.task("updateGlobalState", {
702
+ key: "subdomainName",
703
+ value: newOrganizationName
704
+ });
705
+ cy.task("updateGlobalState", {
706
+ key: "businessName",
707
+ value: newOrganizationName
708
+ });
709
+ var baseUrl = Cypress.config("baseUrl");
710
+ var domain = baseUrl.split(".")[1];
711
+ var newBaseUrl = "https://".concat(newOrganizationName, ".").concat(domain, ".net");
712
+ Cypress.config("baseUrl", newBaseUrl);
713
+ cy.clearAndType(signUpSelectors.organizationNameTextField, newOrganizationName);
714
+ });
715
+ cy.ifExist(signUpSelectors.subdomainError, function () {
716
+ return updateSubdmainIfExit(newOrganizationName);
717
+ });
718
+ });
719
+ };
678
720
  var createOrganization = function createOrganization(_ref) {
679
721
  var email = _ref.email,
680
722
  businessName = _ref.businessName,
@@ -695,15 +737,14 @@ var createOrganization = function createOrganization(_ref) {
695
737
  cy.wait("@signupRequest");
696
738
  cy.get(signUpSelectors.otpTextBox).type(otp);
697
739
  cy.wait("@signupRequest");
698
- cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
699
740
  cy.intercept({
700
741
  url: requestApis.subdomainAvailablity,
701
742
  times: 1
702
743
  }).as("subdomainRequest");
744
+ cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
703
745
  cy.clearAndType(signUpSelectors.subdomainNameTextField, subdomainName);
704
746
  cy.wait("@subdomainRequest");
705
- cy.get(signUpSelectors.organizationNameTextField).should("have.value", businessName);
706
- cy.get(signUpSelectors.subdomainNameTextField).should("have.value", subdomainName);
747
+ updateSubdmainIfExit(subdomainName);
707
748
  cy.intercept({
708
749
  url: requestApis.signUp,
709
750
  times: 1
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
6
+ var pure = require('@bigbinary/neeto-commons-frontend/pure');
7
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
6
8
  var neetoui = require('@bigbinary/neetoui');
7
9
  var axios = require('axios');
8
10
  var i18next = require('i18next');
@@ -59,158 +61,6 @@ function _defineProperty(obj, key, value) {
59
61
  return obj;
60
62
  }
61
63
 
62
- function _arrayWithHoles(arr) {
63
- if (Array.isArray(arr)) return arr;
64
- }
65
-
66
- function _iterableToArrayLimit(arr, i) {
67
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
68
- if (null != _i) {
69
- var _s,
70
- _e,
71
- _x,
72
- _r,
73
- _arr = [],
74
- _n = !0,
75
- _d = !1;
76
- try {
77
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
78
- if (Object(_i) !== _i) return;
79
- _n = !1;
80
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
81
- } catch (err) {
82
- _d = !0, _e = err;
83
- } finally {
84
- try {
85
- if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
86
- } finally {
87
- if (_d) throw _e;
88
- }
89
- }
90
- return _arr;
91
- }
92
- }
93
-
94
- function _arrayLikeToArray(arr, len) {
95
- if (len == null || len > arr.length) len = arr.length;
96
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
97
- return arr2;
98
- }
99
-
100
- function _unsupportedIterableToArray(o, minLen) {
101
- if (!o) return;
102
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
103
- var n = Object.prototype.toString.call(o).slice(8, -1);
104
- if (n === "Object" && o.constructor) n = o.constructor.name;
105
- if (n === "Map" || n === "Set") return Array.from(o);
106
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
107
- }
108
-
109
- function _nonIterableRest() {
110
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
111
- }
112
-
113
- function _slicedToArray(arr, i) {
114
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
115
- }
116
-
117
- /**
118
- * @template {Function} T
119
- * @param {T} func
120
- * @returns {T}
121
- */
122
- var nullSafe = function nullSafe(func) {
123
- return (
124
- // @ts-ignore
125
- ramda.curryN(func.length, function () {
126
- var _ref;
127
- var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
128
- return ramda.isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
129
- })
130
- );
131
- };
132
-
133
- var snakeToCamelCase = function snakeToCamelCase(string) {
134
- return string.replace(/(_\w)/g, function (letter) {
135
- return letter[1].toUpperCase();
136
- });
137
- };
138
- var camelToSnakeCase = function camelToSnakeCase(string) {
139
- return string.replace(/[A-Z]/g, function (letter) {
140
- return "_".concat(letter.toLowerCase());
141
- });
142
- };
143
-
144
- var matchesImpl = function matchesImpl(pattern, object) {
145
- var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
146
- if (object === pattern) return true;
147
- if (typeof pattern === "function" && pattern(object, __parent)) return true;
148
- if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
149
- if (_typeof(pattern) !== "object") return false;
150
- return Object.entries(pattern).every(function (_ref) {
151
- var _ref2 = _slicedToArray(_ref, 2),
152
- key = _ref2[0],
153
- value = _ref2[1];
154
- return matchesImpl(value, object[key], __parent);
155
- });
156
- };
157
- var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
158
- var objectPreProcessor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
159
- if (objectPreProcessor && typeof objectPreProcessor === "function") {
160
- object = objectPreProcessor(object);
161
- }
162
- if (Array.isArray(object)) {
163
- return object.map(function (obj) {
164
- return transformObjectDeep(obj, keyValueTransformer, objectPreProcessor);
165
- });
166
- } else if (object === null || _typeof(object) !== "object") {
167
- return object;
168
- }
169
- return Object.fromEntries(Object.entries(object).map(function (_ref3) {
170
- var _ref4 = _slicedToArray(_ref3, 2),
171
- key = _ref4[0],
172
- value = _ref4[1];
173
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer, objectPreProcessor));
174
- }));
175
- };
176
- var keysToCamelCase = function keysToCamelCase(object) {
177
- return transformObjectDeep(object, function (key, value) {
178
- return [snakeToCamelCase(key), value];
179
- });
180
- };
181
- var serializeKeysToSnakeCase = function serializeKeysToSnakeCase(object) {
182
- return transformObjectDeep(object, function (key, value) {
183
- return [camelToSnakeCase(key), value];
184
- }, function (object) {
185
- return typeof (object === null || object === void 0 ? void 0 : object.toJSON) === "function" ? object.toJSON() : object;
186
- });
187
- };
188
- var deepFreezeObject = function deepFreezeObject(object) {
189
- if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
190
- Object.keys(object).forEach(function (property) {
191
- return deepFreezeObject(object[property]);
192
- });
193
- Object.freeze(object);
194
- }
195
- return object;
196
- };
197
- var matches = /*#__PURE__*/ramda.curry(function (pattern, object) {
198
- return matchesImpl(pattern, object);
199
- });
200
- var filterNonNull = function filterNonNull(object) {
201
- return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
202
- var _ref6 = _slicedToArray(_ref5, 2),
203
- v = _ref6[1];
204
- return !ramda.isNil(v);
205
- }).map(function (_ref7) {
206
- var _ref8 = _slicedToArray(_ref7, 2),
207
- k = _ref8[0],
208
- v = _ref8[1];
209
- return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
210
- }));
211
- };
212
- nullSafe(filterNonNull);
213
-
214
64
  var HEADERS_KEYS = {
215
65
  xAuthEmail: "X-Auth-Email",
216
66
  xAuthToken: "X-Auth-Token",
@@ -219,12 +69,6 @@ var HEADERS_KEYS = {
219
69
  accept: "Accept"
220
70
  };
221
71
 
222
- var resetAuthTokens = function resetAuthTokens() {
223
- ramda.values(HEADERS_KEYS).forEach(function (header) {
224
- delete axios__default["default"].defaults.headers[header];
225
- });
226
- };
227
-
228
72
  var shouldNot = function shouldNot(skip) {
229
73
  return _typeof(skip) === "object" || !skip;
230
74
  };
@@ -256,7 +100,7 @@ var transformResponseKeysToCamelCase = function transformResponseKeysToCamelCase
256
100
  var _response$config$tran = response.config.transformResponseCase,
257
101
  transformResponseCase = _response$config$tran === void 0 ? true : _response$config$tran;
258
102
  if (response.data && transformResponseCase) {
259
- response.data = keysToCamelCase(response.data);
103
+ response.data = pure.keysToCamelCase(response.data);
260
104
  }
261
105
  return response;
262
106
  };
@@ -266,7 +110,7 @@ var transformErrorKeysToCamelCase = function transformErrorKeysToCamelCase(error
266
110
  _ref$transformRespons = _ref.transformResponseCase,
267
111
  transformResponseCase = _ref$transformRespons === void 0 ? true : _ref$transformRespons;
268
112
  if ((_error$response = error.response) !== null && _error$response !== void 0 && _error$response.data && transformResponseCase) {
269
- error.response.data = keysToCamelCase(error.response.data);
113
+ error.response.data = pure.keysToCamelCase(error.response.data);
270
114
  }
271
115
  return error;
272
116
  };
@@ -274,7 +118,7 @@ var showSuccessToastr = function showSuccessToastr(response) {
274
118
  var _response$config$show = response.config.showToastr,
275
119
  showToastr = _response$config$show === void 0 ? true : _response$config$show;
276
120
  if (!showToastr) return response;
277
- if (matches({
121
+ if (pure.matches({
278
122
  showThumbsUpToastr: true
279
123
  }, response.data)) {
280
124
  // @ts-ignore
@@ -282,6 +126,14 @@ var showSuccessToastr = function showSuccessToastr(response) {
282
126
  icon: "👍",
283
127
  className: "w-20"
284
128
  });
129
+ } else if (pure.matches({
130
+ noticeCode: "thumbs_up"
131
+ }, response.data)) {
132
+ // @ts-ignore
133
+ neetoui.Toastr.success("", {
134
+ icon: "👍",
135
+ className: "w-20"
136
+ });
285
137
  } else if (shouldShowToastr(response.data)) {
286
138
  neetoui.Toastr.success(response.data);
287
139
  }
@@ -302,7 +154,7 @@ var buildSuccessResponseHandler = function buildSuccessResponseHandler(skip) {
302
154
  var handleUnauthorizedErrorResponse = function handleUnauthorizedErrorResponse(error) {
303
155
  var _error$response2, _error$config2;
304
156
  if (((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) !== 401) return error;
305
- resetAuthTokens();
157
+ utils.resetAuthTokens();
306
158
  var _ref2 = (_error$config2 = error.config) !== null && _error$config2 !== void 0 ? _error$config2 : {},
307
159
  _ref2$redirectOnError = _ref2.redirectOnError,
308
160
  redirectOnError = _ref2$redirectOnError === void 0 ? true : _ref2$redirectOnError;
@@ -369,8 +221,8 @@ var transformDataToSnakeCase = function transformDataToSnakeCase(request) {
369
221
  transformRequestCase = _request$transformReq === void 0 ? true : _request$transformReq;
370
222
  if (!transformRequestCase) return request;
371
223
  return ramda.evolve({
372
- data: serializeKeysToSnakeCase,
373
- params: serializeKeysToSnakeCase
224
+ data: pure.serializeKeysToSnakeCase,
225
+ params: pure.serializeKeysToSnakeCase
374
226
  }, request);
375
227
  };
376
228
  var addRequestInterceptors = function addRequestInterceptors(skip) {
@@ -396,8 +248,8 @@ function initializeAxios(skip) {
396
248
 
397
249
  function initializeGlobalProps() {
398
250
  var _document$getElements, _document$getElements2;
399
- window.globalProps = keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
400
- deepFreezeObject(window.globalProps);
251
+ window.globalProps = pure.keysToCamelCase(JSON.parse(((_document$getElements = document.getElementsByClassName("root-container")[0]) === null || _document$getElements === void 0 ? void 0 : (_document$getElements2 = _document$getElements.dataset) === null || _document$getElements2 === void 0 ? void 0 : _document$getElements2.reactProps) || "{}"));
252
+ pure.deepFreezeObject(window.globalProps);
401
253
  }
402
254
 
403
255
  var generic = {