@react-pakistan/util-functions 1.23.92 → 1.23.94
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/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/use-module-entity.d.ts +35 -0
- package/hooks/use-module-entity.js +50 -0
- package/package.json +1 -1
package/hooks/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './use-fetch';
|
|
|
4
4
|
export * from './use-force-render';
|
|
5
5
|
export * from './use-ip-geo-location';
|
|
6
6
|
export * from './use-is-mobile';
|
|
7
|
+
export * from './use-module-entity';
|
|
7
8
|
export * from './use-position';
|
|
8
9
|
export * from './use-sticky';
|
|
9
10
|
export * from './use-toggle-state';
|
package/hooks/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./use-fetch"), exports);
|
|
|
20
20
|
__exportStar(require("./use-force-render"), exports);
|
|
21
21
|
__exportStar(require("./use-ip-geo-location"), exports);
|
|
22
22
|
__exportStar(require("./use-is-mobile"), exports);
|
|
23
|
+
__exportStar(require("./use-module-entity"), exports);
|
|
23
24
|
__exportStar(require("./use-position"), exports);
|
|
24
25
|
__exportStar(require("./use-sticky"), exports);
|
|
25
26
|
__exportStar(require("./use-toggle-state"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FetchConfig } from './use-fetch';
|
|
2
|
+
export interface CallbackParams {
|
|
3
|
+
data: any;
|
|
4
|
+
error: any;
|
|
5
|
+
}
|
|
6
|
+
interface Params {
|
|
7
|
+
byIdCallback: (d: CallbackParams) => void;
|
|
8
|
+
byIdParams: object;
|
|
9
|
+
deleteCallback: (d: CallbackParams) => void;
|
|
10
|
+
deleteParams: object;
|
|
11
|
+
listCallback: (d: CallbackParams) => void;
|
|
12
|
+
listParams: object;
|
|
13
|
+
listUrl: string;
|
|
14
|
+
unitByIdUrl: string;
|
|
15
|
+
unitUrl: string;
|
|
16
|
+
updateCallback: (d: CallbackParams) => void;
|
|
17
|
+
updateParams: object;
|
|
18
|
+
searchQuery: string;
|
|
19
|
+
}
|
|
20
|
+
interface Return {
|
|
21
|
+
byIdError: Error;
|
|
22
|
+
byIdFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
23
|
+
byIdLoading: boolean;
|
|
24
|
+
deleteError: Error;
|
|
25
|
+
deleteFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
26
|
+
deleteLoading: boolean;
|
|
27
|
+
listError: Error;
|
|
28
|
+
listFetchNow: () => void;
|
|
29
|
+
listLoading: boolean;
|
|
30
|
+
updateError: Error;
|
|
31
|
+
updateFetchNow: () => void;
|
|
32
|
+
updateLoading: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const useModuleEntity: ({ byIdCallback, byIdParams, deleteCallback, deleteParams, listCallback, listParams, listUrl, unitByIdUrl, unitUrl, updateCallback, updateParams, searchQuery, }: Params) => Return;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useModuleEntity = void 0;
|
|
5
|
+
var constants_1 = require("../constants");
|
|
6
|
+
var use_fetch_1 = require("./use-fetch");
|
|
7
|
+
var use_debounce_1 = require("./use-debounce");
|
|
8
|
+
var useModuleEntity = function (_a) {
|
|
9
|
+
var byIdCallback = _a.byIdCallback, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, deleteParams = _a.deleteParams, listCallback = _a.listCallback, listParams = _a.listParams, listUrl = _a.listUrl, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, updateParams = _a.updateParams, searchQuery = _a.searchQuery;
|
|
10
|
+
var debouncedQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
|
|
11
|
+
// list
|
|
12
|
+
var _b = (0, use_fetch_1.useFetch)(listUrl, {
|
|
13
|
+
method: constants_1.API_METHODS.POST,
|
|
14
|
+
body: JSON.stringify(listParams),
|
|
15
|
+
callback: listCallback,
|
|
16
|
+
}, [debouncedQuery]), listError = _b.error, listFetchNow = _b.fetchNow, listLoading = _b.loading;
|
|
17
|
+
// create / edit
|
|
18
|
+
var _c = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
19
|
+
method: constants_1.API_METHODS.POST,
|
|
20
|
+
body: JSON.stringify(updateParams),
|
|
21
|
+
callback: updateCallback,
|
|
22
|
+
}), updateError = _c.error, updateLoading = _c.loading, updateFetchNow = _c.fetchNow;
|
|
23
|
+
// by id
|
|
24
|
+
var _d = (0, use_fetch_1.useFetch)(unitByIdUrl, {
|
|
25
|
+
method: constants_1.API_METHODS.POST,
|
|
26
|
+
body: JSON.stringify(byIdParams),
|
|
27
|
+
callback: byIdCallback,
|
|
28
|
+
}), byIdError = _d.error, byIdLoading = _d.loading, byIdFetchNow = _d.fetchNow;
|
|
29
|
+
// delete
|
|
30
|
+
var _e = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
31
|
+
method: constants_1.API_METHODS.DELETE,
|
|
32
|
+
body: JSON.stringify(deleteParams),
|
|
33
|
+
callback: deleteCallback,
|
|
34
|
+
}), deleteError = _e.error, deleteLoading = _e.loading, deleteFetchNow = _e.fetchNow;
|
|
35
|
+
return {
|
|
36
|
+
byIdError: byIdError,
|
|
37
|
+
byIdFetchNow: byIdFetchNow,
|
|
38
|
+
byIdLoading: byIdLoading,
|
|
39
|
+
deleteError: deleteError,
|
|
40
|
+
deleteFetchNow: deleteFetchNow,
|
|
41
|
+
deleteLoading: deleteLoading,
|
|
42
|
+
listError: listError,
|
|
43
|
+
listFetchNow: listFetchNow,
|
|
44
|
+
listLoading: listLoading,
|
|
45
|
+
updateError: updateError,
|
|
46
|
+
updateFetchNow: updateFetchNow,
|
|
47
|
+
updateLoading: updateLoading,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.useModuleEntity = useModuleEntity;
|