mirror of
https://github.com/openziti/zrok.git
synced 2025-02-12 08:19:59 +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 {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 ReleaseShareProps {
|
interface ReleaseShareProps {
|
||||||
close: () => void;
|
close: () => void;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
user: User;
|
||||||
|
share: Node;
|
||||||
detail: Share;
|
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 [token, setToken] = useState<String>("");
|
||||||
const [checked, setChecked] = useState<boolean>(false);
|
const [checked, setChecked] = useState<boolean>(false);
|
||||||
const checkedRef = useRef<boolean>();
|
const checkedRef = useRef<boolean>();
|
||||||
@ -30,6 +33,24 @@ const ReleaseShareModal = ({ close, isOpen, detail, action }: ReleaseShareProps)
|
|||||||
}
|
}
|
||||||
}, [detail]);
|
}, [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 (
|
return (
|
||||||
<Modal open={isOpen} onClose={close}>
|
<Modal open={isOpen} onClose={close}>
|
||||||
<Box sx={{ ...modalStyle }}>
|
<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 }} />
|
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{token}</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={releaseShare}>Release</Button>
|
||||||
</Grid2>
|
</Grid2>
|
||||||
</Box>
|
</Box>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {Node} from "@xyflow/react";
|
import {Node} from "@xyflow/react";
|
||||||
import {Button, Grid2, Tooltip, Typography} from "@mui/material";
|
import {Button, Grid2, Tooltip, Typography} from "@mui/material";
|
||||||
import ShareIcon from "@mui/icons-material/Share";
|
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 {useEffect, useState} from "react";
|
||||||
import PropertyTable from "./PropertyTable.tsx";
|
import PropertyTable from "./PropertyTable.tsx";
|
||||||
import useStore from "./model/store.ts";
|
import useStore from "./model/store.ts";
|
||||||
@ -62,24 +62,6 @@ const SharePanel = ({ share }: SharePanelProps) => {
|
|||||||
})
|
})
|
||||||
}, [share]);
|
}, [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography component="div">
|
<Typography component="div">
|
||||||
@ -101,7 +83,7 @@ const SharePanel = ({ share }: SharePanelProps) => {
|
|||||||
</Grid2>
|
</Grid2>
|
||||||
</Grid2>
|
</Grid2>
|
||||||
</Typography>
|
</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