Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Fix Confirm dialog loading bug #3647

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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