copy enable command (#72)

This commit is contained in:
Michael Quigley 2022-10-26 13:31:38 -04:00
parent 0b13ec7bd4
commit 447bb2ae90
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -1,8 +1,7 @@
import Icon from "@mdi/react"; import Icon from "@mdi/react";
import {mdiKey} from "@mdi/js"; import {mdiKey, mdiContentCopy} from "@mdi/js";
import Popover from "@mui/material/Popover"; import Popover from "@mui/material/Popover";
import {useState} from "react"; import {useState} from "react";
import Copy from "./Copy";
const Token = (props) => { const Token = (props) => {
const [anchorEl, setAnchorEl] = useState(null); const [anchorEl, setAnchorEl] = useState(null);
@ -17,6 +16,15 @@ const Token = (props) => {
const popoverId = popoverOpen ? 'token-popover' : undefined; const popoverId = popoverOpen ? 'token-popover' : undefined;
const text = "zrok enable " + props.user.token const text = "zrok enable " + props.user.token
const handleCopy = async () => {
let copiedText = document.getElementById("zrok-enable-command").innerHTML;
try {
await navigator.clipboard.writeText(copiedText);
console.log("copied enable command");
} catch(err) {
console.error("failed to copy", err);
}
}
return ( return (
<div> <div>
@ -34,7 +42,7 @@ const Token = (props) => {
<div className={"popover"}> <div className={"popover"}>
<h3>Enable zrok access in your shell:</h3> <h3>Enable zrok access in your shell:</h3>
<pre> <pre>
{text} <Copy text={text}/> $ <span id={"zrok-enable-command"}>{text}</span> <Icon path={mdiContentCopy} size={0.7} onClick={handleCopy}/>
</pre> </pre>
</div> </div>
</Popover> </Popover>