@react-pakistan/util-functions 1.25.18 → 1.25.19
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.
|
@@ -75,6 +75,8 @@ interface Params {
|
|
|
75
75
|
listDeps?: Array<any> | Array<string>;
|
|
76
76
|
listParams: object;
|
|
77
77
|
listUrl: string;
|
|
78
|
+
/** Optional headers to include on every fetch made by this hook */
|
|
79
|
+
headers?: Record<string, string>;
|
|
78
80
|
searchQuery: string;
|
|
79
81
|
unitByIdUrl: string;
|
|
80
82
|
unitUrl: string;
|
|
@@ -96,5 +98,5 @@ interface Return {
|
|
|
96
98
|
updateFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
97
99
|
updateLoading: boolean;
|
|
98
100
|
}
|
|
99
|
-
export declare const useModuleEntityV2: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
|
|
101
|
+
export declare const useModuleEntityV2: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, headers, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
|
|
100
102
|
export {};
|
|
@@ -74,7 +74,7 @@ var constants_1 = require("../constants");
|
|
|
74
74
|
var use_fetch_1 = require("./use-fetch");
|
|
75
75
|
var use_debounce_1 = require("./use-debounce");
|
|
76
76
|
var useModuleEntityV2 = function (_a) {
|
|
77
|
-
var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
|
|
77
|
+
var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, headers = _a.headers, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
|
|
78
78
|
var debouncedQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
|
|
79
79
|
// debounced list refresh to batch multiple updates/deletes
|
|
80
80
|
var refreshTimerRef = (0, react_1.useRef)(null);
|
|
@@ -88,6 +88,7 @@ var useModuleEntityV2 = function (_a) {
|
|
|
88
88
|
var _f = (0, use_fetch_1.useFetch)(listUrl, {
|
|
89
89
|
method: constants_1.API_METHODS.GET,
|
|
90
90
|
params: listParams,
|
|
91
|
+
headers: headers,
|
|
91
92
|
callback: listCallback,
|
|
92
93
|
credentials: true,
|
|
93
94
|
}, __spreadArray([debouncedQuery, listParams], listDeps, true)), listError = _f.error, listFetchNow = _f.fetchNow, listLoading = _f.loading;
|
|
@@ -102,6 +103,7 @@ var useModuleEntityV2 = function (_a) {
|
|
|
102
103
|
listFetchNow(undefined, {
|
|
103
104
|
method: constants_1.API_METHODS.GET,
|
|
104
105
|
params: listParams,
|
|
106
|
+
headers: headers,
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
catch (_a) {
|
|
@@ -114,6 +116,7 @@ var useModuleEntityV2 = function (_a) {
|
|
|
114
116
|
var _g = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
115
117
|
method: constants_1.API_METHODS.PUT,
|
|
116
118
|
body: JSON.stringify(updateParams),
|
|
119
|
+
headers: headers,
|
|
117
120
|
callback: function (d) {
|
|
118
121
|
if (updateCallback) {
|
|
119
122
|
try {
|
|
@@ -139,12 +142,14 @@ var useModuleEntityV2 = function (_a) {
|
|
|
139
142
|
var _h = (0, use_fetch_1.useFetch)(unitByIdUrl, {
|
|
140
143
|
method: constants_1.API_METHODS.GET,
|
|
141
144
|
params: byIdParams,
|
|
145
|
+
headers: headers,
|
|
142
146
|
callback: byIdCallback,
|
|
143
147
|
}, __spreadArray([], byIdDeps, true)), byIdError = _h.error, byIdLoading = _h.loading, byIdFetchNow = _h.fetchNow;
|
|
144
148
|
// delete
|
|
145
149
|
var _j = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
146
150
|
method: constants_1.API_METHODS.DELETE,
|
|
147
151
|
body: JSON.stringify(deleteParams),
|
|
152
|
+
headers: headers,
|
|
148
153
|
callback: function (d) {
|
|
149
154
|
if (deleteCallback) {
|
|
150
155
|
try {
|