Skip to content

Commit

Permalink
fix ts
Browse files Browse the repository at this point in the history
  • Loading branch information
slax57 committed Dec 17, 2024
1 parent bd3faf0 commit 6c4fd3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
20 changes: 17 additions & 3 deletions packages/ra-core/src/controller/create/useCreateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export const useCreateController = <
MutationOptionsError,
ResultRecordType
> = {}
): CreateControllerResult<RecordType> => {
): CreateControllerResult<
RecordType,
MutationOptionsError,
ResultRecordType
> => {
const {
disableAuthentication,
record,
Expand Down Expand Up @@ -157,7 +161,10 @@ export const useCreateController = <
transform: transformFromSave,
meta: metaFromSave,
...callTimeOptions
} = {} as SaveHandlerCallbacks
} = {} as SaveHandlerCallbacks<
ResultRecordType,
MutationOptionsError
>
) =>
Promise.resolve(
transformFromSave
Expand Down Expand Up @@ -228,7 +235,14 @@ export interface CreateControllerProps<

export interface CreateControllerResult<
RecordType extends Omit<RaRecord, 'id'> = any,
> extends SaveContextValue {
MutationOptionsError = any,
ResultRecordType extends RaRecord = RecordType & { id: Identifier },
> extends SaveContextValue<
RecordType,
(...args: any[]) => any,
MutationOptionsError,
ResultRecordType
> {
defaultTitle?: string;
isFetching: boolean;
isPending: boolean;
Expand Down
26 changes: 13 additions & 13 deletions packages/ra-core/src/controller/saveContext/SaveContext.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { createContext } from 'react';
import {
RaRecord,
OnError,
OnSuccess,
TransformData,
MutationMode,
} from '../../types';
import { OnError, OnSuccess, TransformData, MutationMode } from '../../types';
import { Middleware } from './useMutationMiddlewares';
import { UseMutationOptions } from '@tanstack/react-query';

export interface SaveContextValue<
RecordType extends RaRecord = any,
RecordType = any,
MutateFunc extends (...args: any[]) => any = (...args: any[]) => any,
ErrorType = Error,
ResultRecordType = RecordType,
> {
save?: SaveHandler<RecordType>;
save?: SaveHandler<RecordType, ErrorType, ResultRecordType>;
/**
* @deprecated. Rely on the form isSubmitting value instead
*/
Expand All @@ -23,17 +19,21 @@ export interface SaveContextValue<
unregisterMutationMiddleware?: (callback: Middleware<MutateFunc>) => void;
}

export type SaveHandler<RecordType, ErrorType = Error> = (
export type SaveHandler<
RecordType,
ErrorType = Error,
ResultRecordType = RecordType,
> = (
record: Partial<RecordType>,
callbacks?: SaveHandlerCallbacks<RecordType, ErrorType>
callbacks?: SaveHandlerCallbacks<ResultRecordType, ErrorType>
) => Promise<void | RecordType> | Record<string, string>;

export type SaveHandlerCallbacks<
RecordType = any,
ResultRecordType = any,
ErrorType = Error,
TVariables = any,
> = Omit<
UseMutationOptions<RecordType, ErrorType, TVariables>,
UseMutationOptions<ResultRecordType, ErrorType, TVariables>,
'mutationFn'
> & {
onSuccess?: OnSuccess;
Expand Down

0 comments on commit 6c4fd3e

Please sign in to comment.