@torq-north/react-tools 1.0.0 → 1.1.1

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/index.es.js CHANGED
@@ -144,8 +144,12 @@ var sendGet = function (url, params) { return __awaiter(void 0, void 0, void 0,
144
144
  switch (_a.label) {
145
145
  case 0:
146
146
  params &&
147
- Object.keys(params).forEach(function (key) { return params[key] === undefined && delete params[key]; });
148
- fetchUrl = params ? "".concat(url, "?").concat(new URLSearchParams(params).toString()) : url;
147
+ Object.keys(params).forEach(function (key) {
148
+ return params[key] === undefined && delete params[key];
149
+ });
150
+ fetchUrl = params
151
+ ? "".concat(url, "?").concat(new URLSearchParams(params).toString())
152
+ : url;
149
153
  return [4 /*yield*/, fetch(fetchUrl)];
150
154
  case 1:
151
155
  response = _a.sent();
@@ -246,11 +250,29 @@ function isJson(response) {
246
250
  }
247
251
  return contentType.indexOf("application/json") >= 0;
248
252
  }
253
+ var authLoginUrl = "/auth/login";
254
+ var authRedirectEnabled = false;
255
+ function enableAuthRedirect(loginUrl) {
256
+ if (loginUrl === void 0) { loginUrl = "/auth/login"; }
257
+ authLoginUrl = loginUrl;
258
+ authRedirectEnabled = true;
259
+ }
260
+ function isSessionExpired(response) {
261
+ return (response.status === 401 ||
262
+ (response.redirected && response.url.includes("/auth/login")));
263
+ }
249
264
  function process$1(response) {
250
265
  return __awaiter(this, void 0, void 0, function () {
251
266
  return __generator(this, function (_a) {
252
267
  switch (_a.label) {
253
- case 0: return [4 /*yield*/, checkResponse(response)];
268
+ case 0:
269
+ if (authRedirectEnabled && isSessionExpired(response)) {
270
+ window.location.href = authLoginUrl;
271
+ // Return a never-resolving promise to suspend execution while the browser navigates away,
272
+ // preventing any error handling or UI updates from firing before the page unloads.
273
+ return [2 /*return*/, new Promise(function () { })];
274
+ }
275
+ return [4 /*yield*/, checkResponse(response)];
254
276
  case 1:
255
277
  _a.sent();
256
278
  if (isJson(response)) {
@@ -768,7 +790,11 @@ var ErrorNotification = function (_a) {
768
790
  return (jsx(Snackbar, { open: open, autoHideDuration: 6000, onClose: onClose, children: jsx(Alert, { onClose: onClose, severity: "error", sx: { width: "100%" }, elevation: 6, variant: "filled", children: message !== null && message !== void 0 ? message : "An error has occured" }) }));
769
791
  };
770
792
 
771
- var DropIndicator = styled(Box)(function (_a) {
793
+ var DropIndicator = styled(Box, {
794
+ shouldForwardProp: function (propName) {
795
+ return propName != "dragOver" && propName != "multiple" && propName != "disabled";
796
+ },
797
+ })(function (_a) {
772
798
  var theme = _a.theme, dragOver = _a.dragOver, multiple = _a.multiple, disabled = _a.disabled;
773
799
  return ({
774
800
  padding: dragOver ? "1px" : "4px",
@@ -777,7 +803,7 @@ var DropIndicator = styled(Box)(function (_a) {
777
803
  borderRadius: 1,
778
804
  cursor: multiple ? undefined : "pointer",
779
805
  transition: "0.2s opacity",
780
- "&:hover": disabled
806
+ "&:hover": disabled || multiple
781
807
  ? undefined
782
808
  : {
783
809
  opacity: 0.8,
@@ -4778,7 +4804,7 @@ function useFileEditorField(name, options) {
4778
4804
  var _c = useState(""), errorMessage = _c[0], setErrorMessage = _c[1];
4779
4805
  var _d = useState(false), dragOverDropzone = _d[0], setDragOverDropzone = _d[1];
4780
4806
  var multiple = options.multiple, disabled = options.disabled, otherOptions = __rest(options, ["multiple", "disabled"]);
4781
- var _e = useDropzone(__assign({ multiple: multiple, noClick: multiple, noKeyboard: multiple, disabled: disabled, onDragEnter: function () { return setDragOverDropzone(true); }, onDragOver: function (e) {
4807
+ var _e = useDropzone(__assign({ multiple: multiple, noClick: multiple || values.length == 0, noKeyboard: multiple, disabled: disabled, onDragEnter: function () { return setDragOverDropzone(true); }, onDragOver: function (e) {
4782
4808
  e.preventDefault();
4783
4809
  e.stopPropagation();
4784
4810
  }, onDragLeave: function () { return setDragOverDropzone(false); }, onDrop: function () { return setDragOverDropzone(false); }, onDropAccepted: function (acceptedFiles) {
@@ -4881,9 +4907,9 @@ function IndividualFile(_a) {
4881
4907
  function FileDisplay(_a) {
4882
4908
  var files = _a.files, individualFileProps = __rest(_a, ["files"]);
4883
4909
  if (!Array.isArray(files)) {
4884
- return (jsx(Box, { p: 1, children: jsx(IndividualFile, __assign({ file: files }, individualFileProps)) }));
4910
+ return (jsx(Box, { children: jsx(IndividualFile, __assign({ file: files }, individualFileProps)) }));
4885
4911
  }
4886
- return (jsx(Stack, { p: 1, children: files.map(function (f) { return (jsx(IndividualFile, __assign({ file: f }, individualFileProps), isAsset(f) ? f.id : f.name)); }) }));
4912
+ return (jsx(Stack, { children: files.map(function (f) { return (jsx(IndividualFile, __assign({ file: f }, individualFileProps), isAsset(f) ? f.id : f.name)); }) }));
4887
4913
  }
4888
4914
 
4889
4915
  function FileEditorField(_a) {
@@ -4895,7 +4921,7 @@ function FileEditorField(_a) {
4895
4921
  required: required,
4896
4922
  fieldProps: slotProps === null || slotProps === void 0 ? void 0 : slotProps.field,
4897
4923
  }), getInputProps = _b.getInputProps, getRootProps = _b.getRootProps, dragOverDropzone = _b.dragOverDropzone, values = _b.values, removeFile = _b.removeFile, open = _b.open, showError = _b.showError, setShowError = _b.setShowError, errorMessage = _b.errorMessage, meta = _b.meta;
4898
- return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsxs(FormControl, { fullWidth: true, sx: { position: "relative" }, children: [label && (jsx(FormLabel, { disabled: disabled, error: meta.touched && meta.error, children: label })), jsx("input", __assign({}, getInputProps())), jsxs(DropIndicator, __assign({ multiple: multiple, dragOver: dragOverDropzone, disabled: disabled }, getRootProps(), { children: [jsx(Box, { sx: { opacity: disabled ? 0.4 : 1 }, children: jsx(FileDisplay, { files: values !== null && values !== void 0 ? values : [], disableLink: true, allowDelete: !disabled, onDelete: removeFile }) }), (multiple || (values === null || values === void 0 ? void 0 : values.length) == 0) && (jsx(Button, { onClick: open, startIcon: jsx(AddIcon, {}), fullWidth: true, disabled: disabled, children: placeholder !== null && placeholder !== void 0 ? placeholder : "Add File".concat(multiple ? "s" : "") }))] })), dragOverDropzone && (jsx(Stack, { position: "absolute", top: 0, bottom: 0, left: 0, right: 0, justifyContent: "center", alignItems: "center", sx: { pointerEvents: "none" }, children: jsx(NoteAddIcon, { sx: { fontSize: 50 } }) })), jsx(FormHelperText, { error: meta.touched && meta.error, children: (meta.touched && meta.error) || helperText })] }), jsx(ErrorNotification, { open: showError, onClose: function () { return setShowError(false); }, message: errorMessage })] }));
4924
+ return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsxs(FormControl, { fullWidth: true, sx: { position: "relative" }, children: [label && (jsx(FormLabel, { disabled: disabled, error: meta.touched && meta.error, children: label })), jsx("input", __assign({}, getInputProps())), jsx(DropIndicator, __assign({ multiple: multiple, dragOver: dragOverDropzone, disabled: disabled }, getRootProps(), { children: jsxs(Stack, { gap: 1, children: [values.length > 0 && (jsx(Box, { sx: { opacity: disabled ? 0.4 : 1 }, children: jsx(FileDisplay, { files: values !== null && values !== void 0 ? values : [], disableLink: true, allowDelete: !disabled, onDelete: removeFile }) })), (multiple || (values === null || values === void 0 ? void 0 : values.length) == 0) && (jsx(Button, { onClick: open, startIcon: jsx(AddIcon, {}), fullWidth: true, disabled: disabled, children: placeholder !== null && placeholder !== void 0 ? placeholder : "Add File".concat(multiple ? "s" : "") }))] }) })), dragOverDropzone && (jsx(Stack, { position: "absolute", top: 0, bottom: 0, left: 0, right: 0, justifyContent: "center", alignItems: "center", sx: { pointerEvents: "none" }, children: jsx(NoteAddIcon, { sx: { fontSize: 50 } }) })), jsx(FormHelperText, { error: meta.touched && meta.error, children: (meta.touched && meta.error) || helperText })] }), jsx(ErrorNotification, { open: showError, onClose: function () { return setShowError(false); }, message: errorMessage })] }));
4899
4925
  }
4900
4926
 
4901
4927
  function asInteger(value) {
@@ -5176,5 +5202,5 @@ function TabSet(_a) {
5176
5202
  }) }) }), jsx(Panel, __assign({}, actualTab === null || actualTab === void 0 ? void 0 : actualTab.PanelProps, { children: actualTab === null || actualTab === void 0 ? void 0 : actualTab.content }))] }));
5177
5203
  }
5178
5204
 
5179
- export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditorField, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, usePartialSetterState };
5205
+ export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditorField, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, enableAuthRedirect, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, usePartialSetterState };
5180
5206
  //# sourceMappingURL=index.es.js.map