@bigbinary/neeto-commons-frontend 2.0.9 → 2.0.10

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
@@ -7,7 +7,7 @@ The commons frontend library for Neeto Applications.
7
7
  Install from npm:
8
8
 
9
9
  ```bash
10
- yarn add "@bigbinary/neeto-commons-frontend@2.0.9"
10
+ yarn add "@bigbinary/neeto-commons-frontend@2.0.10"
11
11
  ```
12
12
 
13
13
  This package relies on the host project's tailwind configuration. So add
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -47,7 +47,9 @@
47
47
  "@babel/preset-env": "^7.17.10",
48
48
  "@babel/preset-react": "^7.16.7",
49
49
  "@bigbinary/neeto-icons": "^1.8.35",
50
- "@bigbinary/neetoui": "^3.5.16",
50
+ "@bigbinary/neetoui": "^4.0.0",
51
+ "antd": "4.18.7",
52
+ "react-toastify": "^9.0.8",
51
53
  "@honeybadger-io/react": "2.0.1",
52
54
  "@rollup/plugin-alias": "^3.1.9",
53
55
  "@rollup/plugin-babel": "^5.3.1",
@@ -96,7 +98,7 @@
96
98
  "dependencies": {},
97
99
  "peerDependencies": {
98
100
  "@bigbinary/neeto-icons": "^1.8.35",
99
- "@bigbinary/neetoui": "^3.5.16",
101
+ "@bigbinary/neetoui": "^4.0.0",
100
102
  "@honeybadger-io/react": "2.0.1",
101
103
  "axios": "^0.27.2",
102
104
  "dayjs": "1.11.1",
@@ -108,7 +108,8 @@ var DateFormat = ramda.fromPairs(ramda.keys(timeFormat).map(function (key) {
108
108
  _ref$typographyProps = _ref.typographyProps,
109
109
  typographyProps = _ref$typographyProps === void 0 ? {} : _ref$typographyProps;
110
110
  var dateDisplay = /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, _extends$3({
111
- component: "span"
111
+ component: "span",
112
+ style: "body2"
112
113
  }, typographyProps), timeFormat[key](date));
113
114
  return key === "extended" ? dateDisplay : /*#__PURE__*/React__default["default"].createElement(neetoui.Tooltip, _extends$3({
114
115
  position: "top",
@@ -239,24 +240,19 @@ function _objectWithoutProperties(source, excluded) {
239
240
  return target;
240
241
  }
241
242
 
242
- var _excluded = ["component", "condition", "path", "redirectRoute"];
243
+ var _excluded = ["condition", "redirectRoute"];
243
244
 
244
245
  var PrivateRoute = function PrivateRoute(_ref) {
245
- var Component = _ref.component,
246
- condition = _ref.condition,
247
- path = _ref.path,
246
+ var _ref$condition = _ref.condition,
247
+ condition = _ref$condition === void 0 ? globalProps.authenticated : _ref$condition,
248
248
  redirectRoute = _ref.redirectRoute,
249
249
  props = _objectWithoutProperties(_ref, _excluded);
250
250
 
251
- if (!condition) return /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Redirect, {
251
+ return condition ? /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Route, props) : /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Redirect, {
252
252
  to: {
253
253
  pathname: redirectRoute
254
254
  }
255
255
  });
256
- return /*#__PURE__*/React__default["default"].createElement(reactRouterDom.Route, _extends$3({
257
- path: path,
258
- component: Component
259
- }, props));
260
256
  };
261
257
 
262
258
  function _arrayWithHoles(arr) {
@@ -470,6 +466,43 @@ var useFuncDebounce = function useFuncDebounce(func) {
470
466
  return debouncedFunc;
471
467
  };
472
468
 
469
+ var useForceUpdate = function useForceUpdate() {
470
+ var _useState = React.useState(0),
471
+ _useState2 = _slicedToArray(_useState, 2),
472
+ setValue = _useState2[1];
473
+
474
+ return function () {
475
+ return setValue(function (value) {
476
+ return value + 1;
477
+ });
478
+ };
479
+ };
480
+
481
+ var useIsElementVisibleInDom = function useIsElementVisibleInDom(target) {
482
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
483
+
484
+ var _useState = React.useState(false),
485
+ _useState2 = _slicedToArray(_useState, 2),
486
+ isIntersecting = _useState2[0],
487
+ setIntersecting = _useState2[1];
488
+
489
+ var forceUpdate = useForceUpdate();
490
+ React.useEffect(function () {
491
+ if (!target) return forceUpdate();
492
+ var observer = new IntersectionObserver(function (_ref) {
493
+ var _ref2 = _slicedToArray(_ref, 1),
494
+ entry = _ref2[0];
495
+
496
+ return setIntersecting(entry.isIntersecting);
497
+ }, options);
498
+ observer.observe(target);
499
+ return function () {
500
+ return observer.unobserve(target);
501
+ };
502
+ }, [target, options]);
503
+ return isIntersecting;
504
+ };
505
+
473
506
  var getStorageValue = function getStorageValue(key, defaultValue) {
474
507
  var saved = localStorage.getItem(key);
475
508
  return JSON.parse(saved) || defaultValue;
@@ -682,7 +715,10 @@ var SvgNeetoLogo = function SvgNeetoLogo(props) {
682
715
  })))));
683
716
  };
684
717
 
685
- var ErrorPage = function ErrorPage() {
718
+ var ErrorPage = function ErrorPage(_ref) {
719
+ var _ref$homeUrl = _ref.homeUrl,
720
+ homeUrl = _ref$homeUrl === void 0 ? "/" : _ref$homeUrl;
721
+
686
722
  var _useTranslation = reactI18next.useTranslation(),
687
723
  t = _useTranslation.t;
688
724
 
@@ -710,7 +746,7 @@ var ErrorPage = function ErrorPage() {
710
746
  className: "flex flex-row items-center justify-center"
711
747
  }, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
712
748
  style: "primary",
713
- href: "/",
749
+ href: homeUrl,
714
750
  size: "large",
715
751
  label: t("neetoCommons.errorPage.goToHome")
716
752
  }))))));
