github refinedev/refine @refinedev/core@4.28.0

Minor Changes

  • #4652 96af6d25b7a Thanks @alicanerdurmaz! - feat: added errros field to HttpError type.
    From now on, you can pass errors field to HttpError. This field will be used to update the useForm's error state.

    export interface ValidationErrors {
        [field: string]:
            | string
            | string[]
            | boolean
            | { key: string; message: string };
    }
    
    export interface HttpError extends Record<string, any> {
        message: string;
        statusCode: number;
        errors?: ValidationErrors;
    }

    Usage example:

    import { HttpError } from "@refinedev/core";
    
    const App = () => {
        return (
            <Refine
                routerProvider={routerProvider}
                dataProvider={{
                    // ...
                    update: async () => {
                        // assume that the server returns the following error
                        const error: HttpError = {
                            message:
                                "An error occurred while updating the record.",
                            statusCode: 400,
                            //This field will be used to update the `useForm`'s error state
                            errors: {
                                title: [
                                    "Title is required.",
                                    "Title should have at least 5 characters.",
                                ],
                                "category.id": ["Category is required."],
                                status: true,
                                content: {
                                    key: "form.error.content",
                                    message: "Content is required.",
                                },
                            },
                        };
    
                        return Promise.reject(error);
                    },
                }}
            >
                {/* ... */}
            </Refine>
        );
    };

    Refer to the server-side form validation documentation for more information. →

  • #4652 96af6d25b7a Thanks @alicanerdurmaz! - feat: added disableServerSideValidation to the refine options for globally disabling server-side validation.

    import { Refine } from "@refinedev/core";
    
    <Refine
        options={{
            disableServerSideValidation: true,
        }}
    >
        // ...
    </Refine>;
  • #4591 f8891ead2bd Thanks @yildirayunlu! - feat: autoSave feature for useForm hook now accept autoSave object. enabled is a boolean value and debounce is a number value in milliseconds. debounce is optional and default value is 1000.
    autoSaveProps is an object that contains data, error and status values. data is the saved data, error is the error object and status is the status of the request. status can be loading, error, idle and success.

    const { autoSaveProps } = useForm({
        autoSave: {
            enabled: true,
            debounce: 2000, // not required, default is 1000
        },
    });
    

Patch Changes

  • #4659 3af99896101 Thanks @salihozdemir! - chore: fix tsdoc description of onCancel property on following hooks:

    • useUpdate
    • useUpdateMany
    • useDelete
    • useDeleteMany
  • #4665 3442f4bd00a Thanks @yildirayunlu! - feat: add false return type on SuccessErrorNotification

    This issue has been fixed in this PR, where the successNotification and errorNotification methods can now return false when a callback function is given. This allows the conditional notification to be displayed.

    const { mutate } = useCreate<IPost>({});
    
    mutate({
        resource: "posts",
        values: {
            title: "Hello World",
            status: "published",
        },
        successNotification: (data) => {
            if (data?.data.status === "published") {
                return {
                    type: "success",
                    message: "Post published",
                };
            }
    
            return false;
        },
    });
    

Don't miss a new refine release

NewReleases is sending notifications on new releases.