Forked from adylevy/DeleteButtonWithConfirmation.js
Last active
December 17, 2020 17:15
-
-
Save te-online/9b7cd7d81ecd47f56f2191121031cc9f to your computer and use it in GitHub Desktop.
react-admin delete button with confirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage | |
import React from 'react'; | |
import { List, Datagrid, TextField } from 'react-admin'; | |
import DeleteButtonWithConfirmation from './DeleteButtonWithConfirmation'; | |
export const ItemList = props => { | |
return ( | |
<List {...props} perPage={100} bulkActions={false} sort={{ field: 'date', order: 'DESC' }}> | |
<Datagrid> | |
<TextField source="itemDate" linkType="show" /> | |
<TextField sortable={false} source="itemName" /> | |
<DeleteButtonWithConfirmation undoable={false} titleSource="itemName" /> | |
</Datagrid> | |
</List> | |
); | |
}; |
@thatshailesh I added a small component showing the usage. Hope it helps.
Awesome, thank you so much
Very good!
unless I'm missing something, what's wrong with just doing this ?
import React from 'react';
import { DeleteButton } from 'react-admin';
const CustomDeleteButton = ({ type = 'Item', field, ...props }) => {
const { record } = props;
return (
<DeleteButton
confirmTitle={`Delete ${type}: ${field ? record[field] : 'this item'} ?`}
confirmContent={'Are you sure you want to delete this item?'}
{...props}
/>
);
}
export default CustomDeleteButton;
and then just use this in place of a DeleteButton in your list/form
<CustomDeleteButton basePath="/customers" undoable={false} type="Customer" field="cus_name" />
obviously type/field are my way to make it usable across my entire admin site
@AndreLorenz If this is a new property on DeleteButton
then it does just the same! When I wrote this gist, those confirm*
properties probably didn't exist yet 😉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can anyone share the usage please? how to use