Skip to content

Commit

Permalink
Show a confirmation modal on reset changes and move reset changes but…
Browse files Browse the repository at this point in the history
…ton to next to the right
  • Loading branch information
emmatown committed May 25, 2022
1 parent e052769 commit b59c789
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-snakes-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

The reset changes button on the item view now presents a confirmation modal before resetting changes and it has been moved to the right of the bottom bar so it is next to the delete button.
Original file line number Diff line number Diff line change
Expand Up @@ -554,31 +554,63 @@ const Toolbar = memo(function Toolbar({
zIndex: 20,
}}
>
<Button
isDisabled={!hasChangedFields}
isLoading={loading}
weight="bold"
tone="active"
onClick={onSave}
>
Save changes
</Button>
<Stack align="center" across gap="small">
<Button
isDisabled={!hasChangedFields}
isLoading={loading}
weight="bold"
tone="active"
onClick={onSave}
>
Save changes
</Button>
{hasChangedFields ? (
<Button weight="none" onClick={onReset}>
Reset changes
</Button>
<ResetChangesButton onReset={onReset} />
) : (
<Text weight="medium" paddingX="large" color="neutral600">
No changes
</Text>
)}
{deleteButton}
</Stack>
{deleteButton}
</div>
);
});

function ResetChangesButton(props: { onReset: () => void }) {
const [isConfirmModalOpen, setConfirmModalOpen] = useState(false);

return (
<Fragment>
<Button
weight="none"
onClick={() => {
setConfirmModalOpen(true);
}}
>
Reset changes
</Button>
<AlertDialog
actions={{
confirm: {
action: () => props.onReset(),
label: 'Reset changes',
},
cancel: {
action: () => setConfirmModalOpen(false),
label: 'Cancel',
},
}}
isOpen={isConfirmModalOpen}
title="Are you sure you want to reset changes?"
tone="negative"
>
{null}
</AlertDialog>
</Fragment>
);
}

const ColumnLayout = (props: HTMLAttributes<HTMLDivElement>) => {
const { spacing } = useTheme();

Expand Down

0 comments on commit b59c789

Please sign in to comment.