mirror of
https://github.com/openziti/zrok.git
synced 2025-03-13 15:08:21 +01:00
move releaseEnvironment logic into ReleaseEnvironmentModal (#822)
This commit is contained in:
parent
3a71848ba8
commit
a6bd6828fe
@ -57,25 +57,6 @@ const EnvironmentPanel = ({environment}: EnvironmentPanelProps) => {
|
||||
})
|
||||
}, [environment]);
|
||||
|
||||
const releaseEnvironment = () => {
|
||||
if(environment.data && environment.data.envZId) {
|
||||
console.log("releasing");
|
||||
let cfg = new Configuration({
|
||||
headers: {
|
||||
"X-TOKEN": user.token
|
||||
}
|
||||
});
|
||||
let environmentApi = new EnvironmentApi(cfg);
|
||||
environmentApi.disable({body: {identity: environment.data.envZId as string}})
|
||||
.then(d => {
|
||||
setReleaseEnvironmentOpen(false);
|
||||
})
|
||||
.catch(e => {
|
||||
console.log("releaseEnvironment", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Typography component="div">
|
||||
@ -97,7 +78,7 @@ const EnvironmentPanel = ({environment}: EnvironmentPanelProps) => {
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
</Typography>
|
||||
<ReleaseEnvironmentModal close={closeReleaseEnvironment} isOpen={releaseEnvironmentOpen} detail={detail} action={releaseEnvironment} />
|
||||
<ReleaseEnvironmentModal close={closeReleaseEnvironment} isOpen={releaseEnvironmentOpen} user={user} environment={environment} detail={detail} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -1,22 +1,25 @@
|
||||
import {Environment} from "./api";
|
||||
import {Configuration, Environment, EnvironmentApi} 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";
|
||||
import {User} from "./model/user.ts";
|
||||
import {Node} from "@xyflow/react";
|
||||
|
||||
interface ReleaseEnvironmentProps {
|
||||
close: () => void;
|
||||
isOpen: boolean;
|
||||
user: User;
|
||||
environment: Node;
|
||||
detail: Environment;
|
||||
action: () => void;
|
||||
}
|
||||
|
||||
const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvironmentProps) => {
|
||||
const ReleaseEnvironmentModal = ({ close, isOpen, user, environment, detail }: 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>) => {
|
||||
const toggleChecked = () => {
|
||||
setChecked(!checkedRef.current);
|
||||
}
|
||||
|
||||
@ -30,6 +33,27 @@ const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvir
|
||||
}
|
||||
}, [detail]);
|
||||
|
||||
const releaseEnvironment = () => {
|
||||
if(environment.data && environment.data.envZId) {
|
||||
console.log("releasing");
|
||||
let cfg = new Configuration({
|
||||
headers: {
|
||||
"X-TOKEN": user.token
|
||||
}
|
||||
});
|
||||
let environmentApi = new EnvironmentApi(cfg);
|
||||
environmentApi.disable({body: {identity: environment.data.envZId as string}})
|
||||
.then(d => {
|
||||
close();
|
||||
})
|
||||
.catch(e => {
|
||||
e.response.json().then(ex => {
|
||||
console.log("releaseEnvironment", ex.message);
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal open={isOpen} onClose={close}>
|
||||
<Box sx={{ ...modalStyle }}>
|
||||
@ -46,7 +70,7 @@ const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvir
|
||||
<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>
|
||||
<Button color="error" variant="contained" disabled={!checked} onClick={releaseEnvironment}>Release</Button>
|
||||
</Grid2>
|
||||
</Box>
|
||||
</Modal>
|
||||
|
Loading…
Reference in New Issue
Block a user