@centreon/ui 23.10.73 → 23.10.74
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/package.json
CHANGED
|
@@ -21,15 +21,15 @@ export enum Method {
|
|
|
21
21
|
PUT = 'PUT'
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type UseMutationQueryProps<T> = {
|
|
24
|
+
export type UseMutationQueryProps<T, TMeta> = {
|
|
25
25
|
catchError?: (props: CatchErrorProps) => void;
|
|
26
26
|
decoder?: JsonDecoder.Decoder<T>;
|
|
27
27
|
defaultFailureMessage?: string;
|
|
28
28
|
fetchHeaders?: HeadersInit;
|
|
29
|
-
getEndpoint: (_meta
|
|
29
|
+
getEndpoint: (_meta: TMeta) => string;
|
|
30
30
|
httpCodesBypassErrorSnackbar?: Array<number>;
|
|
31
31
|
method: Method;
|
|
32
|
-
} & Omit<UseMutationOptions<T>, 'mutationFn'>;
|
|
32
|
+
} & Omit<UseMutationOptions<T & { _meta?: TMeta }>, 'mutationFn'>;
|
|
33
33
|
|
|
34
34
|
const log = anylogger('API Request');
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ export type UseMutationQueryState<T> = {
|
|
|
38
38
|
isMutating: boolean;
|
|
39
39
|
} & UseMutationResult<T | ResponseError>;
|
|
40
40
|
|
|
41
|
-
const useMutationQuery = <T extends object>({
|
|
41
|
+
const useMutationQuery = <T extends object, TMeta>({
|
|
42
42
|
getEndpoint,
|
|
43
43
|
catchError,
|
|
44
44
|
decoder,
|
|
@@ -47,20 +47,24 @@ const useMutationQuery = <T extends object>({
|
|
|
47
47
|
httpCodesBypassErrorSnackbar = [],
|
|
48
48
|
method,
|
|
49
49
|
onMutate,
|
|
50
|
-
onError
|
|
51
|
-
|
|
50
|
+
onError,
|
|
51
|
+
onSuccess
|
|
52
|
+
}: UseMutationQueryProps<T, TMeta>): UseMutationQueryState<T> => {
|
|
52
53
|
const { showErrorMessage } = useSnackbar();
|
|
53
54
|
|
|
54
|
-
const queryData = useMutation<
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const queryData = useMutation<
|
|
56
|
+
T | ResponseError,
|
|
57
|
+
ResponseError,
|
|
58
|
+
T & { _meta: TMeta }
|
|
59
|
+
>(
|
|
60
|
+
(_payload: T & { _meta: TMeta }): Promise<T | ResponseError> => {
|
|
57
61
|
const { _meta, ...payload } = _payload || {};
|
|
58
62
|
|
|
59
63
|
return customFetch<T>({
|
|
60
64
|
catchError,
|
|
61
65
|
decoder,
|
|
62
66
|
defaultFailureMessage,
|
|
63
|
-
endpoint: getEndpoint(_meta),
|
|
67
|
+
endpoint: getEndpoint(_meta as TMeta),
|
|
64
68
|
headers: new Headers({
|
|
65
69
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
66
70
|
...fetchHeaders
|
|
@@ -72,7 +76,8 @@ const useMutationQuery = <T extends object>({
|
|
|
72
76
|
},
|
|
73
77
|
{
|
|
74
78
|
onError,
|
|
75
|
-
onMutate
|
|
79
|
+
onMutate,
|
|
80
|
+
onSuccess
|
|
76
81
|
}
|
|
77
82
|
);
|
|
78
83
|
|