-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split out ReleaseEnvironmentModal (#724)
- Loading branch information
1 parent
a2f8cac
commit edc3d08
Showing
2 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {Environment} 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 ReleaseEnvironmentProps { | ||
close: () => void; | ||
isOpen: boolean; | ||
detail: Environment; | ||
action: () => void; | ||
} | ||
|
||
const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvironmentProps) => { | ||
const [description, setDescription] = 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.description) { | ||
setDescription(detail.description); | ||
} | ||
}, [detail]); | ||
|
||
return ( | ||
<Modal open={isOpen} onClose={close}> | ||
<Box sx={{ ...modalStyle }}> | ||
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center"> | ||
<Typography variant="h5"><strong>Release Environment</strong></Typography> | ||
</Grid2> | ||
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center"> | ||
<Typography variant="body1">Would you like to release the environment <code>{description}</code> ?</Typography> | ||
</Grid2> | ||
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center"> | ||
<Typography variant="body1">Releasing this environment will also release any shares and accesses that are associated with it.</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>{description}</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 ReleaseEnvironmentModal; |