Skip to content

Commit

Permalink
Fix Confirm dialog loading bug
Browse files Browse the repository at this point in the history
Closes #3241, #3645
  • Loading branch information
fzaninotto committed Sep 3, 2019
1 parent f9d80e1 commit 76de140
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ const ResetViewsButton = ({ selectedIds }) => {
<Button label="Reset Views" onClick={handleClick} />
<Confirm
isOpen={open}
loading={loading}
title="Update View Count"
content="Are you sure you want to reset the views for these items?"
onConfirm={handleConfirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const BulkDeleteWithConfirmButton = ({
const unselectAll = useUnselectAll();
const refresh = useRefresh();
const translate = useTranslate();
const [deleteMany] = useDeleteMany(resource, selectedIds, {
const [deleteMany, { loading }] = useDeleteMany(resource, selectedIds, {
onSuccess: () => {
refresh();
notify('ra.notification.deleted', 'info', {
Expand Down Expand Up @@ -102,6 +102,7 @@ const BulkDeleteWithConfirmButton = ({
</Button>
<Confirm
isOpen={isOpen}
loading={loading}
title="ra.message.bulk_delete_title"
content="ra.message.bulk_delete_content"
translateOptions={{
Expand All @@ -124,7 +125,6 @@ const BulkDeleteWithConfirmButton = ({
BulkDeleteWithConfirmButton.propTypes = {
basePath: PropTypes.string,
classes: PropTypes.object,
crudDeleteMany: PropTypes.func.isRequired,
label: PropTypes.string,
resource: PropTypes.string.isRequired,
selectedIds: PropTypes.arrayOf(PropTypes.any).isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const DeleteWithConfirmButton = ({
const redirect = useRedirect();
const refresh = useRefresh();
const classes = useStyles({ classes: classesOverride });
const [deleteOne] = useDelete(resource, record.id, record, {
const [deleteOne, { loading }] = useDelete(resource, record.id, record, {
onSuccess: () => {
notify('ra.notification.deleted', 'info', { smart_count: 1 });
redirect(redirectTo, basePath);
Expand Down Expand Up @@ -114,6 +114,7 @@ const DeleteWithConfirmButton = ({
</Button>
<Confirm
isOpen={open}
loading={loading}
title="ra.message.delete_title"
content="ra.message.delete_content"
translateOptions={{
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-ui-materialui/src/layout/Confirm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
Expand Down Expand Up @@ -52,6 +52,7 @@ const useStyles = makeStyles(theme => ({
*/
const Confirm = ({
isOpen,
loading,
title,
content,
confirm,
Expand All @@ -63,13 +64,11 @@ const Confirm = ({
translateOptions = {},
}) => {
const classes = useStyles({ classes: classesOverride });
const [loading, setLoading] = useState(false);
const translate = useTranslate();

const handleConfirm = useCallback(
e => {
e.stopPropagation();
setLoading(true);
onConfirm();
},
[onConfirm]
Expand Down Expand Up @@ -126,6 +125,7 @@ Confirm.propTypes = {
confirmColor: PropTypes.string.isRequired,
content: PropTypes.string.isRequired,
isOpen: PropTypes.bool,
loading: PropTypes.bool,
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
Expand Down

0 comments on commit 76de140

Please sign in to comment.