mirror of
https://github.com/openziti/zrok.git
synced 2025-02-07 13:59:47 +01:00
move release share logic into ReleaseShareModal (#822)
This commit is contained in:
parent
62e78eb3bc
commit
3857899d6f
@ -1,16 +1,19 @@
|
||||
import {Share} from "./api";
|
||||
import {Configuration, Share, ShareApi} 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 ReleaseShareProps {
|
||||
close: () => void;
|
||||
isOpen: boolean;
|
||||
user: User;
|
||||
share: Node;
|
||||
detail: Share;
|
||||
action: () => void;
|
||||
}
|
||||
|
||||
const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps) => {
|
||||
const ReleaseShareModal = ({ close, isOpen, user, share, detail }: ReleaseShareProps) => {
|
||||
const [token, setToken] = useState<String>("");
|
||||
const [checked, setChecked] = useState<boolean>(false);
|
||||
const checkedRef = useRef<boolean>();
|
||||
@ -30,6 +33,24 @@ const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps)
|
||||
}
|
||||
}, [detail]);
|
||||
|
||||
const releaseShare = () => {
|
||||
if(detail) {
|
||||
let cfg = new Configuration({
|
||||
headers: {
|
||||
"X-TOKEN": user.token
|
||||
}
|
||||
});
|
||||
let shareApi = new ShareApi(cfg);
|
||||
shareApi.unshare({body: {envZId: share.data.envZId as string, shrToken: detail.token, reserved: detail.reserved}})
|
||||
.then(d => {
|
||||
close();
|
||||
})
|
||||
.catch(e => {
|
||||
console.log("releaseShare", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal open={isOpen} onClose={close}>
|
||||
<Box sx={{ ...modalStyle }}>
|
||||
@ -43,7 +64,7 @@ const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps)
|
||||
<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>
|
||||
<Button color="error" variant="contained" disabled={!checked} onClick={releaseShare}>Release</Button>
|
||||
</Grid2>
|
||||
</Box>
|
||||
</Modal>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Node} from "@xyflow/react";
|
||||
import {Button, Grid2, Tooltip, Typography} from "@mui/material";
|
||||
import ShareIcon from "@mui/icons-material/Share";
|
||||
import {Configuration, MetadataApi, Share, ShareApi} from "./api";
|
||||
import {Configuration, MetadataApi, Share} from "./api";
|
||||
import {useEffect, useState} from "react";
|
||||
import PropertyTable from "./PropertyTable.tsx";
|
||||
import useStore from "./model/store.ts";
|
||||
@ -62,24 +62,6 @@ const SharePanel = ({ share }: SharePanelProps) => {
|
||||
})
|
||||
}, [share]);
|
||||
|
||||
const releaseShare = () => {
|
||||
if(detail) {
|
||||
let cfg = new Configuration({
|
||||
headers: {
|
||||
"X-TOKEN": user.token
|
||||
}
|
||||
});
|
||||
let shareApi = new ShareApi(cfg);
|
||||
shareApi.unshare({body: {envZId: share.data.envZId as string, shrToken: detail.token, reserved: detail.reserved}})
|
||||
.then(d => {
|
||||
setReleaseShareOpen(false);
|
||||
})
|
||||
.catch(e => {
|
||||
console.log("releaseShare", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Typography component="div">
|
||||
@ -101,7 +83,7 @@ const SharePanel = ({ share }: SharePanelProps) => {
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
</Typography>
|
||||
<ReleaseShareModal close={closeReleaseShare} isOpen={releaseShareOpen} detail={detail} action={releaseShare} />
|
||||
<ReleaseShareModal close={closeReleaseShare} isOpen={releaseShareOpen} user={user} share={share} detail={detail} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user