fastapi-rtk 0.2.8 → 0.2.9
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/core/cjs/Tables/DataGrid/Toolbar/Filter/FilterMenu.cjs +1 -1
- package/dist/core/cjs/Wrappers/ApiProvider/hooks/useProvideApi.cjs +8 -8
- package/dist/core/cjs/Wrappers/ApiProvider/hooks/useProvideBulk.cjs +4 -7
- package/dist/core/cjs/Wrappers/Provider/hooks/useProvideAuth.cjs +12 -10
- package/dist/core/cjs/fab-react-toolkit-patch/api/hooks/useProvideApi.cjs +8 -8
- package/dist/core/cjs/fab-react-toolkit-patch/api/hooks/useProvideBulk.cjs +4 -7
- package/dist/core/cjs/fab-react-toolkit-patch/auth/hooks/useProvideAuth.cjs +12 -10
- package/dist/core/esm/Tables/DataGrid/Toolbar/Filter/FilterMenu.mjs +1 -1
- package/dist/core/esm/Wrappers/ApiProvider/hooks/useProvideApi.mjs +8 -8
- package/dist/core/esm/Wrappers/ApiProvider/hooks/useProvideBulk.mjs +4 -7
- package/dist/core/esm/Wrappers/Provider/hooks/useProvideAuth.mjs +12 -10
- package/dist/core/esm/fab-react-toolkit-patch/api/hooks/useProvideApi.mjs +8 -8
- package/dist/core/esm/fab-react-toolkit-patch/api/hooks/useProvideBulk.mjs +4 -7
- package/dist/core/esm/fab-react-toolkit-patch/auth/hooks/useProvideAuth.mjs +12 -10
- package/dist/core/lib/Wrappers/ApiProvider/hooks/useProvideApi.d.ts +1 -1
- package/dist/core/lib/Wrappers/ApiProvider/hooks/useProvideBulk.d.ts +1 -0
- package/dist/core/lib/Wrappers/Provider/hooks/useProvideAuth.d.ts +1 -0
- package/dist/core/lib/fab-react-toolkit-patch/api/hooks/useProvideApi.d.ts +1 -1
- package/dist/core/lib/fab-react-toolkit-patch/api/hooks/useProvideBulk.d.ts +1 -0
- package/dist/core/lib/fab-react-toolkit-patch/auth/hooks/useProvideAuth.d.ts +1 -0
- package/dist/core/lib/hooks/api/useBulkActions.d.ts +15 -1
- package/dist/core/lib/hooks/auth/useAuth.d.ts +4 -0
- package/dist/hooks/cjs/useCustomFetch/useCustomFetch.cjs +4 -3
- package/dist/hooks/esm/useCustomFetch/useCustomFetch.mjs +5 -4
- package/dist/hooks/lib/useCustomFetch/useCustomFetch.d.ts +2 -1
- package/package.json +1 -1
- /package/dist/.external/cjs/{mantine-form-yup-resolver@2.0.0_@mantine_form@8.1.3_yup@1.6.1 → mantine-form-yup-resolver@2.0.0_@mantine_form@8.2.1_yup@1.6.1}/mantine-form-yup-resolver/dist/esm/index.cjs +0 -0
- /package/dist/.external/esm/{mantine-form-yup-resolver@2.0.0_@mantine_form@8.1.3_yup@1.6.1 → mantine-form-yup-resolver@2.0.0_@mantine_form@8.2.1_yup@1.6.1}/mantine-form-yup-resolver/dist/esm/index.mjs +0 -0
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const core = require("@mantine/core");
|
|
5
5
|
const form = require("@mantine/form");
|
|
6
6
|
const hooks = require("@mantine/hooks");
|
|
7
|
-
const index = require("../../../../../../.external/cjs/mantine-form-yup-resolver@2.0.0_@mantine_form@8.
|
|
7
|
+
const index = require("../../../../../../.external/cjs/mantine-form-yup-resolver@2.0.0_@mantine_form@8.2.1_yup@1.6.1/mantine-form-yup-resolver/dist/esm/index.cjs");
|
|
8
8
|
const React = require("react");
|
|
9
9
|
const index_esm = require("../../../../../../.external/cjs/yup@1.6.1/yup/index.esm.cjs");
|
|
10
10
|
const useApi = require("../../../../hooks/api/useApi.cjs");
|
|
@@ -85,9 +85,9 @@ function useProvideApi({
|
|
|
85
85
|
}),
|
|
86
86
|
[streamingMode]
|
|
87
87
|
);
|
|
88
|
-
const [error, setError] = React.useState(
|
|
88
|
+
const [error, setError] = React.useState();
|
|
89
89
|
const memoizedError = React.useMemo(() => error, [error]);
|
|
90
|
-
const resetError = React.useCallback(() => setError(
|
|
90
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
91
91
|
const {
|
|
92
92
|
data: info,
|
|
93
93
|
isFetching: infoLoading,
|
|
@@ -150,8 +150,8 @@ function useProvideApi({
|
|
|
150
150
|
const getEntry = React.useCallback(
|
|
151
151
|
async (id) => {
|
|
152
152
|
try {
|
|
153
|
-
const response = await getItem.getItem(pathRef.current, convertId.convertId(id));
|
|
154
153
|
resetError();
|
|
154
|
+
const response = await getItem.getItem(pathRef.current, convertId.convertId(id));
|
|
155
155
|
return response;
|
|
156
156
|
} catch (error2) {
|
|
157
157
|
setError({ message: `Couldn't fetch item with id ${id}`, originalError: error2 });
|
|
@@ -166,9 +166,9 @@ function useProvideApi({
|
|
|
166
166
|
async (item) => {
|
|
167
167
|
var _a;
|
|
168
168
|
try {
|
|
169
|
+
resetError();
|
|
169
170
|
const func = ((_a = infoRef.current) == null ? void 0 : _a.add_type) === "form" ? formCreateItem.formCreateItem : createItem.createItem;
|
|
170
171
|
const response = await func(pathRef.current, item);
|
|
171
|
-
resetError();
|
|
172
172
|
return response;
|
|
173
173
|
} catch (error2) {
|
|
174
174
|
setError({ message: `Couldn't add item`, originalError: error2 });
|
|
@@ -183,9 +183,9 @@ function useProvideApi({
|
|
|
183
183
|
async (id, item) => {
|
|
184
184
|
var _a;
|
|
185
185
|
try {
|
|
186
|
+
resetError();
|
|
186
187
|
const func = ((_a = infoRef.current) == null ? void 0 : _a.edit_type) === "form" ? formUpdateItem.formUpdateItem : updateItem.updateItem;
|
|
187
188
|
const response = await func(pathRef.current, convertId.convertId(id), item);
|
|
188
|
-
resetError();
|
|
189
189
|
return response;
|
|
190
190
|
} catch (error2) {
|
|
191
191
|
setError({ message: `Couldn't update item with id ${id}`, originalError: error2 });
|
|
@@ -199,8 +199,8 @@ function useProvideApi({
|
|
|
199
199
|
const deleteEntry = React.useCallback(
|
|
200
200
|
async (id) => {
|
|
201
201
|
try {
|
|
202
|
-
const response = await deleteItem.deleteItem(pathRef.current, convertId.convertId(id));
|
|
203
202
|
resetError();
|
|
203
|
+
const response = await deleteItem.deleteItem(pathRef.current, convertId.convertId(id));
|
|
204
204
|
return response;
|
|
205
205
|
} catch (error2) {
|
|
206
206
|
setError({ message: `Couldn't delete item with id ${id}`, originalError: error2 });
|
|
@@ -214,8 +214,8 @@ function useProvideApi({
|
|
|
214
214
|
const download = React.useCallback(
|
|
215
215
|
async (label, { export_mode, delimiter, quotechar } = {}) => {
|
|
216
216
|
try {
|
|
217
|
-
await downloadItems.downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
218
217
|
resetError();
|
|
218
|
+
await downloadItems.downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
219
219
|
} catch (error2) {
|
|
220
220
|
setError({ message: `Couldn't download`, originalError: error2 });
|
|
221
221
|
if (throwOnError) {
|
|
@@ -228,8 +228,8 @@ function useProvideApi({
|
|
|
228
228
|
const upload = React.useCallback(
|
|
229
229
|
async (file, { delimiter, quotechar } = {}) => {
|
|
230
230
|
try {
|
|
231
|
-
const response = await uploadItems.uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
232
231
|
resetError();
|
|
232
|
+
const response = await uploadItems.uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
233
233
|
return response;
|
|
234
234
|
} catch (error2) {
|
|
235
235
|
setError({ message: `Couldn't upload`, originalError: error2 });
|
|
@@ -5,26 +5,23 @@ const postBulkAction = require("../utils/bulkActions/postBulkAction.cjs");
|
|
|
5
5
|
const useProvideBulk = ({ path }) => {
|
|
6
6
|
const [selectedIds, setSelectedIds] = React.useState([]);
|
|
7
7
|
const [error, setError] = React.useState();
|
|
8
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
8
9
|
const dispatchBulkActions = React.useCallback(
|
|
9
10
|
async (handler, data) => {
|
|
10
11
|
try {
|
|
12
|
+
resetError();
|
|
11
13
|
if (data === void 0) {
|
|
12
14
|
data = selectedIds;
|
|
13
15
|
}
|
|
14
16
|
const response = await postBulkAction.postBulk(path, handler, data);
|
|
15
|
-
setError(void 0);
|
|
16
17
|
return response;
|
|
17
18
|
} catch (error2) {
|
|
18
19
|
setError({ message: `Couldn't perform bulk action`, originalError: error2 });
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
|
-
[path, selectedIds]
|
|
22
|
+
[path, resetError, selectedIds]
|
|
22
23
|
);
|
|
23
24
|
const bulkActions = React.useMemo(() => ({ selectedIds, setSelectedIds }), [selectedIds, setSelectedIds]);
|
|
24
|
-
return {
|
|
25
|
-
bulkActions,
|
|
26
|
-
dispatchBulkActions,
|
|
27
|
-
error
|
|
28
|
-
};
|
|
25
|
+
return { bulkActions, dispatchBulkActions, error, resetError };
|
|
29
26
|
};
|
|
30
27
|
exports.useProvideBulk = useProvideBulk;
|
|
@@ -13,31 +13,32 @@ function useProvideAuth(baseURL, authQueryProps) {
|
|
|
13
13
|
retry: false,
|
|
14
14
|
...authQueryProps
|
|
15
15
|
});
|
|
16
|
-
const [error, setError] = React.useState(
|
|
16
|
+
const [error, setError] = React.useState();
|
|
17
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
17
18
|
const signin = React.useCallback(
|
|
18
19
|
({ username, password }) => {
|
|
19
|
-
|
|
20
|
+
resetError();
|
|
20
21
|
authFetch.authSignin(baseURL, { username, password }).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
21
22
|
},
|
|
22
|
-
[baseURL, queryClient]
|
|
23
|
+
[baseURL, queryClient, resetError]
|
|
23
24
|
);
|
|
24
25
|
const signout = React.useCallback(() => {
|
|
25
|
-
|
|
26
|
+
resetError();
|
|
26
27
|
authFetch.authSignout(baseURL).then(() => queryClient.resetQueries({ queryKey: ["user"] })).then(() => queryClient.resetQueries({ queryKey: ["info"] })).catch((err) => setError(err));
|
|
27
|
-
}, [baseURL, queryClient]);
|
|
28
|
+
}, [baseURL, queryClient, resetError]);
|
|
28
29
|
const update = React.useCallback(
|
|
29
30
|
(data) => {
|
|
30
|
-
|
|
31
|
+
resetError();
|
|
31
32
|
userCRUD.updateUser(baseURL, data).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
32
33
|
},
|
|
33
|
-
[baseURL, queryClient]
|
|
34
|
+
[baseURL, queryClient, resetError]
|
|
34
35
|
);
|
|
35
36
|
const resetPassword = React.useCallback(
|
|
36
37
|
(password) => {
|
|
37
|
-
|
|
38
|
+
resetError();
|
|
38
39
|
authFetch.authResetPassword(baseURL, password, query.data).catch((err) => setError(err));
|
|
39
40
|
},
|
|
40
|
-
[baseURL, query.data]
|
|
41
|
+
[baseURL, query.data, resetError]
|
|
41
42
|
);
|
|
42
43
|
const oauth_signin = React.useCallback(
|
|
43
44
|
(provider, popup) => authFetch.authOAuthSignin(baseURL, provider, popup, () => queryClient.invalidateQueries({ queryKey: ["user"] })),
|
|
@@ -52,7 +53,8 @@ function useProvideAuth(baseURL, authQueryProps) {
|
|
|
52
53
|
update,
|
|
53
54
|
resetPassword,
|
|
54
55
|
oauth_signin,
|
|
55
|
-
refetch: query.refetch
|
|
56
|
+
refetch: query.refetch,
|
|
57
|
+
resetError
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
exports.useProvideAuth = useProvideAuth;
|
|
@@ -83,9 +83,9 @@ function useFabProvideApi({
|
|
|
83
83
|
}),
|
|
84
84
|
[streamingMode]
|
|
85
85
|
);
|
|
86
|
-
const [error, setError] = React.useState(
|
|
86
|
+
const [error, setError] = React.useState();
|
|
87
87
|
const memoizedError = React.useMemo(() => error, [error]);
|
|
88
|
-
const resetError = React.useCallback(() => setError(
|
|
88
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
89
89
|
const {
|
|
90
90
|
data: info,
|
|
91
91
|
isFetching: infoLoading,
|
|
@@ -144,8 +144,8 @@ function useFabProvideApi({
|
|
|
144
144
|
const getEntry = React.useCallback(
|
|
145
145
|
async (id) => {
|
|
146
146
|
try {
|
|
147
|
-
const response = await getItem.getItem(pathRef.current, convertId.convertId(id));
|
|
148
147
|
resetError();
|
|
148
|
+
const response = await getItem.getItem(pathRef.current, convertId.convertId(id));
|
|
149
149
|
return response;
|
|
150
150
|
} catch (error2) {
|
|
151
151
|
setError({ message: `Couldn't fetch item with id ${id}`, originalError: error2 });
|
|
@@ -159,8 +159,8 @@ function useFabProvideApi({
|
|
|
159
159
|
const addEntry = React.useCallback(
|
|
160
160
|
async (item) => {
|
|
161
161
|
try {
|
|
162
|
-
const response = await createItem.createItem(pathRef.current, item);
|
|
163
162
|
resetError();
|
|
163
|
+
const response = await createItem.createItem(pathRef.current, item);
|
|
164
164
|
return response;
|
|
165
165
|
} catch (error2) {
|
|
166
166
|
setError({ message: `Couldn't add item`, originalError: error2 });
|
|
@@ -174,8 +174,8 @@ function useFabProvideApi({
|
|
|
174
174
|
const updateEntry = React.useCallback(
|
|
175
175
|
async (id, item) => {
|
|
176
176
|
try {
|
|
177
|
-
const response = await updateItem.updateItem(pathRef.current, convertId.convertId(id), item);
|
|
178
177
|
resetError();
|
|
178
|
+
const response = await updateItem.updateItem(pathRef.current, convertId.convertId(id), item);
|
|
179
179
|
return response;
|
|
180
180
|
} catch (error2) {
|
|
181
181
|
setError({ message: `Couldn't update item with id ${id}`, originalError: error2 });
|
|
@@ -189,8 +189,8 @@ function useFabProvideApi({
|
|
|
189
189
|
const deleteEntry = React.useCallback(
|
|
190
190
|
async (id) => {
|
|
191
191
|
try {
|
|
192
|
-
const response = await deleteItem.deleteItem(pathRef.current, convertId.convertId(id));
|
|
193
192
|
resetError();
|
|
193
|
+
const response = await deleteItem.deleteItem(pathRef.current, convertId.convertId(id));
|
|
194
194
|
return response;
|
|
195
195
|
} catch (error2) {
|
|
196
196
|
setError({ message: `Couldn't delete item with id ${id}`, originalError: error2 });
|
|
@@ -204,8 +204,8 @@ function useFabProvideApi({
|
|
|
204
204
|
const download = React.useCallback(
|
|
205
205
|
async (label, { export_mode, delimiter, quotechar } = {}) => {
|
|
206
206
|
try {
|
|
207
|
-
await downloadItems.downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
208
207
|
resetError();
|
|
208
|
+
await downloadItems.downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
209
209
|
} catch (error2) {
|
|
210
210
|
setError({ message: `Couldn't download`, originalError: error2 });
|
|
211
211
|
if (throwOnError) {
|
|
@@ -218,8 +218,8 @@ function useFabProvideApi({
|
|
|
218
218
|
const upload = React.useCallback(
|
|
219
219
|
async (file, { delimiter, quotechar } = {}) => {
|
|
220
220
|
try {
|
|
221
|
-
const response = await uploadItems.uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
222
221
|
resetError();
|
|
222
|
+
const response = await uploadItems.uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
223
223
|
return response;
|
|
224
224
|
} catch (error2) {
|
|
225
225
|
setError({ message: `Couldn't upload`, originalError: error2 });
|
|
@@ -5,26 +5,23 @@ const postBulkAction = require("../utils/bulkActions/postBulkAction.cjs");
|
|
|
5
5
|
const useFabProvideBulk = ({ path }) => {
|
|
6
6
|
const [selectedIds, setSelectedIds] = React.useState([]);
|
|
7
7
|
const [error, setError] = React.useState();
|
|
8
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
8
9
|
const dispatchBulkActions = React.useCallback(
|
|
9
10
|
async (handler, data) => {
|
|
10
11
|
try {
|
|
12
|
+
resetError();
|
|
11
13
|
if (data === void 0) {
|
|
12
14
|
data = selectedIds;
|
|
13
15
|
}
|
|
14
16
|
const response = await postBulkAction.postBulk(path, handler, data);
|
|
15
|
-
setError(void 0);
|
|
16
17
|
return response;
|
|
17
18
|
} catch (error2) {
|
|
18
19
|
setError({ message: `Couldn't perform bulk action`, originalError: error2 });
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
|
-
[path, selectedIds]
|
|
22
|
+
[path, resetError, selectedIds]
|
|
22
23
|
);
|
|
23
24
|
const bulkActions = React.useMemo(() => ({ selectedIds, setSelectedIds }), [selectedIds, setSelectedIds]);
|
|
24
|
-
return {
|
|
25
|
-
bulkActions,
|
|
26
|
-
dispatchBulkActions,
|
|
27
|
-
error
|
|
28
|
-
};
|
|
25
|
+
return { bulkActions, dispatchBulkActions, error, resetError };
|
|
29
26
|
};
|
|
30
27
|
exports.useFabProvideBulk = useFabProvideBulk;
|
|
@@ -13,31 +13,32 @@ function useFabProvideAuth(baseURL, authQueryProps) {
|
|
|
13
13
|
retry: false,
|
|
14
14
|
...authQueryProps
|
|
15
15
|
});
|
|
16
|
-
const [error, setError] = React.useState(
|
|
16
|
+
const [error, setError] = React.useState();
|
|
17
|
+
const resetError = React.useCallback(() => setError(void 0), []);
|
|
17
18
|
const signin = React.useCallback(
|
|
18
19
|
({ username, password }) => {
|
|
19
|
-
|
|
20
|
+
resetError();
|
|
20
21
|
authFetch.authSignin(baseURL, { username, password }).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
21
22
|
},
|
|
22
|
-
[baseURL, queryClient]
|
|
23
|
+
[baseURL, queryClient, resetError]
|
|
23
24
|
);
|
|
24
25
|
const signout = React.useCallback(() => {
|
|
25
|
-
|
|
26
|
+
resetError();
|
|
26
27
|
authFetch.authSignout(baseURL).then(() => queryClient.resetQueries({ queryKey: ["user"] })).then(() => queryClient.resetQueries({ queryKey: ["info"] })).catch((err) => setError(err));
|
|
27
|
-
}, [baseURL, queryClient]);
|
|
28
|
+
}, [baseURL, queryClient, resetError]);
|
|
28
29
|
const update = React.useCallback(
|
|
29
30
|
(data) => {
|
|
30
|
-
|
|
31
|
+
resetError();
|
|
31
32
|
userCRUD.updateUser(baseURL, data).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
32
33
|
},
|
|
33
|
-
[baseURL, queryClient]
|
|
34
|
+
[baseURL, queryClient, resetError]
|
|
34
35
|
);
|
|
35
36
|
const resetPassword = React.useCallback(
|
|
36
37
|
(password) => {
|
|
37
|
-
|
|
38
|
+
resetError();
|
|
38
39
|
authFetch.authResetPassword(baseURL, password, query.data).catch((err) => setError(err));
|
|
39
40
|
},
|
|
40
|
-
[baseURL, query.data]
|
|
41
|
+
[baseURL, query.data, resetError]
|
|
41
42
|
);
|
|
42
43
|
const oauth_signin = React.useCallback(
|
|
43
44
|
(provider, popup) => authFetch.authOAuthSignin(baseURL, provider, popup, () => queryClient.invalidateQueries({ queryKey: ["user"] })),
|
|
@@ -52,7 +53,8 @@ function useFabProvideAuth(baseURL, authQueryProps) {
|
|
|
52
53
|
update,
|
|
53
54
|
resetPassword,
|
|
54
55
|
oauth_signin,
|
|
55
|
-
refetch: query.refetch
|
|
56
|
+
refetch: query.refetch,
|
|
57
|
+
resetError
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
exports.useFabProvideAuth = useFabProvideAuth;
|
|
@@ -2,7 +2,7 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useProps, Box, Flex, ActionIcon, Divider, Text, ScrollArea, Button, Group } from "@mantine/core";
|
|
3
3
|
import { useForm } from "@mantine/form";
|
|
4
4
|
import { randomId } from "@mantine/hooks";
|
|
5
|
-
import { yupResolver } from "../../../../../../.external/esm/mantine-form-yup-resolver@2.0.0_@mantine_form@8.
|
|
5
|
+
import { yupResolver } from "../../../../../../.external/esm/mantine-form-yup-resolver@2.0.0_@mantine_form@8.2.1_yup@1.6.1/mantine-form-yup-resolver/dist/esm/index.mjs";
|
|
6
6
|
import { useEffect } from "react";
|
|
7
7
|
import { object as create$3, array as create$2, mixed as create$8, string as create$6 } from "../../../../../../.external/esm/yup@1.6.1/yup/index.esm.mjs";
|
|
8
8
|
import { useApi } from "../../../../hooks/api/useApi.mjs";
|
|
@@ -83,9 +83,9 @@ function useProvideApi({
|
|
|
83
83
|
}),
|
|
84
84
|
[streamingMode]
|
|
85
85
|
);
|
|
86
|
-
const [error, setError] = useState(
|
|
86
|
+
const [error, setError] = useState();
|
|
87
87
|
const memoizedError = useMemo(() => error, [error]);
|
|
88
|
-
const resetError = useCallback(() => setError(
|
|
88
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
89
89
|
const {
|
|
90
90
|
data: info,
|
|
91
91
|
isFetching: infoLoading,
|
|
@@ -148,8 +148,8 @@ function useProvideApi({
|
|
|
148
148
|
const getEntry = useCallback(
|
|
149
149
|
async (id) => {
|
|
150
150
|
try {
|
|
151
|
-
const response = await getItem(pathRef.current, convertId(id));
|
|
152
151
|
resetError();
|
|
152
|
+
const response = await getItem(pathRef.current, convertId(id));
|
|
153
153
|
return response;
|
|
154
154
|
} catch (error2) {
|
|
155
155
|
setError({ message: `Couldn't fetch item with id ${id}`, originalError: error2 });
|
|
@@ -164,9 +164,9 @@ function useProvideApi({
|
|
|
164
164
|
async (item) => {
|
|
165
165
|
var _a;
|
|
166
166
|
try {
|
|
167
|
+
resetError();
|
|
167
168
|
const func = ((_a = infoRef.current) == null ? void 0 : _a.add_type) === "form" ? formCreateItem : createItem;
|
|
168
169
|
const response = await func(pathRef.current, item);
|
|
169
|
-
resetError();
|
|
170
170
|
return response;
|
|
171
171
|
} catch (error2) {
|
|
172
172
|
setError({ message: `Couldn't add item`, originalError: error2 });
|
|
@@ -181,9 +181,9 @@ function useProvideApi({
|
|
|
181
181
|
async (id, item) => {
|
|
182
182
|
var _a;
|
|
183
183
|
try {
|
|
184
|
+
resetError();
|
|
184
185
|
const func = ((_a = infoRef.current) == null ? void 0 : _a.edit_type) === "form" ? formUpdateItem : updateItem;
|
|
185
186
|
const response = await func(pathRef.current, convertId(id), item);
|
|
186
|
-
resetError();
|
|
187
187
|
return response;
|
|
188
188
|
} catch (error2) {
|
|
189
189
|
setError({ message: `Couldn't update item with id ${id}`, originalError: error2 });
|
|
@@ -197,8 +197,8 @@ function useProvideApi({
|
|
|
197
197
|
const deleteEntry = useCallback(
|
|
198
198
|
async (id) => {
|
|
199
199
|
try {
|
|
200
|
-
const response = await deleteItem(pathRef.current, convertId(id));
|
|
201
200
|
resetError();
|
|
201
|
+
const response = await deleteItem(pathRef.current, convertId(id));
|
|
202
202
|
return response;
|
|
203
203
|
} catch (error2) {
|
|
204
204
|
setError({ message: `Couldn't delete item with id ${id}`, originalError: error2 });
|
|
@@ -212,8 +212,8 @@ function useProvideApi({
|
|
|
212
212
|
const download = useCallback(
|
|
213
213
|
async (label, { export_mode, delimiter, quotechar } = {}) => {
|
|
214
214
|
try {
|
|
215
|
-
await downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
216
215
|
resetError();
|
|
216
|
+
await downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
217
217
|
} catch (error2) {
|
|
218
218
|
setError({ message: `Couldn't download`, originalError: error2 });
|
|
219
219
|
if (throwOnError) {
|
|
@@ -226,8 +226,8 @@ function useProvideApi({
|
|
|
226
226
|
const upload = useCallback(
|
|
227
227
|
async (file, { delimiter, quotechar } = {}) => {
|
|
228
228
|
try {
|
|
229
|
-
const response = await uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
230
229
|
resetError();
|
|
230
|
+
const response = await uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
231
231
|
return response;
|
|
232
232
|
} catch (error2) {
|
|
233
233
|
setError({ message: `Couldn't upload`, originalError: error2 });
|
|
@@ -3,27 +3,24 @@ import { postBulk } from "../utils/bulkActions/postBulkAction.mjs";
|
|
|
3
3
|
const useProvideBulk = ({ path }) => {
|
|
4
4
|
const [selectedIds, setSelectedIds] = useState([]);
|
|
5
5
|
const [error, setError] = useState();
|
|
6
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
6
7
|
const dispatchBulkActions = useCallback(
|
|
7
8
|
async (handler, data) => {
|
|
8
9
|
try {
|
|
10
|
+
resetError();
|
|
9
11
|
if (data === void 0) {
|
|
10
12
|
data = selectedIds;
|
|
11
13
|
}
|
|
12
14
|
const response = await postBulk(path, handler, data);
|
|
13
|
-
setError(void 0);
|
|
14
15
|
return response;
|
|
15
16
|
} catch (error2) {
|
|
16
17
|
setError({ message: `Couldn't perform bulk action`, originalError: error2 });
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
|
-
[path, selectedIds]
|
|
20
|
+
[path, resetError, selectedIds]
|
|
20
21
|
);
|
|
21
22
|
const bulkActions = useMemo(() => ({ selectedIds, setSelectedIds }), [selectedIds, setSelectedIds]);
|
|
22
|
-
return {
|
|
23
|
-
bulkActions,
|
|
24
|
-
dispatchBulkActions,
|
|
25
|
-
error
|
|
26
|
-
};
|
|
23
|
+
return { bulkActions, dispatchBulkActions, error, resetError };
|
|
27
24
|
};
|
|
28
25
|
export {
|
|
29
26
|
useProvideBulk
|
|
@@ -11,31 +11,32 @@ function useProvideAuth(baseURL, authQueryProps) {
|
|
|
11
11
|
retry: false,
|
|
12
12
|
...authQueryProps
|
|
13
13
|
});
|
|
14
|
-
const [error, setError] = useState(
|
|
14
|
+
const [error, setError] = useState();
|
|
15
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
15
16
|
const signin = useCallback(
|
|
16
17
|
({ username, password }) => {
|
|
17
|
-
|
|
18
|
+
resetError();
|
|
18
19
|
authSignin(baseURL, { username, password }).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
19
20
|
},
|
|
20
|
-
[baseURL, queryClient]
|
|
21
|
+
[baseURL, queryClient, resetError]
|
|
21
22
|
);
|
|
22
23
|
const signout = useCallback(() => {
|
|
23
|
-
|
|
24
|
+
resetError();
|
|
24
25
|
authSignout(baseURL).then(() => queryClient.resetQueries({ queryKey: ["user"] })).then(() => queryClient.resetQueries({ queryKey: ["info"] })).catch((err) => setError(err));
|
|
25
|
-
}, [baseURL, queryClient]);
|
|
26
|
+
}, [baseURL, queryClient, resetError]);
|
|
26
27
|
const update = useCallback(
|
|
27
28
|
(data) => {
|
|
28
|
-
|
|
29
|
+
resetError();
|
|
29
30
|
updateUser(baseURL, data).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
30
31
|
},
|
|
31
|
-
[baseURL, queryClient]
|
|
32
|
+
[baseURL, queryClient, resetError]
|
|
32
33
|
);
|
|
33
34
|
const resetPassword = useCallback(
|
|
34
35
|
(password) => {
|
|
35
|
-
|
|
36
|
+
resetError();
|
|
36
37
|
authResetPassword(baseURL, password, query.data).catch((err) => setError(err));
|
|
37
38
|
},
|
|
38
|
-
[baseURL, query.data]
|
|
39
|
+
[baseURL, query.data, resetError]
|
|
39
40
|
);
|
|
40
41
|
const oauth_signin = useCallback(
|
|
41
42
|
(provider, popup) => authOAuthSignin(baseURL, provider, popup, () => queryClient.invalidateQueries({ queryKey: ["user"] })),
|
|
@@ -50,7 +51,8 @@ function useProvideAuth(baseURL, authQueryProps) {
|
|
|
50
51
|
update,
|
|
51
52
|
resetPassword,
|
|
52
53
|
oauth_signin,
|
|
53
|
-
refetch: query.refetch
|
|
54
|
+
refetch: query.refetch,
|
|
55
|
+
resetError
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
export {
|
|
@@ -81,9 +81,9 @@ function useFabProvideApi({
|
|
|
81
81
|
}),
|
|
82
82
|
[streamingMode]
|
|
83
83
|
);
|
|
84
|
-
const [error, setError] = useState(
|
|
84
|
+
const [error, setError] = useState();
|
|
85
85
|
const memoizedError = useMemo(() => error, [error]);
|
|
86
|
-
const resetError = useCallback(() => setError(
|
|
86
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
87
87
|
const {
|
|
88
88
|
data: info,
|
|
89
89
|
isFetching: infoLoading,
|
|
@@ -142,8 +142,8 @@ function useFabProvideApi({
|
|
|
142
142
|
const getEntry = useCallback(
|
|
143
143
|
async (id) => {
|
|
144
144
|
try {
|
|
145
|
-
const response = await getItem(pathRef.current, convertId(id));
|
|
146
145
|
resetError();
|
|
146
|
+
const response = await getItem(pathRef.current, convertId(id));
|
|
147
147
|
return response;
|
|
148
148
|
} catch (error2) {
|
|
149
149
|
setError({ message: `Couldn't fetch item with id ${id}`, originalError: error2 });
|
|
@@ -157,8 +157,8 @@ function useFabProvideApi({
|
|
|
157
157
|
const addEntry = useCallback(
|
|
158
158
|
async (item) => {
|
|
159
159
|
try {
|
|
160
|
-
const response = await createItem(pathRef.current, item);
|
|
161
160
|
resetError();
|
|
161
|
+
const response = await createItem(pathRef.current, item);
|
|
162
162
|
return response;
|
|
163
163
|
} catch (error2) {
|
|
164
164
|
setError({ message: `Couldn't add item`, originalError: error2 });
|
|
@@ -172,8 +172,8 @@ function useFabProvideApi({
|
|
|
172
172
|
const updateEntry = useCallback(
|
|
173
173
|
async (id, item) => {
|
|
174
174
|
try {
|
|
175
|
-
const response = await updateItem(pathRef.current, convertId(id), item);
|
|
176
175
|
resetError();
|
|
176
|
+
const response = await updateItem(pathRef.current, convertId(id), item);
|
|
177
177
|
return response;
|
|
178
178
|
} catch (error2) {
|
|
179
179
|
setError({ message: `Couldn't update item with id ${id}`, originalError: error2 });
|
|
@@ -187,8 +187,8 @@ function useFabProvideApi({
|
|
|
187
187
|
const deleteEntry = useCallback(
|
|
188
188
|
async (id) => {
|
|
189
189
|
try {
|
|
190
|
-
const response = await deleteItem(pathRef.current, convertId(id));
|
|
191
190
|
resetError();
|
|
191
|
+
const response = await deleteItem(pathRef.current, convertId(id));
|
|
192
192
|
return response;
|
|
193
193
|
} catch (error2) {
|
|
194
194
|
setError({ message: `Couldn't delete item with id ${id}`, originalError: error2 });
|
|
@@ -202,8 +202,8 @@ function useFabProvideApi({
|
|
|
202
202
|
const download = useCallback(
|
|
203
203
|
async (label, { export_mode, delimiter, quotechar } = {}) => {
|
|
204
204
|
try {
|
|
205
|
-
await downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
206
205
|
resetError();
|
|
206
|
+
await downloadItems(pathRef.current, queryParamsRef.current, { label, export_mode, delimiter, quotechar });
|
|
207
207
|
} catch (error2) {
|
|
208
208
|
setError({ message: `Couldn't download`, originalError: error2 });
|
|
209
209
|
if (throwOnError) {
|
|
@@ -216,8 +216,8 @@ function useFabProvideApi({
|
|
|
216
216
|
const upload = useCallback(
|
|
217
217
|
async (file, { delimiter, quotechar } = {}) => {
|
|
218
218
|
try {
|
|
219
|
-
const response = await uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
220
219
|
resetError();
|
|
220
|
+
const response = await uploadItems(pathRef.current, file, { delimiter, quotechar });
|
|
221
221
|
return response;
|
|
222
222
|
} catch (error2) {
|
|
223
223
|
setError({ message: `Couldn't upload`, originalError: error2 });
|
|
@@ -3,27 +3,24 @@ import { postBulk } from "../utils/bulkActions/postBulkAction.mjs";
|
|
|
3
3
|
const useFabProvideBulk = ({ path }) => {
|
|
4
4
|
const [selectedIds, setSelectedIds] = useState([]);
|
|
5
5
|
const [error, setError] = useState();
|
|
6
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
6
7
|
const dispatchBulkActions = useCallback(
|
|
7
8
|
async (handler, data) => {
|
|
8
9
|
try {
|
|
10
|
+
resetError();
|
|
9
11
|
if (data === void 0) {
|
|
10
12
|
data = selectedIds;
|
|
11
13
|
}
|
|
12
14
|
const response = await postBulk(path, handler, data);
|
|
13
|
-
setError(void 0);
|
|
14
15
|
return response;
|
|
15
16
|
} catch (error2) {
|
|
16
17
|
setError({ message: `Couldn't perform bulk action`, originalError: error2 });
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
|
-
[path, selectedIds]
|
|
20
|
+
[path, resetError, selectedIds]
|
|
20
21
|
);
|
|
21
22
|
const bulkActions = useMemo(() => ({ selectedIds, setSelectedIds }), [selectedIds, setSelectedIds]);
|
|
22
|
-
return {
|
|
23
|
-
bulkActions,
|
|
24
|
-
dispatchBulkActions,
|
|
25
|
-
error
|
|
26
|
-
};
|
|
23
|
+
return { bulkActions, dispatchBulkActions, error, resetError };
|
|
27
24
|
};
|
|
28
25
|
export {
|
|
29
26
|
useFabProvideBulk
|
|
@@ -11,31 +11,32 @@ function useFabProvideAuth(baseURL, authQueryProps) {
|
|
|
11
11
|
retry: false,
|
|
12
12
|
...authQueryProps
|
|
13
13
|
});
|
|
14
|
-
const [error, setError] = useState(
|
|
14
|
+
const [error, setError] = useState();
|
|
15
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
15
16
|
const signin = useCallback(
|
|
16
17
|
({ username, password }) => {
|
|
17
|
-
|
|
18
|
+
resetError();
|
|
18
19
|
authSignin(baseURL, { username, password }).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
19
20
|
},
|
|
20
|
-
[baseURL, queryClient]
|
|
21
|
+
[baseURL, queryClient, resetError]
|
|
21
22
|
);
|
|
22
23
|
const signout = useCallback(() => {
|
|
23
|
-
|
|
24
|
+
resetError();
|
|
24
25
|
authSignout(baseURL).then(() => queryClient.resetQueries({ queryKey: ["user"] })).then(() => queryClient.resetQueries({ queryKey: ["info"] })).catch((err) => setError(err));
|
|
25
|
-
}, [baseURL, queryClient]);
|
|
26
|
+
}, [baseURL, queryClient, resetError]);
|
|
26
27
|
const update = useCallback(
|
|
27
28
|
(data) => {
|
|
28
|
-
|
|
29
|
+
resetError();
|
|
29
30
|
updateUser(baseURL, data).then(() => queryClient.invalidateQueries({ queryKey: ["user"] })).catch((err) => setError(err));
|
|
30
31
|
},
|
|
31
|
-
[baseURL, queryClient]
|
|
32
|
+
[baseURL, queryClient, resetError]
|
|
32
33
|
);
|
|
33
34
|
const resetPassword = useCallback(
|
|
34
35
|
(password) => {
|
|
35
|
-
|
|
36
|
+
resetError();
|
|
36
37
|
authResetPassword(baseURL, password, query.data).catch((err) => setError(err));
|
|
37
38
|
},
|
|
38
|
-
[baseURL, query.data]
|
|
39
|
+
[baseURL, query.data, resetError]
|
|
39
40
|
);
|
|
40
41
|
const oauth_signin = useCallback(
|
|
41
42
|
(provider, popup) => authOAuthSignin(baseURL, provider, popup, () => queryClient.invalidateQueries({ queryKey: ["user"] })),
|
|
@@ -50,7 +51,8 @@ function useFabProvideAuth(baseURL, authQueryProps) {
|
|
|
50
51
|
update,
|
|
51
52
|
resetPassword,
|
|
52
53
|
oauth_signin,
|
|
53
|
-
refetch: query.refetch
|
|
54
|
+
refetch: query.refetch,
|
|
55
|
+
resetError
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
export {
|
|
@@ -11,4 +11,5 @@ export function useProvideAuth(baseURL: any, authQueryProps: any): {
|
|
|
11
11
|
resetPassword: (password: any) => void;
|
|
12
12
|
oauth_signin: (provider: any, popup: any) => Promise<void>;
|
|
13
13
|
refetch: (options?: import('@tanstack/react-query').RefetchOptions) => Promise<import('@tanstack/react-query').QueryObserverResult<unknown, Error>>;
|
|
14
|
+
resetError: () => void;
|
|
14
15
|
};
|
|
@@ -11,4 +11,5 @@ export function useFabProvideAuth(baseURL: any, authQueryProps: any): {
|
|
|
11
11
|
resetPassword: (password: any) => void;
|
|
12
12
|
oauth_signin: (provider: any, popup: any) => Promise<void>;
|
|
13
13
|
refetch: (options?: import('@tanstack/react-query').RefetchOptions) => Promise<import('@tanstack/react-query').QueryObserverResult<unknown, Error>>;
|
|
14
|
+
resetError: () => void;
|
|
14
15
|
};
|
|
@@ -9,11 +9,21 @@ export type SafeContextOptions = {
|
|
|
9
9
|
*/
|
|
10
10
|
defaultValue?: any;
|
|
11
11
|
};
|
|
12
|
+
export type BulkActions = {
|
|
13
|
+
/**
|
|
14
|
+
* - An array of currently selected IDs for bulk actions.
|
|
15
|
+
*/
|
|
16
|
+
selectedIds: Array<string | number>;
|
|
17
|
+
/**
|
|
18
|
+
* - A function to set the selected IDs.
|
|
19
|
+
*/
|
|
20
|
+
setSelectedIds: Function;
|
|
21
|
+
};
|
|
12
22
|
export type BulkActionsContext = {
|
|
13
23
|
/**
|
|
14
24
|
* - An array containing the selected IDs and a function to set them.
|
|
15
25
|
*/
|
|
16
|
-
bulkActions:
|
|
26
|
+
bulkActions: BulkActions;
|
|
17
27
|
/**
|
|
18
28
|
* - A function to dispatch bulk actions with a handler and optional data. If data is not provided, it uses the currently selected IDs.
|
|
19
29
|
*/
|
|
@@ -25,4 +35,8 @@ export type BulkActionsContext = {
|
|
|
25
35
|
message: string;
|
|
26
36
|
originalError: Error;
|
|
27
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* - A function to reset the error state.
|
|
40
|
+
*/
|
|
41
|
+
resetError: () => void;
|
|
28
42
|
};
|
|
@@ -4,7 +4,8 @@ const react = require("react");
|
|
|
4
4
|
function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearDataOnRefetch = false, ...options } = {}) {
|
|
5
5
|
const [data, setData] = react.useState(null);
|
|
6
6
|
const [loading, setLoading] = react.useState(initialLoading);
|
|
7
|
-
const [error, setError] = react.useState(
|
|
7
|
+
const [error, setError] = react.useState();
|
|
8
|
+
const resetError = react.useCallback(() => setError(void 0), []);
|
|
8
9
|
const controller = react.useRef(null);
|
|
9
10
|
const refetch = react.useCallback(() => {
|
|
10
11
|
if (!url) {
|
|
@@ -13,7 +14,7 @@ function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearD
|
|
|
13
14
|
if (clearDataOnRefetch) {
|
|
14
15
|
setData(null);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
resetError();
|
|
17
18
|
if (controller.current) {
|
|
18
19
|
controller.current.abort();
|
|
19
20
|
}
|
|
@@ -53,6 +54,6 @@ function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearD
|
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
56
|
}, [refetch, autoInvoke]);
|
|
56
|
-
return { data, loading, error, refetch, abort };
|
|
57
|
+
return { data, loading, error, refetch, abort, resetError };
|
|
57
58
|
}
|
|
58
59
|
exports.useCustomFetch = useCustomFetch;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useState,
|
|
1
|
+
import { useState, useCallback, useRef, useEffect } from "react";
|
|
2
2
|
function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearDataOnRefetch = false, ...options } = {}) {
|
|
3
3
|
const [data, setData] = useState(null);
|
|
4
4
|
const [loading, setLoading] = useState(initialLoading);
|
|
5
|
-
const [error, setError] = useState(
|
|
5
|
+
const [error, setError] = useState();
|
|
6
|
+
const resetError = useCallback(() => setError(void 0), []);
|
|
6
7
|
const controller = useRef(null);
|
|
7
8
|
const refetch = useCallback(() => {
|
|
8
9
|
if (!url) {
|
|
@@ -11,7 +12,7 @@ function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearD
|
|
|
11
12
|
if (clearDataOnRefetch) {
|
|
12
13
|
setData(null);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
resetError();
|
|
15
16
|
if (controller.current) {
|
|
16
17
|
controller.current.abort();
|
|
17
18
|
}
|
|
@@ -51,7 +52,7 @@ function useCustomFetch(url, { autoInvoke = true, initialLoading = false, clearD
|
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
54
|
}, [refetch, autoInvoke]);
|
|
54
|
-
return { data, loading, error, refetch, abort };
|
|
55
|
+
return { data, loading, error, refetch, abort, resetError };
|
|
55
56
|
}
|
|
56
57
|
export {
|
|
57
58
|
useCustomFetch
|
package/package.json
CHANGED
|
File without changes
|