Skip to content

Commit

Permalink
mode releaseAccess logic into ReleaseAccessModal (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jan 24, 2025
1 parent a6bd682 commit 7df7141
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
20 changes: 1 addition & 19 deletions ui100/src/AccessPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ const AccessPanel = ({ access }: AccessPanelProps) => {
setReleaseAccessOpen(false);
}

const releaseAccess = () => {
if(detail && detail.token) {
let cfg = new Configuration({
headers: {
"X-TOKEN": user.token
}
});
let shareApi = new ShareApi(cfg);
shareApi.unaccess({body: {frontendToken: detail.token, envZId: access.data.envZId as string, shrToken: detail.shrToken}})
.then(d => {
setReleaseAccessOpen(false);
})
.catch(e => {
console.log("releaseAccess", e);
});
}
}

useEffect(() => {
let cfg = new Configuration({
headers: {
Expand Down Expand Up @@ -98,7 +80,7 @@ const AccessPanel = ({ access }: AccessPanelProps) => {
</Grid2>
</Grid2>
</Typography>
<ReleaseAccessModal close={closeReleaseAccess} isOpen={releaseAccessOpen} detail={detail} action={releaseAccess} />
<ReleaseAccessModal close={closeReleaseAccess} isOpen={releaseAccessOpen} user={user} access={access} detail={detail} />
</>
);
}
Expand Down
31 changes: 27 additions & 4 deletions ui100/src/ReleaseAccessModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {Frontend} from "./api";
import {Configuration, Frontend, 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 ReleaseAccessProps {
close: () => void;
isOpen: boolean;
user: User;
access: Node;
detail: Frontend;
action: () => void;
}

const ReleaseAccessModal = ({ close, isOpen, detail, action }: ReleaseAccessProps) => {
const ReleaseAccessModal = ({ close, isOpen, user, access, detail }: ReleaseAccessProps) => {
const [feToken, setFeToken] = useState<String>("");
const [checked, setChecked] = useState<boolean>(false);
const checkedRef = useRef<boolean>(checked);
Expand All @@ -29,6 +32,26 @@ const ReleaseAccessModal = ({ close, isOpen, detail, action }: ReleaseAccessProp
}
}, [detail]);

const releaseAccess = () => {
if(detail && detail.token) {
let cfg = new Configuration({
headers: {
"X-TOKEN": user.token
}
});
let shareApi = new ShareApi(cfg);
shareApi.unaccess({body: {frontendToken: detail.token, envZId: access.data.envZId as string, shrToken: detail.shrToken}})
.then(d => {
close();
})
.catch(e => {
e.response.json().then(ex => {
console.log("releaseAccess", ex.message);
});
});
}
}

return (
<Modal open={isOpen} onClose={close}>
<Box sx={{ ...modalStyle }}>
Expand All @@ -42,7 +65,7 @@ const ReleaseAccessModal = ({ close, isOpen, detail, action }: ReleaseAccessProp
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{feToken}</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={releaseAccess}>Release</Button>
</Grid2>
</Box>
</Modal>
Expand Down
2 changes: 1 addition & 1 deletion ui100/src/ReleaseEnvironmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ReleaseEnvironmentModal = ({ close, isOpen, user, environment, detail }: R
.catch(e => {
e.response.json().then(ex => {
console.log("releaseEnvironment", ex.message);
})
});
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion ui100/src/ReleaseShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const ReleaseShareModal = ({ close, isOpen, user, share, detail }: ReleaseShareP
close();
})
.catch(e => {
console.log("releaseShare", e);
e.response.json().then(ex => {
console.log("releaseShare", ex.message);
});
});
}
}
Expand Down

0 comments on commit 7df7141

Please sign in to comment.