mirror of
https://github.com/openziti/zrok.git
synced 2025-06-24 19:51:32 +02:00
error handling in ReleaseAccessModal (#837)
This commit is contained in:
parent
f962a7d253
commit
efbf713816
@ -15,6 +15,7 @@ interface ReleaseAccessProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ReleaseAccessModal = ({ close, isOpen, user, access, detail }: ReleaseAccessProps) => {
|
const ReleaseAccessModal = ({ close, isOpen, user, access, detail }: ReleaseAccessProps) => {
|
||||||
|
const [errorMessage, setErrorMessage] = useState<React.JSX.Element>(null);
|
||||||
const [feToken, setFeToken] = useState<String>("");
|
const [feToken, setFeToken] = useState<String>("");
|
||||||
const [checked, setChecked] = useState<boolean>(false);
|
const [checked, setChecked] = useState<boolean>(false);
|
||||||
const checkedRef = useRef<boolean>(checked);
|
const checkedRef = useRef<boolean>(checked);
|
||||||
@ -34,20 +35,24 @@ const ReleaseAccessModal = ({ close, isOpen, user, access, detail }: ReleaseAcce
|
|||||||
}, [detail]);
|
}, [detail]);
|
||||||
|
|
||||||
const releaseAccess = () => {
|
const releaseAccess = () => {
|
||||||
|
setErrorMessage(null);
|
||||||
if(detail && detail.token) {
|
if(detail && detail.token) {
|
||||||
getShareApi(user).unaccess({
|
getShareApi(user).unaccess({
|
||||||
body: {
|
body: {
|
||||||
frontendToken: detail.token,
|
frontendToken: detail.token,
|
||||||
envZId: access.data.envZId as string,
|
envZId: access.data.envZId as string,
|
||||||
shrToken: detail.shrToken}
|
shrToken: detail.shrToken
|
||||||
})
|
}
|
||||||
.then(d => {
|
})
|
||||||
|
.then(() => {
|
||||||
close();
|
close();
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
e.response.json().then(ex => {
|
e.response.json().then(ex => {
|
||||||
console.log("releaseAccess", ex.message);
|
console.log("releaseAccess", ex.message);
|
||||||
});
|
});
|
||||||
|
setErrorMessage(<Typography color="red">An error occurred releasing your share <code>{detail.token}</code>!</Typography>);
|
||||||
|
setTimeout(() => { setErrorMessage(null); }, 2000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,6 +69,7 @@ const ReleaseAccessModal = ({ close, isOpen, user, access, detail }: ReleaseAcce
|
|||||||
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
|
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
|
||||||
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{feToken}</code></p>} sx={{ mt: 2 }} />
|
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{feToken}</code></p>} sx={{ mt: 2 }} />
|
||||||
</Grid2>
|
</Grid2>
|
||||||
|
{ errorMessage ? <Grid2 container sx={{ mb: 2, p: 1}}><Typography>{errorMessage}</Typography></Grid2> : null}
|
||||||
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
|
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
|
||||||
<Button color="error" variant="contained" disabled={!checked} onClick={releaseAccess}>Release</Button>
|
<Button color="error" variant="contained" disabled={!checked} onClick={releaseAccess}>Release</Button>
|
||||||
</Grid2>
|
</Grid2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user