mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 17:58:50 +02: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]);
|
}, [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography component="div">
|
<Typography component="div">
|
||||||
@ -97,7 +78,7 @@ const EnvironmentPanel = ({environment}: EnvironmentPanelProps) => {
|
|||||||
</Grid2>
|
</Grid2>
|
||||||
</Grid2>
|
</Grid2>
|
||||||
</Typography>
|
</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 {useEffect, useRef, useState} from "react";
|
||||||
import {Box, Button, Checkbox, FormControlLabel, Grid2, Modal, Typography} from "@mui/material";
|
import {Box, Button, Checkbox, FormControlLabel, Grid2, Modal, Typography} from "@mui/material";
|
||||||
import {modalStyle} from "./styling/theme.ts";
|
import {modalStyle} from "./styling/theme.ts";
|
||||||
|
import {User} from "./model/user.ts";
|
||||||
|
import {Node} from "@xyflow/react";
|
||||||
|
|
||||||
interface ReleaseEnvironmentProps {
|
interface ReleaseEnvironmentProps {
|
||||||
close: () => void;
|
close: () => void;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
user: User;
|
||||||
|
environment: Node;
|
||||||
detail: Environment;
|
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 [description, setDescription] = useState<String>("");
|
||||||
const [checked, setChecked] = useState<boolean>(false);
|
const [checked, setChecked] = useState<boolean>(false);
|
||||||
const checkedRef = useRef<boolean>();
|
const checkedRef = useRef<boolean>();
|
||||||
checkedRef.current = checked;
|
checkedRef.current = checked;
|
||||||
|
|
||||||
const toggleChecked = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const toggleChecked = () => {
|
||||||
setChecked(!checkedRef.current);
|
setChecked(!checkedRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +33,27 @@ const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvir
|
|||||||
}
|
}
|
||||||
}, [detail]);
|
}, [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 (
|
return (
|
||||||
<Modal open={isOpen} onClose={close}>
|
<Modal open={isOpen} onClose={close}>
|
||||||
<Box sx={{ ...modalStyle }}>
|
<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 }} />
|
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{description}</code></p>} sx={{ mt: 2 }} />
|
||||||
</Grid2>
|
</Grid2>
|
||||||
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
|
<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>
|
</Grid2>
|
||||||
</Box>
|
</Box>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user