@qlibs/utils 1.9.1 → 1.10.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.
@@ -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,8 +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
- config.toastFunction.error(message);
120
+ if (config === null || config === void 0 ? void 0 : config.showToast) {
121
+ showErrorMessage(config.toastFunction, message);
121
122
  }
122
123
  return {
123
124
  code,
@@ -151,3 +152,20 @@ function handleFormValidation(errors, formRef) {
151
152
  formRef.setFields(fields);
152
153
  }
153
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlibs/utils",
3
- "version": "1.9.1",
3
+ "version": "1.10.1",
4
4
  "description": "",
5
5
  "author": "QBIT Developer",
6
6
  "license": "MIT",