@refinedev/core 4.53.0 → 4.54.0
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/CHANGELOG.md +361 -0
- package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
- package/dist/definitions/types/index.d.cts +12 -0
- package/dist/definitions/types/index.d.cts.map +1 -0
- package/dist/definitions/types/index.d.mts +12 -0
- package/dist/definitions/types/index.d.mts.map +12 -0
- package/dist/definitions/types/index.d.ts +12 -0
- package/dist/definitions/types/index.d.ts.map +1 -0
- package/dist/hooks/data/useCreate.d.cts +7 -6
- package/dist/hooks/data/useCreate.d.cts.map +1 -1
- package/dist/hooks/data/useCreate.d.mts +7 -6
- package/dist/hooks/data/useCreate.d.mts.map +7 -6
- package/dist/hooks/data/useCreate.d.ts +7 -6
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.cts +9 -9
- package/dist/hooks/data/useCreateMany.d.cts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.mts +9 -9
- package/dist/hooks/data/useCreateMany.d.mts.map +9 -9
- package/dist/hooks/data/useCreateMany.d.ts +9 -9
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.cts +8 -7
- package/dist/hooks/data/useUpdate.d.cts.map +1 -1
- package/dist/hooks/data/useUpdate.d.mts +8 -7
- package/dist/hooks/data/useUpdate.d.mts.map +8 -7
- package/dist/hooks/data/useUpdate.d.ts +8 -7
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.cts +9 -9
- package/dist/hooks/data/useUpdateMany.d.cts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.mts +9 -9
- package/dist/hooks/data/useUpdateMany.d.mts.map +9 -9
- package/dist/hooks/data/useUpdateMany.d.ts +9 -9
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/form/index.d.cts.map +1 -1
- package/dist/hooks/form/index.d.ts.map +1 -1
- package/dist/hooks/form/types.d.cts +8 -0
- package/dist/hooks/form/types.d.cts.map +1 -1
- package/dist/hooks/form/types.d.mts +8 -0
- package/dist/hooks/form/types.d.mts.map +8 -0
- package/dist/hooks/form/types.d.ts +8 -0
- package/dist/hooks/form/types.d.ts.map +1 -1
- package/dist/hooks/show/index.d.cts.map +1 -1
- package/dist/hooks/show/index.d.ts.map +1 -1
- package/dist/hooks/show/types.d.cts +4 -0
- package/dist/hooks/show/types.d.cts.map +1 -1
- package/dist/hooks/show/types.d.mts +4 -0
- package/dist/hooks/show/types.d.mts.map +4 -0
- package/dist/hooks/show/types.d.ts +4 -0
- package/dist/hooks/show/types.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.cts +10 -2
- package/dist/hooks/useSelect/index.d.cts.map +1 -1
- package/dist/hooks/useSelect/index.d.mts +10 -2
- package/dist/hooks/useSelect/index.d.mts.map +10 -2
- package/dist/hooks/useSelect/index.d.ts +10 -2
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.cts +4 -0
- package/dist/hooks/useTable/index.d.cts.map +1 -1
- package/dist/hooks/useTable/index.d.mts +4 -0
- package/dist/hooks/useTable/index.d.mts.map +4 -0
- package/dist/hooks/useTable/index.d.ts +4 -0
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/pages/auth/components/login/index.tsx +7 -2
- package/src/definitions/types/index.ts +40 -0
- package/src/hooks/data/useCreate.ts +93 -32
- package/src/hooks/data/useCreateMany.ts +96 -33
- package/src/hooks/data/useUpdate.ts +137 -53
- package/src/hooks/data/useUpdateMany.ts +140 -51
- package/src/hooks/form/index.ts +2 -0
- package/src/hooks/form/types.ts +10 -0
- package/src/hooks/show/index.ts +1 -0
- package/src/hooks/show/types.ts +4 -0
- package/src/hooks/useSelect/index.ts +50 -28
- package/src/hooks/useTable/index.ts +5 -0
- package/dist/hooks/show/useShow.d.cts +0 -57
- package/dist/hooks/show/useShow.d.cts.map +0 -1
- package/dist/hooks/show/useShow.d.mts +0 -57
- package/dist/hooks/show/useShow.d.mts.map +0 -57
- package/dist/hooks/show/useShow.d.ts +0 -57
- package/dist/hooks/show/useShow.d.ts.map +0 -1
- package/src/hooks/show/useShow.ts +0 -179
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.54.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"module": "dist/index.mjs",
|
|
28
28
|
"typings": "dist/index.d.ts",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@refinedev/devtools-internal": "1.1.
|
|
30
|
+
"@refinedev/devtools-internal": "1.1.14",
|
|
31
31
|
"@tanstack/react-query": "^4.10.1",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"lodash-es": "^4.17.21",
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { useActiveAuthProvider } from "@definitions/helpers";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
useLink,
|
|
6
|
+
useLogin,
|
|
7
|
+
useRouterContext,
|
|
8
|
+
useRouterType,
|
|
9
|
+
useTranslate,
|
|
10
|
+
} from "@hooks";
|
|
6
11
|
|
|
7
12
|
import type { DivPropsType, FormPropsType } from "../..";
|
|
8
13
|
import type { LoginFormTypes, LoginPageProps } from "../../types";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MutateOptions,
|
|
3
|
+
UseMutationResult as UseMutationResultBase,
|
|
4
|
+
} from "@tanstack/react-query";
|
|
5
|
+
|
|
6
|
+
export type MutateAsyncFunction<
|
|
7
|
+
TData = unknown,
|
|
8
|
+
TError = unknown,
|
|
9
|
+
TVariables = void,
|
|
10
|
+
TContext = unknown,
|
|
11
|
+
> = (
|
|
12
|
+
variables?: TVariables,
|
|
13
|
+
options?: MutateOptions<TData, TError, TVariables, TContext>,
|
|
14
|
+
) => Promise<TData>;
|
|
15
|
+
|
|
16
|
+
export type MutateFunction<
|
|
17
|
+
TData = unknown,
|
|
18
|
+
TError = unknown,
|
|
19
|
+
TVariables = void,
|
|
20
|
+
TContext = unknown,
|
|
21
|
+
> = (
|
|
22
|
+
...args: Parameters<MutateAsyncFunction<TData, TError, TVariables, TContext>>
|
|
23
|
+
) => void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* we want to make the mutate and mutateAsync functions optional in the UseMutationResult
|
|
27
|
+
* because we want users to be able to provide the required parameters from the hook
|
|
28
|
+
*/
|
|
29
|
+
export type UseMutationResult<
|
|
30
|
+
TData = unknown,
|
|
31
|
+
TError = unknown,
|
|
32
|
+
TVariables = unknown,
|
|
33
|
+
TContext = unknown,
|
|
34
|
+
> = Omit<
|
|
35
|
+
UseMutationResultBase<TData, TError, TVariables, TContext>,
|
|
36
|
+
"mutate" | "mutateAsync"
|
|
37
|
+
> & {
|
|
38
|
+
mutate: MutateFunction<TData, TError, TVariables, TContext>;
|
|
39
|
+
mutateAsync: MutateAsyncFunction<TData, TError, TVariables, TContext>;
|
|
40
|
+
};
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { getXRay } from "@refinedev/devtools-internal";
|
|
7
7
|
import {
|
|
8
8
|
type UseMutationOptions,
|
|
9
|
-
type
|
|
9
|
+
type MutateOptions,
|
|
10
10
|
useMutation,
|
|
11
11
|
} from "@tanstack/react-query";
|
|
12
12
|
|
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
IQueryKeys,
|
|
32
32
|
MetaQuery,
|
|
33
33
|
} from "../../contexts/data/types";
|
|
34
|
+
import type { UseMutationResult } from "../../definitions/types";
|
|
34
35
|
import type { SuccessErrorNotification } from "../../contexts/notification/types";
|
|
35
36
|
import {
|
|
36
37
|
type UseLoadingOvertimeOptionsProps,
|
|
@@ -42,11 +43,11 @@ export type UseCreateParams<TData, TError, TVariables> = {
|
|
|
42
43
|
/**
|
|
43
44
|
* Resource name for API data interactions
|
|
44
45
|
*/
|
|
45
|
-
resource
|
|
46
|
+
resource?: string;
|
|
46
47
|
/**
|
|
47
48
|
* Values for mutation function
|
|
48
49
|
*/
|
|
49
|
-
values
|
|
50
|
+
values?: TVariables;
|
|
50
51
|
/**
|
|
51
52
|
* Meta data for `dataProvider`
|
|
52
53
|
*/
|
|
@@ -89,9 +90,10 @@ export type UseCreateProps<
|
|
|
89
90
|
UseCreateParams<TData, TError, TVariables>,
|
|
90
91
|
unknown
|
|
91
92
|
>,
|
|
92
|
-
"mutationFn"
|
|
93
|
+
"mutationFn"
|
|
93
94
|
>;
|
|
94
|
-
} & UseLoadingOvertimeOptionsProps
|
|
95
|
+
} & UseLoadingOvertimeOptionsProps &
|
|
96
|
+
UseCreateParams<TData, TError, TVariables>;
|
|
95
97
|
|
|
96
98
|
/**
|
|
97
99
|
* `useCreate` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for create mutations.
|
|
@@ -111,6 +113,14 @@ export const useCreate = <
|
|
|
111
113
|
TError extends HttpError = HttpError,
|
|
112
114
|
TVariables = {},
|
|
113
115
|
>({
|
|
116
|
+
resource: resourceFromProps,
|
|
117
|
+
values: valuesFromProps,
|
|
118
|
+
dataProviderName: dataProviderNameFromProps,
|
|
119
|
+
successNotification: successNotificationFromProps,
|
|
120
|
+
errorNotification: errorNotificationFromProps,
|
|
121
|
+
invalidates: invalidatesFromProps,
|
|
122
|
+
meta: metaFromProps,
|
|
123
|
+
metaData: metaDataFromProps,
|
|
114
124
|
mutationOptions,
|
|
115
125
|
overtimeOptions,
|
|
116
126
|
}: UseCreateProps<TData, TError, TVariables> = {}): UseCreateReturnType<
|
|
@@ -136,19 +146,22 @@ export const useCreate = <
|
|
|
136
146
|
} = useRefineContext();
|
|
137
147
|
const { keys, preferLegacyKeys } = useKeys();
|
|
138
148
|
|
|
139
|
-
const
|
|
149
|
+
const mutationResult = useMutation<
|
|
140
150
|
CreateResponse<TData>,
|
|
141
151
|
TError,
|
|
142
152
|
UseCreateParams<TData, TError, TVariables>,
|
|
143
153
|
unknown
|
|
144
154
|
>({
|
|
145
155
|
mutationFn: ({
|
|
146
|
-
resource: resourceName,
|
|
147
|
-
values,
|
|
148
|
-
meta,
|
|
149
|
-
metaData,
|
|
150
|
-
dataProviderName,
|
|
156
|
+
resource: resourceName = resourceFromProps,
|
|
157
|
+
values = valuesFromProps,
|
|
158
|
+
meta = metaFromProps,
|
|
159
|
+
metaData = metaDataFromProps,
|
|
160
|
+
dataProviderName = dataProviderNameFromProps,
|
|
151
161
|
}: UseCreateParams<TData, TError, TVariables>) => {
|
|
162
|
+
if (!values) throw missingValuesError;
|
|
163
|
+
if (!resourceName) throw missingResourceError;
|
|
164
|
+
|
|
152
165
|
const { resource, identifier } = select(resourceName);
|
|
153
166
|
|
|
154
167
|
const combinedMeta = getMeta({
|
|
@@ -165,18 +178,20 @@ export const useCreate = <
|
|
|
165
178
|
metaData: combinedMeta,
|
|
166
179
|
});
|
|
167
180
|
},
|
|
168
|
-
onSuccess: (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
dataProviderName: dataProviderNameFromProp,
|
|
174
|
-
invalidates = ["list", "many"],
|
|
175
|
-
values,
|
|
176
|
-
meta,
|
|
177
|
-
metaData,
|
|
178
|
-
}
|
|
179
|
-
|
|
181
|
+
onSuccess: (data, variables, context) => {
|
|
182
|
+
const {
|
|
183
|
+
resource: resourceName = resourceFromProps,
|
|
184
|
+
successNotification:
|
|
185
|
+
successNotificationFromProp = successNotificationFromProps,
|
|
186
|
+
dataProviderName: dataProviderNameFromProp = dataProviderNameFromProps,
|
|
187
|
+
invalidates = invalidatesFromProps ?? ["list", "many"],
|
|
188
|
+
values = valuesFromProps,
|
|
189
|
+
meta = metaFromProps,
|
|
190
|
+
metaData = metaDataFromProps,
|
|
191
|
+
} = variables;
|
|
192
|
+
if (!values) throw missingValuesError;
|
|
193
|
+
if (!resourceName) throw missingResourceError;
|
|
194
|
+
|
|
180
195
|
const { resource, identifier } = select(resourceName);
|
|
181
196
|
const resourceSingular = textTransformers.singular(identifier);
|
|
182
197
|
|
|
@@ -247,15 +262,19 @@ export const useCreate = <
|
|
|
247
262
|
...rest,
|
|
248
263
|
},
|
|
249
264
|
});
|
|
265
|
+
|
|
266
|
+
mutationOptions?.onSuccess?.(data, variables, context);
|
|
250
267
|
},
|
|
251
|
-
onError: (
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
values,
|
|
257
|
-
}
|
|
258
|
-
|
|
268
|
+
onError: (err: TError, variables, context) => {
|
|
269
|
+
const {
|
|
270
|
+
resource: resourceName = resourceFromProps,
|
|
271
|
+
errorNotification:
|
|
272
|
+
errorNotificationFromProp = errorNotificationFromProps,
|
|
273
|
+
values = valuesFromProps,
|
|
274
|
+
} = variables;
|
|
275
|
+
if (!values) throw missingValuesError;
|
|
276
|
+
if (!resourceName) throw missingResourceError;
|
|
277
|
+
|
|
259
278
|
checkError(err);
|
|
260
279
|
|
|
261
280
|
const { identifier } = select(resourceName);
|
|
@@ -283,6 +302,8 @@ export const useCreate = <
|
|
|
283
302
|
),
|
|
284
303
|
type: "error",
|
|
285
304
|
});
|
|
305
|
+
|
|
306
|
+
mutationOptions?.onError?.(err, variables, context);
|
|
286
307
|
},
|
|
287
308
|
mutationKey: keys().data().mutation("create").get(preferLegacyKeys),
|
|
288
309
|
...mutationOptions,
|
|
@@ -291,6 +312,7 @@ export const useCreate = <
|
|
|
291
312
|
...getXRay("useCreate", preferLegacyKeys),
|
|
292
313
|
},
|
|
293
314
|
});
|
|
315
|
+
const { mutate, mutateAsync, ...mutation } = mutationResult;
|
|
294
316
|
|
|
295
317
|
const { elapsedTime } = useLoadingOvertime({
|
|
296
318
|
isLoading: mutation.isLoading,
|
|
@@ -298,5 +320,44 @@ export const useCreate = <
|
|
|
298
320
|
onInterval: overtimeOptions?.onInterval,
|
|
299
321
|
});
|
|
300
322
|
|
|
301
|
-
|
|
323
|
+
// this function is used to make the `variables` parameter optional
|
|
324
|
+
const handleMutation = (
|
|
325
|
+
variables?: UseCreateParams<TData, TError, TVariables>,
|
|
326
|
+
options?: MutateOptions<
|
|
327
|
+
CreateResponse<TData>,
|
|
328
|
+
TError,
|
|
329
|
+
UseCreateParams<TData, TError, TVariables>,
|
|
330
|
+
unknown
|
|
331
|
+
>,
|
|
332
|
+
) => {
|
|
333
|
+
return mutate(variables || {}, options);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// this function is used to make the `variables` parameter optional
|
|
337
|
+
const handleMutateAsync = (
|
|
338
|
+
variables?: UseCreateParams<TData, TError, TVariables>,
|
|
339
|
+
options?: MutateOptions<
|
|
340
|
+
CreateResponse<TData>,
|
|
341
|
+
TError,
|
|
342
|
+
UseCreateParams<TData, TError, TVariables>,
|
|
343
|
+
unknown
|
|
344
|
+
>,
|
|
345
|
+
) => {
|
|
346
|
+
return mutateAsync(variables || {}, options);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
...mutation,
|
|
351
|
+
mutate: handleMutation,
|
|
352
|
+
mutateAsync: handleMutateAsync,
|
|
353
|
+
overtime: { elapsedTime },
|
|
354
|
+
};
|
|
302
355
|
};
|
|
356
|
+
|
|
357
|
+
const missingResourceError = new Error(
|
|
358
|
+
"[useCreate]: `resource` is not defined or not matched but is required",
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const missingValuesError = new Error(
|
|
362
|
+
"[useCreate]: `values` is not provided but is required",
|
|
363
|
+
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getXRay } from "@refinedev/devtools-internal";
|
|
2
2
|
import {
|
|
3
3
|
type UseMutationOptions,
|
|
4
|
-
type
|
|
4
|
+
type MutateOptions,
|
|
5
5
|
useMutation,
|
|
6
6
|
} from "@tanstack/react-query";
|
|
7
7
|
|
|
@@ -30,6 +30,7 @@ import type {
|
|
|
30
30
|
IQueryKeys,
|
|
31
31
|
MetaQuery,
|
|
32
32
|
} from "../../contexts/data/types";
|
|
33
|
+
import type { UseMutationResult } from "../../definitions/types";
|
|
33
34
|
import type { SuccessErrorNotification } from "../../contexts/notification/types";
|
|
34
35
|
import {
|
|
35
36
|
type UseLoadingOvertimeOptionsProps,
|
|
@@ -37,9 +38,9 @@ import {
|
|
|
37
38
|
useLoadingOvertime,
|
|
38
39
|
} from "../useLoadingOvertime";
|
|
39
40
|
|
|
40
|
-
type
|
|
41
|
-
resource
|
|
42
|
-
values
|
|
41
|
+
export type UseCreateManyParams<TData, TError, TVariables> = {
|
|
42
|
+
resource?: string;
|
|
43
|
+
values?: TVariables[];
|
|
43
44
|
meta?: MetaQuery;
|
|
44
45
|
metaData?: MetaQuery;
|
|
45
46
|
dataProviderName?: string;
|
|
@@ -53,7 +54,7 @@ export type UseCreateManyReturnType<
|
|
|
53
54
|
> = UseMutationResult<
|
|
54
55
|
CreateManyResponse<TData>,
|
|
55
56
|
TError,
|
|
56
|
-
|
|
57
|
+
UseCreateManyParams<TData, TError, TVariables>,
|
|
57
58
|
unknown
|
|
58
59
|
>;
|
|
59
60
|
|
|
@@ -66,11 +67,12 @@ export type UseCreateManyProps<
|
|
|
66
67
|
UseMutationOptions<
|
|
67
68
|
CreateManyResponse<TData>,
|
|
68
69
|
TError,
|
|
69
|
-
|
|
70
|
+
UseCreateManyParams<TData, TError, TVariables>
|
|
70
71
|
>,
|
|
71
|
-
"mutationFn"
|
|
72
|
+
"mutationFn"
|
|
72
73
|
>;
|
|
73
|
-
} & UseLoadingOvertimeOptionsProps
|
|
74
|
+
} & UseLoadingOvertimeOptionsProps &
|
|
75
|
+
UseCreateManyParams<TData, TError, TVariables>;
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
78
|
* `useCreateMany` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for multiple create mutations.
|
|
@@ -89,6 +91,14 @@ export const useCreateMany = <
|
|
|
89
91
|
TError extends HttpError = HttpError,
|
|
90
92
|
TVariables = {},
|
|
91
93
|
>({
|
|
94
|
+
resource: resourceFromProps,
|
|
95
|
+
values: valuesFromProps,
|
|
96
|
+
dataProviderName: dataProviderNameFromProps,
|
|
97
|
+
successNotification: successNotificationFromProps,
|
|
98
|
+
errorNotification: errorNotificationFromProps,
|
|
99
|
+
meta: metaFromProps,
|
|
100
|
+
metaData: metaDataFromProps,
|
|
101
|
+
invalidates: invalidatesFromProps,
|
|
92
102
|
mutationOptions,
|
|
93
103
|
overtimeOptions,
|
|
94
104
|
}: UseCreateManyProps<TData, TError, TVariables> = {}): UseCreateManyReturnType<
|
|
@@ -110,18 +120,21 @@ export const useCreateMany = <
|
|
|
110
120
|
} = useRefineContext();
|
|
111
121
|
const { keys, preferLegacyKeys } = useKeys();
|
|
112
122
|
|
|
113
|
-
const
|
|
123
|
+
const mutationResult = useMutation<
|
|
114
124
|
CreateManyResponse<TData>,
|
|
115
125
|
TError,
|
|
116
|
-
|
|
126
|
+
UseCreateManyParams<TData, TError, TVariables>
|
|
117
127
|
>({
|
|
118
128
|
mutationFn: ({
|
|
119
|
-
resource: resourceName,
|
|
120
|
-
values,
|
|
121
|
-
meta,
|
|
122
|
-
metaData,
|
|
123
|
-
dataProviderName,
|
|
124
|
-
}:
|
|
129
|
+
resource: resourceName = resourceFromProps,
|
|
130
|
+
values = valuesFromProps,
|
|
131
|
+
meta = metaFromProps,
|
|
132
|
+
metaData = metaDataFromProps,
|
|
133
|
+
dataProviderName = dataProviderNameFromProps,
|
|
134
|
+
}: UseCreateManyParams<TData, TError, TVariables>) => {
|
|
135
|
+
if (!values) throw missingValuesError;
|
|
136
|
+
if (!resourceName) throw missingResourceError;
|
|
137
|
+
|
|
125
138
|
const { resource, identifier } = select(resourceName);
|
|
126
139
|
|
|
127
140
|
const combinedMeta = getMeta({
|
|
@@ -152,18 +165,19 @@ export const useCreateMany = <
|
|
|
152
165
|
),
|
|
153
166
|
);
|
|
154
167
|
},
|
|
155
|
-
onSuccess: (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
onSuccess: (response, variables, context) => {
|
|
169
|
+
const {
|
|
170
|
+
resource: resourceName = resourceFromProps,
|
|
171
|
+
successNotification = successNotificationFromProps,
|
|
172
|
+
dataProviderName: dataProviderNameFromProp = dataProviderNameFromProps,
|
|
173
|
+
invalidates = invalidatesFromProps ?? ["list", "many"],
|
|
174
|
+
values = valuesFromProps,
|
|
175
|
+
meta = metaFromProps,
|
|
176
|
+
metaData = metaDataFromProps,
|
|
177
|
+
} = variables;
|
|
178
|
+
if (!values) throw missingValuesError;
|
|
179
|
+
if (!resourceName) throw missingResourceError;
|
|
180
|
+
|
|
167
181
|
const { resource, identifier } = select(resourceName);
|
|
168
182
|
const resourcePlural = textTransformers.plural(identifier);
|
|
169
183
|
|
|
@@ -234,11 +248,18 @@ export const useCreateMany = <
|
|
|
234
248
|
...rest,
|
|
235
249
|
},
|
|
236
250
|
});
|
|
251
|
+
|
|
252
|
+
mutationOptions?.onSuccess?.(response, variables, context);
|
|
237
253
|
},
|
|
238
|
-
onError: (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
254
|
+
onError: (err: TError, variables, context) => {
|
|
255
|
+
const {
|
|
256
|
+
resource: resourceName = resourceFromProps,
|
|
257
|
+
errorNotification = errorNotificationFromProps,
|
|
258
|
+
values = valuesFromProps,
|
|
259
|
+
} = variables;
|
|
260
|
+
if (!values) throw missingValuesError;
|
|
261
|
+
if (!resourceName) throw missingResourceError;
|
|
262
|
+
|
|
242
263
|
const { identifier } = select(resourceName);
|
|
243
264
|
|
|
244
265
|
const notificationConfig =
|
|
@@ -259,6 +280,8 @@ export const useCreateMany = <
|
|
|
259
280
|
),
|
|
260
281
|
type: "error",
|
|
261
282
|
});
|
|
283
|
+
|
|
284
|
+
mutationOptions?.onError?.(err, variables, context);
|
|
262
285
|
},
|
|
263
286
|
mutationKey: keys().data().mutation("createMany").get(preferLegacyKeys),
|
|
264
287
|
...mutationOptions,
|
|
@@ -267,6 +290,7 @@ export const useCreateMany = <
|
|
|
267
290
|
...getXRay("useCreateMany", preferLegacyKeys),
|
|
268
291
|
},
|
|
269
292
|
});
|
|
293
|
+
const { mutate, mutateAsync, ...mutation } = mutationResult;
|
|
270
294
|
|
|
271
295
|
const { elapsedTime } = useLoadingOvertime({
|
|
272
296
|
isLoading: mutation.isLoading,
|
|
@@ -274,5 +298,44 @@ export const useCreateMany = <
|
|
|
274
298
|
onInterval: overtimeOptions?.onInterval,
|
|
275
299
|
});
|
|
276
300
|
|
|
277
|
-
|
|
301
|
+
// this function is used to make the `variables` parameter optional
|
|
302
|
+
const handleMutation = (
|
|
303
|
+
variables?: UseCreateManyParams<TData, TError, TVariables>,
|
|
304
|
+
options?: MutateOptions<
|
|
305
|
+
CreateManyResponse<TData>,
|
|
306
|
+
TError,
|
|
307
|
+
UseCreateManyParams<TData, TError, TVariables>,
|
|
308
|
+
unknown
|
|
309
|
+
>,
|
|
310
|
+
) => {
|
|
311
|
+
return mutate(variables || {}, options);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// this function is used to make the `variables` parameter optional
|
|
315
|
+
const handleMutateAsync = (
|
|
316
|
+
variables?: UseCreateManyParams<TData, TError, TVariables>,
|
|
317
|
+
options?: MutateOptions<
|
|
318
|
+
CreateManyResponse<TData>,
|
|
319
|
+
TError,
|
|
320
|
+
UseCreateManyParams<TData, TError, TVariables>,
|
|
321
|
+
unknown
|
|
322
|
+
>,
|
|
323
|
+
) => {
|
|
324
|
+
return mutateAsync(variables || {}, options);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
...mutation,
|
|
329
|
+
mutate: handleMutation,
|
|
330
|
+
mutateAsync: handleMutateAsync,
|
|
331
|
+
overtime: { elapsedTime },
|
|
332
|
+
};
|
|
278
333
|
};
|
|
334
|
+
|
|
335
|
+
const missingResourceError = new Error(
|
|
336
|
+
"[useCreateMany]: `resource` is not defined or not matched but is required",
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const missingValuesError = new Error(
|
|
340
|
+
"[useCreateMany]: `values` is not provided but is required",
|
|
341
|
+
);
|