-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
SaveContext.ts
34 lines (31 loc) · 1006 Bytes
/
SaveContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createContext } from 'react';
import {
RaRecord,
OnError,
OnSuccess,
TransformData,
MutationMode,
} from '../../types';
import { Middleware } from './useMutationMiddlewares';
export interface SaveContextValue<
RecordType extends RaRecord = any,
MutateFunc extends (...args: any[]) => any = (...args: any[]) => any
> {
save?: SaveHandler<RecordType>;
/**
* @deprecated. Rely on the form isSubmitting value instead
*/
saving?: boolean;
mutationMode?: MutationMode;
registerMutationMiddleware?: (callback: Middleware<MutateFunc>) => void;
unregisterMutationMiddleware?: (callback: Middleware<MutateFunc>) => void;
}
export type SaveHandler<RecordType> = (
record: Partial<RecordType>,
callbacks?: {
onSuccess?: OnSuccess;
onError?: OnError;
transform?: TransformData;
}
) => Promise<void | RecordType> | Record<string, string>;
export const SaveContext = createContext<SaveContextValue>(undefined);