@@ -1157,11 +1193,11 @@ function SignInForm(_ref) {
1157
1193
  var handleFormSubmit = _ref.handleFormSubmit;
1158
1194
 
1159
1195
  var emailFromSearchParams = function emailFromSearchParams() {
1160
- return new URLSearchParams(window.location.href).get("email");
1196
+ return new URLSearchParams(window.location.search).get("email") || "";
1161
1197
  };
1162
1198
 
1163
1199
  var emailPrefilledInitialValues = function emailPrefilledInitialValues() {
1164
- return ramda.assocPath(["user", "email"], emailFromSearchParams() || "", INITIAL_FORM_VALUES);
1200
+ return ramda.assoc("email", emailFromSearchParams(), INITIAL_FORM_VALUES);
1165
1201
  };
1166
1202
 
1167
1203
  if (formik.Button === undefined) {
@@ -1312,6 +1348,7 @@ exports.TimeFormat = TimeFormat;
1312
1348
  exports.createContext = createContext;
1313
1349
  exports.useDebounce = useDebounce;
1314
1350
  exports.useFuncDebounce = useFuncDebounce;
1351
+ exports.useIsElementVisibleInDom = useIsElementVisibleInDom;
1315
1352
  exports.useLocalStorage = useLocalStorage;
1316
1353
  exports.useOnClickOutside = useOnClickOutside;
1317
1354
  exports.usePrevious = usePrevious;
package/react-utils.d.ts CHANGED
@@ -10,7 +10,7 @@ export const HoneybadgerErrorBoundary: React.FC<{
10
10
  }>;
11
11
  export function PrivateRoute(
12
12
  props: {
13
- condition: boolean;
13
+ condition?: boolean;
14
14
  redirectRoute: string;
15
15
  } & RouteProps
16
16
  ): JSX.Element;
@@ -36,11 +36,17 @@ export const Sidebar: React.FC<{
36
36
  showAppSwitcher?: boolean;
37
37
  }>;
38
38
 
39
+ type OptionsType = {
40
+ root?: Element | null,
41
+ rootMargin?: String,
42
+ threshold?: Number | Number[]
43
+ }
44
+ export function useIsElementVisibleInDom(target: Element | null, options?: OptionsType): Boolean
39
45
  export function useDebounce<T>(value: T, delay?: number): T;
40
46
  export function useFuncDebounce<F extends Function>(
41
47
  func: F,
42
48
  delay?: number
43
- ): (F & { cancel: () => void };
49
+ ): F & { cancel: () => void };
44
50
  export function useLocalStorage<T>(
45
51
  key: string,
46
52
  initialValue?: T
@@ -72,7 +78,7 @@ export function createContext<T>(
72
78
  useContext: [T, (action: ActionType<T>) => void];
73
79
  };
74
80
 
75
- export const ErrorPage: React.FC<{}>;
81
+ export const ErrorPage: React.FC<{ homeUrl?: string }>;
76
82
  export const LoginPage: React.FC<{
77
83
  handleSubmit: (data: {
78
84
  user: {
package/react-utils.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { useState, useEffect, useRef, useReducer } from 'react';
3
3
  import { Typography, Tooltip, Button, Toastr } from '@bigbinary/neetoui';
4
- import { fromPairs, keys, values, mergeLeft, toLower, not, isNil, assocPath } from 'ramda';
4
+ import { fromPairs, keys, values, mergeLeft, toLower, not, isNil, assoc } from 'ramda';
5
5
  import dayjs from 'dayjs';
6
6
  import relativeTime from 'dayjs/plugin/relativeTime';
7
7
  import updateLocale from 'dayjs/plugin/updateLocale';
8
8
  import { Honeybadger, HoneybadgerErrorBoundary as HoneybadgerErrorBoundary$1 } from '@honeybadger-io/react';
9
9
  import { useTranslation } from 'react-i18next';
10
- import { Redirect, Route, useLocation } from 'react-router-dom';
10
+ import { Route, Redirect, useLocation } from 'react-router-dom';
11
11
  import { Settings, LeftArrow, Help, User } from '@bigbinary/neeto-icons';
12
12
  import { Sidebar as Sidebar$1, AppSwitcher } from '@bigbinary/neetoui/layouts';
13
13
  import i18next from 'i18next';
@@ -76,7 +76,8 @@ var DateFormat = fromPairs(keys(timeFormat).map(function (key) {
76
76
  _ref$typographyProps = _ref.typographyProps,
77
77
  typographyProps = _ref$typographyProps === void 0 ? {} : _ref$typographyProps;
78
78
  var dateDisplay = /*#__PURE__*/React__default.createElement(Typography, _extends$3({
79
- component: "span"
79
+ component: "span",
80
+ style: "body2"
80
81
  }, typographyProps), timeFormat[key](date));
81
82
  return key === "extended" ? dateDisplay : /*#__PURE__*/React__default.createElement(Tooltip, _extends$3({
82
83
  position: "top",
@@ -207,24 +208,19 @@ function _objectWithoutProperties(source, excluded) {
207
208
  return target;
208
209
  }
209
210
 
210
- var _excluded = ["component", "condition", "path", "redirectRoute"];
211
+ var _excluded = ["condition", "redirectRoute"];
211
212
 
212
213
  var PrivateRoute = function PrivateRoute(_ref) {
213
- var Component = _ref.component,
214
- condition = _ref.condition,
215
- path = _ref.path,
214
+ var _ref$condition = _ref.condition,
215
+ condition = _ref$condition === void 0 ? globalProps.authenticated : _ref$condition,
216
216
  redirectRoute = _ref.redirectRoute,
217
217
  props = _objectWithoutProperties(_ref, _excluded);
218
218
 
219
- if (!condition) return /*#__PURE__*/React__default.createElement(Redirect, {
219
+ return condition ? /*#__PURE__*/React__default.createElement(Route, props) : /*#__PURE__*/React__default.createElement(Redirect, {
220
220
  to: {
221
221
  pathname: redirectRoute
222
222
  }
223
223
  });
224
- return /*#__PURE__*/React__default.createElement(Route, _extends$3({
225
- path: path,
226
- component: Component
227
- }, props));
228
224
  };
229
225
 
230
226
  function _arrayWithHoles(arr) {
@@ -438,6 +434,43 @@ var useFuncDebounce = function useFuncDebounce(func) {
438
434
  return debouncedFunc;
439
435
  };
440
436
 
437
+ var useForceUpdate = function useForceUpdate() {
438
+ var _useState = useState(0),
439
+ _useState2 = _slicedToArray(_useState, 2),
440
+ setValue = _useState2[1];
441
+
442
+ return function () {
443
+ return setValue(function (value) {
444
+ return value + 1;
445
+ });
446
+ };
447
+ };
448
+
449
+ var useIsElementVisibleInDom = function useIsElementVisibleInDom(target) {
450
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
451
+
452
+ var _useState = useState(false),
453
+ _useState2 = _slicedToArray(_useState, 2),
454
+ isIntersecting = _useState2[0],
455
+ setIntersecting = _useState2[1];
456
+
457
+ var forceUpdate = useForceUpdate();
458
+ useEffect(function () {
459
+ if (!target) return forceUpdate();
460
+ var observer = new IntersectionObserver(function (_ref) {
461
+ var _ref2 = _slicedToArray(_ref, 1),
462
+ entry = _ref2[0];
463
+
464
+ return setIntersecting(entry.isIntersecting);
465
+ }, options);
466
+ observer.observe(target);
467
+ return function () {
468
+ return observer.unobserve(target);
469
+ };
470
+ }, [target, options]);
471
+ return isIntersecting;
472
+ };
473
+
441
474
  var getStorageValue = function getStorageValue(key, defaultValue) {
442
475
  var saved = localStorage.getItem(key);
443
476
  return JSON.parse(saved) || defaultValue;
@@ -650,7 +683,10 @@ var SvgNeetoLogo = function SvgNeetoLogo(props) {
650
683
  })))));
651
684
  };
652
685
 
653
- var ErrorPage = function ErrorPage() {
686
+ var ErrorPage = function ErrorPage(_ref) {
687
+ var _ref$homeUrl = _ref.homeUrl,
688
+ homeUrl = _ref$homeUrl === void 0 ? "/" : _ref$homeUrl;
689
+
654
690
  var _useTranslation = useTranslation(),
655
691
  t = _useTranslation.t;
656
692
 
@@ -678,7 +714,7 @@ var ErrorPage = function ErrorPage() {
678
714
  className: "flex flex-row items-center justify-center"
679
715
  }, /*#__PURE__*/React__default.createElement(Button, {
680
716
  style: "primary",
681
- href: "/",
717
+ href: homeUrl,
682
718
  size: "large",
683
719
  label: t("neetoCommons.errorPage.goToHome")
684
720
  }))))));
@@ -1125,11 +1161,11 @@ function SignInForm(_ref) {
1125
1161
  var handleFormSubmit = _ref.handleFormSubmit;
1126
1162
 
1127
1163
  var emailFromSearchParams = function emailFromSearchParams() {
1128
- return new URLSearchParams(window.location.href).get("email");
1164
+ return new URLSearchParams(window.location.search).get("email") || "";
1129
1165
  };
1130
1166
 
1131
1167
  var emailPrefilledInitialValues = function emailPrefilledInitialValues() {
1132
- return assocPath(["user", "email"], emailFromSearchParams() || "", INITIAL_FORM_VALUES);
1168
+ return assoc("email", emailFromSearchParams(), INITIAL_FORM_VALUES);
1133
1169
  };
1134
1170
 
1135
1171
  if (Button$1 === undefined) {
@@ -1270,4 +1306,4 @@ function SignIn(_ref) {
1270
1306
  })));
1271
1307
  }
1272
1308
 
1273
- export { DateFormat, ErrorPage, HoneybadgerErrorBoundary, SignIn as LoginPage, PrivateRoute, Sidebar, TimeFormat, createContext, useDebounce, useFuncDebounce, useLocalStorage, useOnClickOutside, usePrevious, useUpdateEffect };
1309
+ export { DateFormat, ErrorPage, HoneybadgerErrorBoundary, SignIn as LoginPage, PrivateRoute, Sidebar, TimeFormat, createContext, useDebounce, useFuncDebounce, useIsElementVisibleInDom, useLocalStorage, useOnClickOutside, usePrevious, useUpdateEffect };
package/utils.cjs.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var axios = require('axios');
6
6
  var ramda = require('ramda');
7
+ var neetoui = require('@bigbinary/neetoui');
7
8
  var i18next = require('i18next');
8
9
  var require$$0 = require('util');
9
10
  var dayjs = require('dayjs');
@@ -2633,8 +2634,6 @@ var copyToClipboard = /*#__PURE__*/function () {
2633
2634
  showToastr,
2634
2635
  _ref2$message,
2635
2636
  message,
2636
- _require,
2637
- Toastr,
2638
2637
  textArea,
2639
2638
  _args = arguments;
2640
2639
 
@@ -2643,27 +2642,21 @@ var copyToClipboard = /*#__PURE__*/function () {
2643
2642
  switch (_context.prev = _context.next) {
2644
2643
  case 0:
2645
2644
  _ref2 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref2$showToastr = _ref2.showToastr, showToastr = _ref2$showToastr === void 0 ? true : _ref2$showToastr, _ref2$message = _ref2.message, message = _ref2$message === void 0 ? i18next__default["default"].t("neetoCommons.toastr.success.copiedToClipboard") : _ref2$message;
2646
-
2647
- /*
2648
- This is a workaround to prevent the jest tests from failing. Once the issue in neetoUI
2649
- https://github.com/bigbinary/neeto-ui/issues/1175 is resolved, this import can be moved to the top of the file.
2650
- */
2651
- _require = require("@bigbinary/neetoui"), Toastr = _require.Toastr;
2652
- _context.prev = 2;
2645
+ _context.prev = 1;
2653
2646
 
2654
2647
  if (!(navigator.clipboard && window.isSecureContext)) {
2655
- _context.next = 8;
2648
+ _context.next = 7;
2656
2649
  break;
2657
2650
  }
2658
2651
 
2659
- _context.next = 6;
2652
+ _context.next = 5;
2660
2653
  return navigator.clipboard.writeText(text);
2661
2654
 
2662
- case 6:
2663
- _context.next = 18;
2655
+ case 5:
2656
+ _context.next = 17;
2664
2657
  break;
2665
2658
 
2666
- case 8:
2659
+ case 7:
2667
2660
  textArea = document.createElement("textarea");
2668
2661
  textArea.value = text;
2669
2662
  textArea.style.top = "0";
@@ -2675,22 +2668,22 @@ var copyToClipboard = /*#__PURE__*/function () {
2675
2668
  document.execCommand("copy");
2676
2669
  document.body.removeChild(textArea);
2677
2670
 
2678
- case 18:
2679
- showToastr && Toastr.success(message);
2680
- _context.next = 24;
2671
+ case 17:
2672
+ showToastr && neetoui.Toastr.success(message);
2673
+ _context.next = 23;
2681
2674
  break;
2682
2675
 
2683
- case 21:
2684
- _context.prev = 21;
2685
- _context.t0 = _context["catch"](2);
2686
- Toastr.error(_context.t0);
2676
+ case 20:
2677
+ _context.prev = 20;
2678
+ _context.t0 = _context["catch"](1);
2679
+ neetoui.Toastr.error(_context.t0);
2687
2680
 
2688
- case 24:
2681
+ case 23:
2689
2682
  case "end":
2690
2683
  return _context.stop();
2691
2684
  }
2692
2685
  }
2693
- }, _callee, null, [[2, 21]]);
2686
+ }, _callee, null, [[1, 20]]);
2694
2687
  }));
2695
2688
 
2696
2689
  return function copyToClipboard(_x) {
package/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { values, curry, toPairs, pipe, omit, isEmpty } from 'ramda';
3
+ import { Toastr } from '@bigbinary/neetoui';
3
4
  import i18next from 'i18next';
4
5
  import require$$0 from 'util';
5
6
  import dayjs from 'dayjs';
@@ -2620,8 +2621,6 @@ var copyToClipboard = /*#__PURE__*/function () {
2620
2621
  showToastr,
2621
2622
  _ref2$message,
2622
2623
  message,
2623
- _require,
2624
- Toastr,
2625
2624
  textArea,
2626
2625
  _args = arguments;
2627
2626
 
@@ -2630,27 +2629,21 @@ var copyToClipboard = /*#__PURE__*/function () {
2630
2629
  switch (_context.prev = _context.next) {
2631
2630
  case 0:
2632
2631
  _ref2 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref2$showToastr = _ref2.showToastr, showToastr = _ref2$showToastr === void 0 ? true : _ref2$showToastr, _ref2$message = _ref2.message, message = _ref2$message === void 0 ? i18next.t("neetoCommons.toastr.success.copiedToClipboard") : _ref2$message;
2633
-
2634
- /*
2635
- This is a workaround to prevent the jest tests from failing. Once the issue in neetoUI
2636
- https://github.com/bigbinary/neeto-ui/issues/1175 is resolved, this import can be moved to the top of the file.
2637
- */
2638
- _require = require("@bigbinary/neetoui"), Toastr = _require.Toastr;
2639
- _context.prev = 2;
2632
+ _context.prev = 1;
2640
2633
 
2641
2634
  if (!(navigator.clipboard && window.isSecureContext)) {
2642
- _context.next = 8;
2635
+ _context.next = 7;
2643
2636
  break;
2644
2637
  }
2645
2638
 
2646
- _context.next = 6;
2639
+ _context.next = 5;
2647
2640
  return navigator.clipboard.writeText(text);
2648
2641
 
2649
- case 6:
2650
- _context.next = 18;
2642
+ case 5:
2643
+ _context.next = 17;
2651
2644
  break;
2652
2645
 
2653
- case 8:
2646
+ case 7:
2654
2647
  textArea = document.createElement("textarea");
2655
2648
  textArea.value = text;
2656
2649
  textArea.style.top = "0";
@@ -2662,22 +2655,22 @@ var copyToClipboard = /*#__PURE__*/function () {
2662
2655
  document.execCommand("copy");
2663
2656
  document.body.removeChild(textArea);
2664
2657
 
2665
- case 18:
2658
+ case 17:
2666
2659
  showToastr && Toastr.success(message);
2667
- _context.next = 24;
2660
+ _context.next = 23;
2668
2661
  break;
2669
2662
 
2670
- case 21:
2671
- _context.prev = 21;
2672
- _context.t0 = _context["catch"](2);
2663
+ case 20:
2664
+ _context.prev = 20;
2665
+ _context.t0 = _context["catch"](1);
2673
2666
  Toastr.error(_context.t0);
2674
2667
 
2675
- case 24:
2668
+ case 23:
2676
2669
  case "end":
2677
2670
  return _context.stop();
2678
2671
  }
2679
2672
  }
2680
- }, _callee, null, [[2, 21]]);
2673
+ }, _callee, null, [[1, 20]]);
2681
2674
  }));
2682
2675
 
2683
2676
  return function copyToClipboard(_x) {