Dialog popup works

This commit is contained in:
2025-08-12 09:55:57 -07:00
parent f8c9a0cc0b
commit f85c64e7f0
2 changed files with 41 additions and 8 deletions
@@ -0,0 +1,33 @@
import { Dialog, Portal, CloseButton, Button } from "@chakra-ui/react";
export default function DialogPopup({dialog}) {
console.log("3. dialog popup")
return(
<Dialog.RootProvider value={dialog}>
<Portal>
<Dialog.Backdrop />
<Dialog.Positioner>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Leave Your Changes Behind?</Dialog.Title>
</Dialog.Header>
<Dialog.Body>
<p>
Click 'No' to go back and save your changes before navigating away from MyDashboard.
</p>
</Dialog.Body>
<Dialog.Footer>
<Dialog.ActionTrigger asChild>
<Button variant="outline">No</Button>
</Dialog.ActionTrigger>
<Button bg="tomato">Yes</Button>
</Dialog.Footer>
<Dialog.CloseTrigger asChild>
<CloseButton size="sm" />
</Dialog.CloseTrigger>
</Dialog.Content>
</Dialog.Positioner>
</Portal>
</Dialog.RootProvider>
);
}
+8 -8
View File
@@ -34,15 +34,12 @@ export default function Dashboard() {
// Prevent navigation while in Edit mode without saving or cancelling // Prevent navigation while in Edit mode without saving or cancelling
const handleViewChange = (nextView) => { const handleViewChange = (nextView) => {
console.log("1. handling view change")
if (view === "mydashboard" && isEditable) { if (view === "mydashboard" && isEditable) {
dialog.open(); console.log("2. currently editing");
<DialogPopup dialog={dialog}/> dialog.setOpen(true);
return;
// const confirmed = window.confirm( // const confirmed = window.confirm(
// "You have unsaved changes. Discard them and continue?" // "You have unsaved changes. Discard them and continue?"
// ); // );
@@ -62,6 +59,8 @@ export default function Dashboard() {
const headerProps = { onChangeView: handleViewChange }; const headerProps = { onChangeView: handleViewChange };
return ( return (
<>
<DialogPopup dialog={dialog} />
<Grid css={styles} <Grid css={styles}
templateRows="1fr 11fr" templateRows="1fr 11fr"
// templateColumns="1fr 20fr" // templateColumns="1fr 20fr"
@@ -79,5 +78,6 @@ export default function Dashboard() {
<Canvas {...canvasProps}/> <Canvas {...canvasProps}/>
</GridItem> </GridItem>
</Grid> </Grid>
</>
); );
} }