Back to React Admin

The SoftDeleteWithConfirmButton Component

docs/SoftDeleteWithConfirmButton.md

5.14.63.7 KB
Original Source

<SoftDeleteWithConfirmButton>

Soft-deletes the current record after a confirm dialog has been accepted.

Usage

{% raw %}

tsx
import * as React from 'react';
import { Toolbar, Edit, SaveButton, useRecordContext } from 'react-admin';
import { SoftDeleteWithConfirmButton } from '@react-admin/ra-soft-delete';

const EditToolbar = () => {
    const record = useRecordContext();

    return (
        <Toolbar>
            <SaveButton/>
            <SoftDeleteWithConfirmButton
                confirmContent="You will be able to recover this record from the trash."
                confirmColor="warning"
                contentTranslateOptions={{ name: record.name }}
                titleTranslateOptions={{ name: record.name }}
            />
        </Toolbar>
    );
};

const MyEdit = () => (
    <Edit>
        <SimpleForm toolbar={<EditToolbar />}>
            ...
        </SimpleForm>        
    </Edit>    
);

{% endraw %}

Props

PropRequiredTypeDefaultDescription
classNameOptionalstring-Class name to customize the look and feel of the button element itself
confirmTitleOptionalReactNode'ra-soft-delete. message. soft_delete_title'Title of the confirm dialog
confirm ContentOptionalReactNode'ra-soft-delete. message. soft_delete_content'Message or React component to be used as the body of the confirm dialog
confirmColorOptional<code>'primary' | 'warning'</code>'primary'The color of the confirm dialog's "Confirm" button
content Translate OptionsOptionalObject{}Custom id, name and record representation to be used in the confirm dialog's content
iconOptionalReactElement<DeleteIcon>iconElement, e.g. <CommentIcon />
labelOptionalstring'ra-soft-delete. action. soft_delete'label or translation message to use
mutation OptionsOptionalnulloptions for react-query useMutation hook
redirectOptional<code>string | false | Function</code>'list'Custom redirection after success side effect
title Translate OptionsOptionalObject{}Custom id, name and record representation to be used in the confirm dialog's title
success MessageOptionalstring'ra-soft-delete. notification. soft_deleted'Lets you customize the success notification message.