@ventlio/tanstack-query 0.1.2 → 0.1.4
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/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/scrollToTop.d.ts +1 -0
- package/dist/helpers/scrollToTop.js +11 -0
- package/dist/helpers/scrollToTop.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -15
- package/dist/index.mjs.map +1 -1
- package/dist/queries/index.d.ts +4 -0
- package/dist/queries/queries.interface.d.ts +11 -0
- package/dist/queries/useDeleteRequest.d.ts +116 -0
- package/dist/queries/useDeleteRequest.js +45 -0
- package/dist/queries/useDeleteRequest.js.map +1 -0
- package/dist/queries/useGetRequest.d.ts +141 -0
- package/dist/queries/useGetRequest.js +104 -0
- package/dist/queries/useGetRequest.js.map +1 -0
- package/dist/queries/usePatchRequest.d.ts +78 -0
- package/dist/queries/usePatchRequest.js +46 -0
- package/dist/queries/usePatchRequest.js.map +1 -0
- package/dist/queries/usePostRequest.d.ts +78 -0
- package/dist/queries/usePostRequest.js +48 -0
- package/dist/queries/usePostRequest.js.map +1 -0
- package/dist/request/buildFormData.d.ts +1 -3
- package/dist/request/buildFormData.js +1 -1
- package/dist/request/make-request.d.ts +1 -1
- package/dist/request/make-request.js +5 -8
- package/dist/request/make-request.js.map +1 -1
- package/dist/request/request.interface.d.ts +2 -2
- package/package.json +5 -8
- package/src/helpers/index.ts +1 -0
- package/src/helpers/scrollToTop.ts +6 -0
- package/src/index.ts +2 -1
- package/src/queries/index.ts +4 -0
- package/src/queries/queries.interface.ts +18 -0
- package/src/queries/useDeleteRequest.ts +52 -0
- package/src/queries/useGetRequest.ts +143 -0
- package/src/queries/usePatchRequest.ts +61 -0
- package/src/queries/usePostRequest.ts +59 -0
- package/src/request/buildFormData.ts +4 -2
- package/src/request/make-request.ts +7 -10
- package/src/request/request.interface.ts +2 -2
- package/dist/useMyHook.d.ts +0 -1
- package/dist/useMyHook.js +0 -14
- package/dist/useMyHook.js.map +0 -1
- package/src/useMyHook.ts +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './scrollToTop';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const scrollToTop: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollToTop.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./constants/index.js');
|
|
4
|
+
var scrollToTop = require('./helpers/scrollToTop.js');
|
|
5
|
+
var useDeleteRequest = require('./queries/useDeleteRequest.js');
|
|
6
|
+
var useGetRequest = require('./queries/useGetRequest.js');
|
|
7
|
+
var usePatchRequest = require('./queries/usePatchRequest.js');
|
|
8
|
+
var usePostRequest = require('./queries/usePostRequest.js');
|
|
4
9
|
var axiosInstance = require('./request/axios-instance.js');
|
|
5
10
|
var buildFormData = require('./request/buildFormData.js');
|
|
6
11
|
var makeRequest = require('./request/make-request.js');
|
|
7
12
|
var request_enum = require('./request/request.enum.js');
|
|
8
13
|
var transformer = require('./request/transformer.js');
|
|
9
|
-
var useMyHook = require('./useMyHook.js');
|
|
10
14
|
|
|
11
15
|
|
|
12
16
|
|
|
13
17
|
exports.API_BASE_URL = index.API_BASE_URL;
|
|
18
|
+
exports.scrollToTop = scrollToTop.scrollToTop;
|
|
19
|
+
exports.useDeleteRequest = useDeleteRequest.useDeleteRequest;
|
|
20
|
+
exports.useGetRequest = useGetRequest.useGetRequest;
|
|
21
|
+
exports.usePatchRequest = usePatchRequest.usePatchRequest;
|
|
22
|
+
exports.usePostRequest = usePostRequest.usePostRequest;
|
|
14
23
|
exports.axiosInstance = axiosInstance.axiosInstance;
|
|
15
24
|
exports.buildFormData = buildFormData.buildFormData;
|
|
16
25
|
exports.makeRequest = makeRequest.makeRequest;
|
|
@@ -24,5 +33,4 @@ Object.defineProperty(exports, 'HttpMethod', {
|
|
|
24
33
|
});
|
|
25
34
|
exports.errorTransformer = transformer.errorTransformer;
|
|
26
35
|
exports.successTransformer = transformer.successTransformer;
|
|
27
|
-
exports.useMyHook = useMyHook.useMyHook;
|
|
28
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useState, startTransition } from 'react';
|
|
1
3
|
import axios from 'axios';
|
|
2
|
-
import { useState } from 'react';
|
|
3
4
|
|
|
4
5
|
const API_BASE_URL = '';
|
|
5
6
|
|
|
7
|
+
const scrollToTop = () => {
|
|
8
|
+
window.scrollTo({
|
|
9
|
+
top: 0,
|
|
10
|
+
behavior: 'smooth',
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
6
14
|
const axiosInstance = (headers) => {
|
|
7
15
|
return axios.create({
|
|
8
16
|
baseURL: 'https://api.ventlio.com',
|
|
@@ -18,7 +26,7 @@ const buildFormData = (body) => {
|
|
|
18
26
|
formData.append(key, body[key]);
|
|
19
27
|
});
|
|
20
28
|
body = formData;
|
|
21
|
-
return
|
|
29
|
+
return body;
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
var HttpMethod;
|
|
@@ -56,25 +64,23 @@ const successTransformer = (data) => {
|
|
|
56
64
|
};
|
|
57
65
|
};
|
|
58
66
|
|
|
59
|
-
async function makeRequest({ body, method = HttpMethod.GET, path, bearerToken,
|
|
60
|
-
// construct api full url
|
|
61
|
-
const apiFullUrl = `${API_BASE_URL}${path}`;
|
|
67
|
+
async function makeRequest({ body, method = HttpMethod.GET, path, bearerToken, isFormData, }) {
|
|
62
68
|
// configure body
|
|
63
|
-
body =
|
|
69
|
+
body = isFormData ? buildFormData(body) : body;
|
|
64
70
|
// configure request header
|
|
65
71
|
const headers = {
|
|
66
72
|
Authorization: `Bearer ${bearerToken}`,
|
|
67
73
|
};
|
|
68
|
-
if (!
|
|
74
|
+
if (!isFormData) {
|
|
69
75
|
headers['Content-Type'] = ContentType.APPLICATION_JSON;
|
|
70
76
|
}
|
|
71
77
|
try {
|
|
72
78
|
const axios = axiosInstance(headers);
|
|
73
79
|
// send request
|
|
74
80
|
const resp = await axios({
|
|
75
|
-
url:
|
|
81
|
+
url: path,
|
|
76
82
|
method,
|
|
77
|
-
data:
|
|
83
|
+
data: body,
|
|
78
84
|
});
|
|
79
85
|
// get response json
|
|
80
86
|
const jsonResp = await resp.data();
|
|
@@ -98,13 +104,207 @@ async function makeRequest({ body, method = HttpMethod.GET, path, bearerToken, f
|
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
const
|
|
102
|
-
const [
|
|
103
|
-
const
|
|
104
|
-
|
|
107
|
+
const useDeleteRequest = () => {
|
|
108
|
+
const [requestPath, updateDeletePath] = useState('');
|
|
109
|
+
const [options, setOptions] = useState();
|
|
110
|
+
const authToken = '';
|
|
111
|
+
const query = useQuery([requestPath, {}], () => new Promise((res, rej) => {
|
|
112
|
+
setTimeout(async () => {
|
|
113
|
+
const postResponse = await makeRequest({
|
|
114
|
+
path: requestPath,
|
|
115
|
+
bearerToken: authToken,
|
|
116
|
+
method: HttpMethod.DELETE,
|
|
117
|
+
});
|
|
118
|
+
if (postResponse.status) {
|
|
119
|
+
res(postResponse);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
rej(postResponse);
|
|
123
|
+
}
|
|
124
|
+
}, 200);
|
|
125
|
+
}), { ...options });
|
|
126
|
+
const updatedPathAsync = async (link) => {
|
|
127
|
+
return updateDeletePath(link);
|
|
128
|
+
};
|
|
129
|
+
const setOptionsAsync = async (fetchOptions) => {
|
|
130
|
+
return setOptions(fetchOptions);
|
|
131
|
+
};
|
|
132
|
+
const deleteR = async (link, fetchOptions) => {
|
|
133
|
+
await updatedPathAsync(link);
|
|
134
|
+
await setOptionsAsync(fetchOptions);
|
|
135
|
+
return query.refetch({
|
|
136
|
+
queryKey: [link, {}],
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
return { updateDeletePath, deleteR, ...query };
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const useGetRequest = ({ path, load = false, queryOptions, }) => {
|
|
143
|
+
const [requestPath, updatePath] = useState(path);
|
|
144
|
+
const authToken = '';
|
|
145
|
+
const [options, setOptions] = useState(queryOptions);
|
|
146
|
+
const [page, setPage] = useState(1);
|
|
147
|
+
const sendRequest = async (res, rej) => {
|
|
148
|
+
const postResponse = await makeRequest({
|
|
149
|
+
path: requestPath,
|
|
150
|
+
bearerToken: authToken,
|
|
151
|
+
});
|
|
152
|
+
if (postResponse.status) {
|
|
153
|
+
res(postResponse);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
rej(postResponse);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const query = useQuery([requestPath, {}], () => new Promise((res, rej) => {
|
|
160
|
+
return sendRequest(res, rej);
|
|
161
|
+
}), {
|
|
162
|
+
enabled: load,
|
|
163
|
+
...options,
|
|
164
|
+
});
|
|
165
|
+
const nextPage = () => {
|
|
166
|
+
if (query.data?.data.pagination) {
|
|
167
|
+
const pagination = query.data.data.pagination;
|
|
168
|
+
if (pagination.next_page !== pagination.current_page &&
|
|
169
|
+
pagination.next_page > pagination.current_page) {
|
|
170
|
+
updatePath(constructPaginationLink(requestPath, pagination.next_page));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const prevPage = () => {
|
|
175
|
+
if (query.data?.data.pagination) {
|
|
176
|
+
const pagination = query.data.data.pagination;
|
|
177
|
+
if (pagination.previous_page !== pagination.current_page &&
|
|
178
|
+
pagination.previous_page < pagination.current_page) {
|
|
179
|
+
updatePath(constructPaginationLink(requestPath, pagination.previous_page));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const constructPaginationLink = (link, pageNumber) => {
|
|
184
|
+
const oldLink = link;
|
|
185
|
+
if (link.includes('?')) {
|
|
186
|
+
if (link.includes('?page=')) {
|
|
187
|
+
// replace current page number with new number
|
|
188
|
+
link = link.replace(/\?page=(\d+)/gim, `?page=${pageNumber}`);
|
|
189
|
+
}
|
|
190
|
+
else if (link.includes('&page=')) {
|
|
191
|
+
link = link.replace(/&page=(\d+)/gim, `&page=${pageNumber}`);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
link = `${link}&page=${pageNumber}`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
link = `${link}?page=${pageNumber}`;
|
|
199
|
+
}
|
|
200
|
+
// only update page when pagination is done
|
|
201
|
+
if (oldLink !== link) {
|
|
202
|
+
setPage(pageNumber);
|
|
203
|
+
}
|
|
204
|
+
return link;
|
|
205
|
+
};
|
|
206
|
+
const gotoPage = (pageNumber) => {
|
|
207
|
+
updatePath(constructPaginationLink(requestPath, pageNumber));
|
|
208
|
+
};
|
|
209
|
+
const updatedPathAsync = async (link) => {
|
|
210
|
+
startTransition(() => {
|
|
211
|
+
updatePath(link);
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
const setOptionsAsync = async (fetchOptions) => {
|
|
215
|
+
startTransition(() => {
|
|
216
|
+
setOptions(fetchOptions);
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
const get = async (link, fetchOptions) => {
|
|
220
|
+
await setOptionsAsync(fetchOptions);
|
|
221
|
+
await updatedPathAsync(link);
|
|
222
|
+
return query.data;
|
|
223
|
+
};
|
|
224
|
+
return {
|
|
225
|
+
...query,
|
|
226
|
+
updatePath,
|
|
227
|
+
nextPage,
|
|
228
|
+
prevPage,
|
|
229
|
+
get,
|
|
230
|
+
gotoPage,
|
|
231
|
+
page,
|
|
232
|
+
queryKey: [requestPath, {}],
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const usePatchRequest = ({ path, isFormData = false, }) => {
|
|
237
|
+
const authToken = '';
|
|
238
|
+
const [resetForm, setResetForm] = useState(false);
|
|
239
|
+
// register post mutation
|
|
240
|
+
const mutation = useMutation((postData) => new Promise((res, rej) => {
|
|
241
|
+
setResetForm(false);
|
|
242
|
+
makeRequest({
|
|
243
|
+
path: path,
|
|
244
|
+
body: postData,
|
|
245
|
+
method: HttpMethod.PATCH,
|
|
246
|
+
bearerToken: authToken,
|
|
247
|
+
isFormData,
|
|
248
|
+
}).then((postResponse) => {
|
|
249
|
+
if (postResponse.status) {
|
|
250
|
+
setResetForm(true);
|
|
251
|
+
// scroll to top after success
|
|
252
|
+
scrollToTop();
|
|
253
|
+
res(postResponse);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// scroll to top after error
|
|
257
|
+
window.scrollTo({
|
|
258
|
+
top: 0,
|
|
259
|
+
behavior: 'smooth',
|
|
260
|
+
});
|
|
261
|
+
rej(postResponse);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}));
|
|
265
|
+
const patch = async (postData, options) => {
|
|
266
|
+
return mutation.mutateAsync(postData, options);
|
|
267
|
+
};
|
|
268
|
+
return { patch, ...mutation, resetForm };
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const usePostRequest = ({ path, isFormData = false, }) => {
|
|
272
|
+
const authToken = '';
|
|
273
|
+
const [resetForm, setResetForm] = useState(false);
|
|
274
|
+
// register post mutation
|
|
275
|
+
const mutation = useMutation(async (postData) => new Promise((res, rej) => {
|
|
276
|
+
setResetForm(false);
|
|
277
|
+
makeRequest({
|
|
278
|
+
path: path,
|
|
279
|
+
body: postData,
|
|
280
|
+
method: HttpMethod.POST,
|
|
281
|
+
bearerToken: authToken,
|
|
282
|
+
isFormData,
|
|
283
|
+
}).then((postResponse) => {
|
|
284
|
+
if (postResponse.status) {
|
|
285
|
+
setResetForm(true);
|
|
286
|
+
// scroll to top after success
|
|
287
|
+
window.scrollTo({
|
|
288
|
+
top: 0,
|
|
289
|
+
behavior: 'smooth',
|
|
290
|
+
});
|
|
291
|
+
res(postResponse);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
// scroll to top after error
|
|
295
|
+
window.scrollTo({
|
|
296
|
+
top: 0,
|
|
297
|
+
behavior: 'smooth',
|
|
298
|
+
});
|
|
299
|
+
rej(postResponse);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}));
|
|
303
|
+
const post = async (postData, options) => {
|
|
304
|
+
return mutation.mutateAsync(postData, options);
|
|
105
305
|
};
|
|
106
|
-
return
|
|
306
|
+
return { post, ...mutation, resetForm };
|
|
107
307
|
};
|
|
108
308
|
|
|
109
|
-
export { API_BASE_URL, ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, makeRequest, successTransformer,
|
|
309
|
+
export { API_BASE_URL, ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useGetRequest, usePatchRequest, usePostRequest };
|
|
110
310
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
3
|
+
export interface IPagination {
|
|
4
|
+
current_page: number;
|
|
5
|
+
next_page: number;
|
|
6
|
+
page_count: number;
|
|
7
|
+
previous_page: number;
|
|
8
|
+
size: number;
|
|
9
|
+
total: number;
|
|
10
|
+
}
|
|
11
|
+
export type TanstackQueryOption<TResponse> = UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, Array<any>>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { MutateOptions, QueryObserverResult } from '@tanstack/react-query';
|
|
3
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
4
|
+
export declare const useDeleteRequest: <TResponse>() => {
|
|
5
|
+
data: IRequestSuccess<TResponse>;
|
|
6
|
+
error: any;
|
|
7
|
+
isError: true;
|
|
8
|
+
isLoading: false;
|
|
9
|
+
isLoadingError: false;
|
|
10
|
+
isRefetchError: true;
|
|
11
|
+
isSuccess: false;
|
|
12
|
+
status: "error";
|
|
13
|
+
dataUpdatedAt: number;
|
|
14
|
+
errorUpdatedAt: number;
|
|
15
|
+
failureCount: number;
|
|
16
|
+
failureReason: any;
|
|
17
|
+
errorUpdateCount: number;
|
|
18
|
+
isFetched: boolean;
|
|
19
|
+
isFetchedAfterMount: boolean;
|
|
20
|
+
isFetching: boolean;
|
|
21
|
+
isInitialLoading: boolean;
|
|
22
|
+
isPaused: boolean;
|
|
23
|
+
isPlaceholderData: boolean;
|
|
24
|
+
isPreviousData: boolean;
|
|
25
|
+
isRefetching: boolean;
|
|
26
|
+
isStale: boolean;
|
|
27
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
28
|
+
remove: () => void;
|
|
29
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
30
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
31
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
32
|
+
} | {
|
|
33
|
+
data: IRequestSuccess<TResponse>;
|
|
34
|
+
error: null;
|
|
35
|
+
isError: false;
|
|
36
|
+
isLoading: false;
|
|
37
|
+
isLoadingError: false;
|
|
38
|
+
isRefetchError: false;
|
|
39
|
+
isSuccess: true;
|
|
40
|
+
status: "success";
|
|
41
|
+
dataUpdatedAt: number;
|
|
42
|
+
errorUpdatedAt: number;
|
|
43
|
+
failureCount: number;
|
|
44
|
+
failureReason: any;
|
|
45
|
+
errorUpdateCount: number;
|
|
46
|
+
isFetched: boolean;
|
|
47
|
+
isFetchedAfterMount: boolean;
|
|
48
|
+
isFetching: boolean;
|
|
49
|
+
isInitialLoading: boolean;
|
|
50
|
+
isPaused: boolean;
|
|
51
|
+
isPlaceholderData: boolean;
|
|
52
|
+
isPreviousData: boolean;
|
|
53
|
+
isRefetching: boolean;
|
|
54
|
+
isStale: boolean;
|
|
55
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
56
|
+
remove: () => void;
|
|
57
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
58
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
59
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
60
|
+
} | {
|
|
61
|
+
data: undefined;
|
|
62
|
+
error: any;
|
|
63
|
+
isError: true;
|
|
64
|
+
isLoading: false;
|
|
65
|
+
isLoadingError: true;
|
|
66
|
+
isRefetchError: false;
|
|
67
|
+
isSuccess: false;
|
|
68
|
+
status: "error";
|
|
69
|
+
dataUpdatedAt: number;
|
|
70
|
+
errorUpdatedAt: number;
|
|
71
|
+
failureCount: number;
|
|
72
|
+
failureReason: any;
|
|
73
|
+
errorUpdateCount: number;
|
|
74
|
+
isFetched: boolean;
|
|
75
|
+
isFetchedAfterMount: boolean;
|
|
76
|
+
isFetching: boolean;
|
|
77
|
+
isInitialLoading: boolean;
|
|
78
|
+
isPaused: boolean;
|
|
79
|
+
isPlaceholderData: boolean;
|
|
80
|
+
isPreviousData: boolean;
|
|
81
|
+
isRefetching: boolean;
|
|
82
|
+
isStale: boolean;
|
|
83
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
84
|
+
remove: () => void;
|
|
85
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
86
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
87
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
88
|
+
} | {
|
|
89
|
+
data: undefined;
|
|
90
|
+
error: null;
|
|
91
|
+
isError: false;
|
|
92
|
+
isLoading: true;
|
|
93
|
+
isLoadingError: false;
|
|
94
|
+
isRefetchError: false;
|
|
95
|
+
isSuccess: false;
|
|
96
|
+
status: "loading";
|
|
97
|
+
dataUpdatedAt: number;
|
|
98
|
+
errorUpdatedAt: number;
|
|
99
|
+
failureCount: number;
|
|
100
|
+
failureReason: any;
|
|
101
|
+
errorUpdateCount: number;
|
|
102
|
+
isFetched: boolean;
|
|
103
|
+
isFetchedAfterMount: boolean;
|
|
104
|
+
isFetching: boolean;
|
|
105
|
+
isInitialLoading: boolean;
|
|
106
|
+
isPaused: boolean;
|
|
107
|
+
isPlaceholderData: boolean;
|
|
108
|
+
isPreviousData: boolean;
|
|
109
|
+
isRefetching: boolean;
|
|
110
|
+
isStale: boolean;
|
|
111
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
112
|
+
remove: () => void;
|
|
113
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
114
|
+
updateDeletePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
115
|
+
deleteR: (link: string, fetchOptions?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
116
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactQuery = require('@tanstack/react-query');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
require('axios');
|
|
6
|
+
var makeRequest = require('../request/make-request.js');
|
|
7
|
+
var request_enum = require('../request/request.enum.js');
|
|
8
|
+
|
|
9
|
+
const useDeleteRequest = () => {
|
|
10
|
+
const [requestPath, updateDeletePath] = react.useState('');
|
|
11
|
+
const [options, setOptions] = react.useState();
|
|
12
|
+
const authToken = '';
|
|
13
|
+
const query = reactQuery.useQuery([requestPath, {}], () => new Promise((res, rej) => {
|
|
14
|
+
setTimeout(async () => {
|
|
15
|
+
const postResponse = await makeRequest.makeRequest({
|
|
16
|
+
path: requestPath,
|
|
17
|
+
bearerToken: authToken,
|
|
18
|
+
method: request_enum.HttpMethod.DELETE,
|
|
19
|
+
});
|
|
20
|
+
if (postResponse.status) {
|
|
21
|
+
res(postResponse);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
rej(postResponse);
|
|
25
|
+
}
|
|
26
|
+
}, 200);
|
|
27
|
+
}), { ...options });
|
|
28
|
+
const updatedPathAsync = async (link) => {
|
|
29
|
+
return updateDeletePath(link);
|
|
30
|
+
};
|
|
31
|
+
const setOptionsAsync = async (fetchOptions) => {
|
|
32
|
+
return setOptions(fetchOptions);
|
|
33
|
+
};
|
|
34
|
+
const deleteR = async (link, fetchOptions) => {
|
|
35
|
+
await updatedPathAsync(link);
|
|
36
|
+
await setOptionsAsync(fetchOptions);
|
|
37
|
+
return query.refetch({
|
|
38
|
+
queryKey: [link, {}],
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return { updateDeletePath, deleteR, ...query };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.useDeleteRequest = useDeleteRequest;
|
|
45
|
+
//# sourceMappingURL=useDeleteRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
3
|
+
import type { IRequestError, IRequestSuccess } from '../request';
|
|
4
|
+
import type { TanstackQueryOption } from './queries.interface';
|
|
5
|
+
export declare const useGetRequest: <TResponse extends Record<string, any>>({ path, load, queryOptions, }: {
|
|
6
|
+
path: string;
|
|
7
|
+
load?: boolean | undefined;
|
|
8
|
+
queryOptions?: TanstackQueryOption<TResponse> | undefined;
|
|
9
|
+
}) => {
|
|
10
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
11
|
+
nextPage: () => void;
|
|
12
|
+
prevPage: () => void;
|
|
13
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
14
|
+
gotoPage: (pageNumber: number) => void;
|
|
15
|
+
page: number;
|
|
16
|
+
queryKey: {}[];
|
|
17
|
+
data: IRequestSuccess<TResponse>;
|
|
18
|
+
error: any;
|
|
19
|
+
isError: true;
|
|
20
|
+
isLoading: false;
|
|
21
|
+
isLoadingError: false;
|
|
22
|
+
isRefetchError: true;
|
|
23
|
+
isSuccess: false;
|
|
24
|
+
status: "error";
|
|
25
|
+
dataUpdatedAt: number;
|
|
26
|
+
errorUpdatedAt: number;
|
|
27
|
+
failureCount: number;
|
|
28
|
+
failureReason: any;
|
|
29
|
+
errorUpdateCount: number;
|
|
30
|
+
isFetched: boolean;
|
|
31
|
+
isFetchedAfterMount: boolean;
|
|
32
|
+
isFetching: boolean;
|
|
33
|
+
isInitialLoading: boolean;
|
|
34
|
+
isPaused: boolean;
|
|
35
|
+
isPlaceholderData: boolean;
|
|
36
|
+
isPreviousData: boolean;
|
|
37
|
+
isRefetching: boolean;
|
|
38
|
+
isStale: boolean;
|
|
39
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
40
|
+
remove: () => void;
|
|
41
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
42
|
+
} | {
|
|
43
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
44
|
+
nextPage: () => void;
|
|
45
|
+
prevPage: () => void;
|
|
46
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
47
|
+
gotoPage: (pageNumber: number) => void;
|
|
48
|
+
page: number;
|
|
49
|
+
queryKey: {}[];
|
|
50
|
+
data: IRequestSuccess<TResponse>;
|
|
51
|
+
error: null;
|
|
52
|
+
isError: false;
|
|
53
|
+
isLoading: false;
|
|
54
|
+
isLoadingError: false;
|
|
55
|
+
isRefetchError: false;
|
|
56
|
+
isSuccess: true;
|
|
57
|
+
status: "success";
|
|
58
|
+
dataUpdatedAt: number;
|
|
59
|
+
errorUpdatedAt: number;
|
|
60
|
+
failureCount: number;
|
|
61
|
+
failureReason: any;
|
|
62
|
+
errorUpdateCount: number;
|
|
63
|
+
isFetched: boolean;
|
|
64
|
+
isFetchedAfterMount: boolean;
|
|
65
|
+
isFetching: boolean;
|
|
66
|
+
isInitialLoading: boolean;
|
|
67
|
+
isPaused: boolean;
|
|
68
|
+
isPlaceholderData: boolean;
|
|
69
|
+
isPreviousData: boolean;
|
|
70
|
+
isRefetching: boolean;
|
|
71
|
+
isStale: boolean;
|
|
72
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
73
|
+
remove: () => void;
|
|
74
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
75
|
+
} | {
|
|
76
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
77
|
+
nextPage: () => void;
|
|
78
|
+
prevPage: () => void;
|
|
79
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
80
|
+
gotoPage: (pageNumber: number) => void;
|
|
81
|
+
page: number;
|
|
82
|
+
queryKey: {}[];
|
|
83
|
+
data: undefined;
|
|
84
|
+
error: any;
|
|
85
|
+
isError: true;
|
|
86
|
+
isLoading: false;
|
|
87
|
+
isLoadingError: true;
|
|
88
|
+
isRefetchError: false;
|
|
89
|
+
isSuccess: false;
|
|
90
|
+
status: "error";
|
|
91
|
+
dataUpdatedAt: number;
|
|
92
|
+
errorUpdatedAt: number;
|
|
93
|
+
failureCount: number;
|
|
94
|
+
failureReason: any;
|
|
95
|
+
errorUpdateCount: number;
|
|
96
|
+
isFetched: boolean;
|
|
97
|
+
isFetchedAfterMount: boolean;
|
|
98
|
+
isFetching: boolean;
|
|
99
|
+
isInitialLoading: boolean;
|
|
100
|
+
isPaused: boolean;
|
|
101
|
+
isPlaceholderData: boolean;
|
|
102
|
+
isPreviousData: boolean;
|
|
103
|
+
isRefetching: boolean;
|
|
104
|
+
isStale: boolean;
|
|
105
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
106
|
+
remove: () => void;
|
|
107
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
108
|
+
} | {
|
|
109
|
+
updatePath: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
110
|
+
nextPage: () => void;
|
|
111
|
+
prevPage: () => void;
|
|
112
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
113
|
+
gotoPage: (pageNumber: number) => void;
|
|
114
|
+
page: number;
|
|
115
|
+
queryKey: {}[];
|
|
116
|
+
data: undefined;
|
|
117
|
+
error: null;
|
|
118
|
+
isError: false;
|
|
119
|
+
isLoading: true;
|
|
120
|
+
isLoadingError: false;
|
|
121
|
+
isRefetchError: false;
|
|
122
|
+
isSuccess: false;
|
|
123
|
+
status: "loading";
|
|
124
|
+
dataUpdatedAt: number;
|
|
125
|
+
errorUpdatedAt: number;
|
|
126
|
+
failureCount: number;
|
|
127
|
+
failureReason: any;
|
|
128
|
+
errorUpdateCount: number;
|
|
129
|
+
isFetched: boolean;
|
|
130
|
+
isFetchedAfterMount: boolean;
|
|
131
|
+
isFetching: boolean;
|
|
132
|
+
isInitialLoading: boolean;
|
|
133
|
+
isPaused: boolean;
|
|
134
|
+
isPlaceholderData: boolean;
|
|
135
|
+
isPreviousData: boolean;
|
|
136
|
+
isRefetching: boolean;
|
|
137
|
+
isStale: boolean;
|
|
138
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
139
|
+
remove: () => void;
|
|
140
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
141
|
+
};
|