@react-pakistan/util-functions 1.23.88 → 1.23.90

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.
@@ -3,16 +3,19 @@ interface FetchResult {
3
3
  error: any;
4
4
  }
5
5
  interface FetchConfig extends RequestInit {
6
- callback?: (result: FetchResult) => void;
7
6
  autoFetch?: boolean;
8
- showErrorNotification?: boolean;
9
- showSuccessNotification?: boolean;
7
+ callback?: (result: FetchResult) => void;
10
8
  }
11
9
  interface Return {
10
+ apiResult: API_RESULT | undefined;
12
11
  data: any;
13
12
  error: any;
14
- loading: boolean;
15
13
  fetchNow: (url?: string, config?: FetchConfig) => void;
14
+ loading: boolean;
15
+ }
16
+ export declare enum API_RESULT {
17
+ SUCCESS = "SUCCESS",
18
+ ERROR = "ERROR"
16
19
  }
17
20
  export declare const useFetch: (url: string, config?: FetchConfig) => Return;
18
21
  export {};
@@ -11,39 +11,6 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  return __assign.apply(this, arguments);
13
13
  };
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
- Object.defineProperty(o, "default", { enumerable: true, value: v });
27
- }) : function(o, v) {
28
- o["default"] = v;
29
- });
30
- var __importStar = (this && this.__importStar) || (function () {
31
- var ownKeys = function(o) {
32
- ownKeys = Object.getOwnPropertyNames || function (o) {
33
- var ar = [];
34
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
- return ar;
36
- };
37
- return ownKeys(o);
38
- };
39
- return function (mod) {
40
- if (mod && mod.__esModule) return mod;
41
- var result = {};
42
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
- __setModuleDefault(result, mod);
44
- return result;
45
- };
46
- })();
47
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
48
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
49
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -91,21 +58,21 @@ var __rest = (this && this.__rest) || function (s, e) {
91
58
  }
92
59
  return t;
93
60
  };
94
- var __importDefault = (this && this.__importDefault) || function (mod) {
95
- return (mod && mod.__esModule) ? mod : { "default": mod };
96
- };
97
61
  Object.defineProperty(exports, "__esModule", { value: true });
98
- exports.useFetch = void 0;
99
- var react_1 = __importStar(require("react"));
100
- var react_hot_toast_1 = __importDefault(require("react-hot-toast"));
101
- var vista_notification_v1_1 = require("@appcorp/app-corp-vista/molecules/vista-notification-v1/vista-notification-v1");
102
- var vista_notification_type_1 = require("@appcorp/app-corp-vista/type/vista-notification-type");
62
+ exports.useFetch = exports.API_RESULT = void 0;
63
+ var react_1 = require("react");
64
+ var API_RESULT;
65
+ (function (API_RESULT) {
66
+ API_RESULT["SUCCESS"] = "SUCCESS";
67
+ API_RESULT["ERROR"] = "ERROR";
68
+ })(API_RESULT || (exports.API_RESULT = API_RESULT = {}));
103
69
  var useFetch = function (url, config) {
104
70
  if (config === void 0) { config = {}; }
105
- var callback = config.callback, _a = config.autoFetch, autoFetch = _a === void 0 ? false : _a, _b = config.showErrorNotification, showErrorNotification = _b === void 0 ? false : _b, _c = config.showSuccessNotification, showSuccessNotification = _c === void 0 ? false : _c, defaultOptions = __rest(config, ["callback", "autoFetch", "showErrorNotification", "showSuccessNotification"]);
106
- var _d = (0, react_1.useState)(null), data = _d[0], setData = _d[1];
107
- var _e = (0, react_1.useState)(null), error = _e[0], setError = _e[1];
108
- var _f = (0, react_1.useState)(false), loading = _f[0], setLoading = _f[1];
71
+ var callback = config.callback, _a = config.autoFetch, autoFetch = _a === void 0 ? false : _a, defaultOptions = __rest(config, ["callback", "autoFetch"]);
72
+ var _b = (0, react_1.useState)(null), data = _b[0], setData = _b[1];
73
+ var _c = (0, react_1.useState)(null), error = _c[0], setError = _c[1];
74
+ var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
75
+ var _e = (0, react_1.useState)(undefined), apiResult = _e[0], setApiResult = _e[1];
109
76
  var abortControllerRef = (0, react_1.useRef)(null);
110
77
  var isMounted = (0, react_1.useRef)(true);
111
78
  (0, react_1.useEffect)(function () {
@@ -144,10 +111,8 @@ var useFetch = function (url, config) {
144
111
  if (isMounted.current) {
145
112
  setData(result);
146
113
  setError(null);
114
+ setApiResult(API_RESULT.SUCCESS);
147
115
  callback === null || callback === void 0 ? void 0 : callback({ data: result, error: null });
148
- if (showSuccessNotification) {
149
- react_hot_toast_1.default.custom(react_1.default.createElement(vista_notification_v1_1.VistaNotificationV1, { isVisible: true, handleIsVisible: function () { return void 0; }, variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS, description: 'Operation successful!' }));
150
- }
151
116
  }
152
117
  return [3 /*break*/, 6];
153
118
  case 4:
@@ -155,10 +120,8 @@ var useFetch = function (url, config) {
155
120
  if (isMounted.current) {
156
121
  setError(err_1);
157
122
  setData(null);
123
+ setApiResult(API_RESULT.ERROR);
158
124
  callback === null || callback === void 0 ? void 0 : callback({ data: null, error: err_1 });
159
- if (showErrorNotification) {
160
- react_hot_toast_1.default.custom(react_1.default.createElement(vista_notification_v1_1.VistaNotificationV1, { isVisible: true, handleIsVisible: function () { return void 0; }, variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR, description: 'Error occurred, try again!' }));
161
- }
162
125
  }
163
126
  return [3 /*break*/, 6];
164
127
  case 5:
@@ -176,10 +139,11 @@ var useFetch = function (url, config) {
176
139
  }
177
140
  }, [fetchNow, autoFetch]);
178
141
  return {
142
+ apiResult: apiResult,
179
143
  data: data,
180
144
  error: error,
181
- loading: loading,
182
145
  fetchNow: fetchNow,
146
+ loading: loading,
183
147
  };
184
148
  };
185
149
  exports.useFetch = useFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.23.88",
3
+ "version": "1.23.90",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -65,7 +65,6 @@
65
65
  "lodash.isequal": "^4.5.0",
66
66
  "next": "^14.2.3",
67
67
  "react": "^19",
68
- "react-hot-toast": "^2.5.2",
69
68
  "react-use": "^17.5.0",
70
69
  "rimraf": "^5.0.5",
71
70
  "ts-jest": "^29",