Skip to content

Commit

Permalink
split out ReleaseShareModal (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jan 24, 2025
1 parent edc3d08 commit 143c4b8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 50 deletions.
53 changes: 53 additions & 0 deletions ui100/src/ReleaseShareModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {Share} from "./api";
import {useEffect, useRef, useState} from "react";
import {Box, Button, Checkbox, FormControlLabel, Grid2, Modal, Typography} from "@mui/material";
import {modalStyle} from "./styling/theme.ts";

interface ReleaseShareProps {
close: () => void;
isOpen: boolean;
detail: Share;
action: () => void;
}

const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps) => {
const [token, setToken] = useState<String>("");
const [checked, setChecked] = useState<boolean>(false);
const checkedRef = useRef<boolean>();
checkedRef.current = checked;

const toggleChecked = () => {
setChecked(!checkedRef.current);
}

useEffect(() => {
setChecked(false);
}, [isOpen]);

useEffect(() => {
if(detail && detail.token) {
setToken(detail.token);
}
}, [detail]);

return (
<Modal open={isOpen} onClose={close}>
<Box sx={{ ...modalStyle }}>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Typography variant="h5"><strong>Release Share</strong></Typography>
</Grid2>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Typography variant="body1">Would you like to release the share <code>{token}</code> ?</Typography>
</Grid2>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{token}</code></p>} sx={{ mt: 2 }} />
</Grid2>
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
<Button color="error" variant="contained" disabled={!checked} onClick={action}>Release</Button>
</Grid2>
</Box>
</Modal>
)
}

export default ReleaseShareModal;
53 changes: 3 additions & 50 deletions ui100/src/SharePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,12 @@
import {Node} from "@xyflow/react";
import {Box, Button, Checkbox, FormControlLabel, Grid2, Modal, Tooltip, Typography} from "@mui/material";
import {Button, Grid2, Tooltip, Typography} from "@mui/material";
import ShareIcon from "@mui/icons-material/Share";
import {Configuration, MetadataApi, Share, ShareApi} from "./api";
import {useEffect, useRef, useState} from "react";
import {useEffect, useState} from "react";
import PropertyTable from "./PropertyTable.tsx";
import useStore from "./model/store.ts";
import DeleteIcon from "@mui/icons-material/Delete";
import {modalStyle} from "./styling/theme.ts";

interface ReleaseShareProps {
close: () => void;
isOpen: boolean;
detail: Share;
action: () => void;
}

const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps) => {
const [token, setToken] = useState<String>("");
const [checked, setChecked] = useState<boolean>(false);
const checkedRef = useRef<boolean>();
checkedRef.current = checked;

const toggleChecked = (event: React.ChangeEvent<HTMLInputElement>) => {
setChecked(!checkedRef.current);
}

useEffect(() => {
setChecked(false);
}, [isOpen]);

useEffect(() => {
if(detail && detail.token) {
setToken(detail.token);
}
}, [detail]);

return (
<Modal open={isOpen} onClose={close}>
<Box sx={{ ...modalStyle }}>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Typography variant="h5"><strong>Release Share</strong></Typography>
</Grid2>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Typography variant="body1">Would you like to release the share <code>{token}</code> ?</Typography>
</Grid2>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{token}</code></p>} sx={{ mt: 2 }} />
</Grid2>
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
<Button color="error" variant="contained" disabled={!checked} onClick={action}>Release</Button>
</Grid2>
</Box>
</Modal>
)
}
import ReleaseShareModal from "./ReleaseShareModal.tsx";

interface SharePanelProps {
share: Node;
Expand Down

0 comments on commit 143c4b8

Please sign in to comment.