@qlibs/utils 1.10.0 → 1.11.0

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.
@@ -0,0 +1,2 @@
1
+ export declare function getBasePath(): string;
2
+ export declare function goBack(navigateFunction: Function): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBasePath = getBasePath;
4
+ exports.goBack = goBack;
5
+ function getBasePath() {
6
+ const pathname = window.location.pathname;
7
+ const segments = pathname.split('/').filter(Boolean);
8
+ if (segments.length <= 1)
9
+ return '/' + (segments[0] || '');
10
+ const baseSegments = segments.slice(0, -1);
11
+ return '/' + baseSegments.join('/');
12
+ }
13
+ function goBack(navigateFunction) {
14
+ if (window.history.length > 0) {
15
+ navigateFunction(-1);
16
+ }
17
+ else {
18
+ const backPath = getBasePath();
19
+ navigateFunction(backPath);
20
+ }
21
+ }
@@ -15,3 +15,4 @@ export declare function getStandardError(err: any, config?: {
15
15
  errors: any[] | null;
16
16
  };
17
17
  export declare function handleFormValidation(errors: any[], formRef: any): void;
18
+ export declare function showErrorMessage(toastFunction: any, message: any): void;
@@ -5,6 +5,7 @@ exports.getErrorCode = getErrorCode;
5
5
  exports.getErrors = getErrors;
6
6
  exports.getStandardError = getStandardError;
7
7
  exports.handleFormValidation = handleFormValidation;
8
+ exports.showErrorMessage = showErrorMessage;
8
9
  function getErrorMessage(err, config) {
9
10
  let errMessage = 'Failed. Please try again.';
10
11
  console.info('err', err);
@@ -116,20 +117,8 @@ function getStandardError(err, config) {
116
117
  if (config === null || config === void 0 ? void 0 : config.triggerFormValidation) {
117
118
  handleFormValidation(errors || [], config.formRef);
118
119
  }
119
- if ((config === null || config === void 0 ? void 0 : config.showToast) && (config === null || config === void 0 ? void 0 : config.toastFunction)) {
120
- if (config.toastFunction.confirm) {
121
- config.toastFunction.error({
122
- title: 'Failed',
123
- content: message,
124
- closable: true,
125
- });
126
- }
127
- else if (config.toastFunction.error) {
128
- config.toastFunction.error(message);
129
- }
130
- else if (typeof config.toastFunction === 'function') {
131
- config.toastFunction(message);
132
- }
120
+ if (config === null || config === void 0 ? void 0 : config.showToast) {
121
+ showErrorMessage(config.toastFunction, message);
133
122
  }
134
123
  return {
135
124
  code,
@@ -163,3 +152,20 @@ function handleFormValidation(errors, formRef) {
163
152
  formRef.setFields(fields);
164
153
  }
165
154
  }
155
+ function showErrorMessage(toastFunction, message) {
156
+ if (toastFunction) {
157
+ if (toastFunction.confirm) {
158
+ toastFunction.error({
159
+ title: 'Failed',
160
+ content: message,
161
+ closable: true,
162
+ });
163
+ }
164
+ else if (toastFunction.error) {
165
+ toastFunction.error(message);
166
+ }
167
+ else if (typeof toastFunction === 'function') {
168
+ toastFunction(message);
169
+ }
170
+ }
171
+ }
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onFinishFailed = void 0;
4
+ const errorHandler_1 = require("./errorHandler");
4
5
  const onFinishFailed = (antdErrorInfo, config) => {
5
6
  console.error('antdErrorInfo', antdErrorInfo);
6
7
  const { errorFields } = antdErrorInfo;
7
8
  if (errorFields && errorFields.length > 0) {
8
9
  const firstError = errorFields[0];
9
10
  if (firstError.errors && firstError.errors.length > 0) {
10
- config.toastFunction.error(firstError.errors.join(' '));
11
+ const message = firstError.errors.join(' ');
12
+ (0, errorHandler_1.showErrorMessage)(config.toastFunction, message);
11
13
  }
12
14
  setTimeout(() => {
13
15
  config.form.scrollToField(firstError.name, {
@@ -17,7 +19,7 @@ const onFinishFailed = (antdErrorInfo, config) => {
17
19
  }, 100);
18
20
  }
19
21
  else {
20
- config.toastFunction.error('Something wrong. Please check your inputs.');
22
+ (0, errorHandler_1.showErrorMessage)(config.toastFunction, 'Something wrong. Please check your inputs.');
21
23
  }
22
24
  };
23
25
  exports.onFinishFailed = onFinishFailed;
@@ -1,5 +1,6 @@
1
1
  export * from './auth';
2
2
  export * from './axios';
3
+ export * from './basePath';
3
4
  export * from './datetime';
4
5
  export * from './errorHandler';
5
6
  export * from './formRules';
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./auth"), exports);
18
18
  __exportStar(require("./axios"), exports);
19
+ __exportStar(require("./basePath"), exports);
19
20
  __exportStar(require("./datetime"), exports);
20
21
  __exportStar(require("./errorHandler"), exports);
21
22
  __exportStar(require("./formRules"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlibs/utils",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "author": "QBIT Developer",
6
6
  "license": "MIT",