mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-28 16:06:41 +01:00
fix ConfirmDialog state persisting
This commit is contained in:
@@ -59,9 +59,8 @@ export type ConfirmDialogProps = {
|
||||
*/
|
||||
export const confirmDialogAtom = atom(
|
||||
{ open: false } as ConfirmDialogProps,
|
||||
(get, set, update: Partial<ConfirmDialogProps>) => {
|
||||
(_, set, update: Partial<ConfirmDialogProps>) => {
|
||||
set(confirmDialogAtom, {
|
||||
...get(confirmDialogAtom),
|
||||
open: true, // Don’t require this to be set explicitly
|
||||
...update,
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
TextField,
|
||||
Button,
|
||||
} from "@mui/material";
|
||||
import MemoizedText from "@src/components/Modal/MemoizedText";
|
||||
|
||||
import { projectScope, confirmDialogAtom } from "@src/atoms/projectScope";
|
||||
|
||||
@@ -63,62 +64,66 @@ export default function ConfirmDialog({
|
||||
maxWidth={maxWidth}
|
||||
sx={{ cursor: "default", zIndex: (theme) => theme.zIndex.modal + 50 }}
|
||||
>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<MemoizedText>
|
||||
<>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
|
||||
<DialogContent>
|
||||
{typeof body === "string" ? (
|
||||
<DialogContentText>{body}</DialogContentText>
|
||||
) : (
|
||||
body
|
||||
)}
|
||||
{confirmationCommand && (
|
||||
<TextField
|
||||
value={dryText}
|
||||
onChange={(e) => setDryText(e.target.value)}
|
||||
autoFocus
|
||||
label={`Type “${confirmationCommand}” below to continue:`}
|
||||
placeholder={confirmationCommand}
|
||||
fullWidth
|
||||
id="dryText"
|
||||
sx={{ mt: 3 }}
|
||||
/>
|
||||
)}
|
||||
</DialogContent>
|
||||
<DialogContent>
|
||||
{typeof body === "string" ? (
|
||||
<DialogContentText>{body}</DialogContentText>
|
||||
) : (
|
||||
body
|
||||
)}
|
||||
{confirmationCommand && (
|
||||
<TextField
|
||||
value={dryText}
|
||||
onChange={(e) => setDryText(e.target.value)}
|
||||
autoFocus
|
||||
label={`Type “${confirmationCommand}” below to continue:`}
|
||||
placeholder={confirmationCommand}
|
||||
fullWidth
|
||||
id="dryText"
|
||||
sx={{ mt: 3 }}
|
||||
/>
|
||||
)}
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions
|
||||
sx={[
|
||||
buttonLayout === "vertical" && {
|
||||
flexDirection: "column",
|
||||
alignItems: "stretch",
|
||||
"& > :not(:first-of-type)": { ml: 0, mt: 1 },
|
||||
},
|
||||
]}
|
||||
>
|
||||
{!hideCancel && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (handleCancel) handleCancel();
|
||||
handleClose();
|
||||
}}
|
||||
<DialogActions
|
||||
sx={[
|
||||
buttonLayout === "vertical" && {
|
||||
flexDirection: "column",
|
||||
alignItems: "stretch",
|
||||
"& > :not(:first-of-type)": { ml: 0, mt: 1 },
|
||||
},
|
||||
]}
|
||||
>
|
||||
{cancel}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (handleConfirm) handleConfirm();
|
||||
handleClose();
|
||||
}}
|
||||
color={confirmColor || "primary"}
|
||||
variant="contained"
|
||||
autoFocus
|
||||
disabled={
|
||||
confirmationCommand ? dryText !== confirmationCommand : false
|
||||
}
|
||||
>
|
||||
{confirm}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
{!hideCancel && (
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (handleCancel) handleCancel();
|
||||
handleClose();
|
||||
}}
|
||||
>
|
||||
{cancel}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (handleConfirm) handleConfirm();
|
||||
handleClose();
|
||||
}}
|
||||
color={confirmColor || "primary"}
|
||||
variant="contained"
|
||||
autoFocus
|
||||
disabled={
|
||||
confirmationCommand ? dryText !== confirmationCommand : false
|
||||
}
|
||||
>
|
||||
{confirm}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</>
|
||||
</MemoizedText>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user