Add token creation dialog
This commit is contained in:
98
matrixgw_frontend/src/routes/APITokensRoute.tsx
Normal file
98
matrixgw_frontend/src/routes/APITokensRoute.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import RefreshIcon from "@mui/icons-material/Refresh";
|
||||
import { Alert, AlertTitle, IconButton, Tooltip } from "@mui/material";
|
||||
import { MatrixGWRouteContainer } from "../widgets/MatrixGWRouteContainer";
|
||||
import React from "react";
|
||||
import { CreateTokenDialog } from "../dialogs/CreateTokenDialog";
|
||||
import { type TokenWithSecret } from "../api/TokensApi";
|
||||
import { APIClient } from "../api/ApiClient";
|
||||
import { QRCodeCanvas } from "qrcode.react";
|
||||
import { CopyTextChip } from "../widgets/CopyTextChip";
|
||||
|
||||
export function APITokensRoute(): React.ReactElement {
|
||||
const [openCreateTokenDialog, setOpenCreateTokenDialog] =
|
||||
React.useState(false);
|
||||
|
||||
const [createdToken, setCreatedToken] =
|
||||
React.useState<TokenWithSecret | null>(null);
|
||||
|
||||
const handleRefreshTokensList = () => {
|
||||
//throw new Error("todo");
|
||||
};
|
||||
|
||||
const handleOpenCreateTokenDialog = () => setOpenCreateTokenDialog(true);
|
||||
|
||||
const handleCancelCreateToken = () => setOpenCreateTokenDialog(false);
|
||||
|
||||
const handleCreatedToken = (s: TokenWithSecret) => {
|
||||
setCreatedToken(s);
|
||||
setOpenCreateTokenDialog(false);
|
||||
handleRefreshTokensList();
|
||||
};
|
||||
|
||||
return (
|
||||
<MatrixGWRouteContainer
|
||||
label={"API tokens"}
|
||||
actions={
|
||||
<span>
|
||||
<Tooltip title="Create new token">
|
||||
<IconButton onClick={handleOpenCreateTokenDialog}>
|
||||
<AddIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title="Refresh tokens list">
|
||||
<IconButton onClick={handleRefreshTokensList}>
|
||||
<RefreshIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<CreateTokenDialog
|
||||
open={openCreateTokenDialog}
|
||||
onCreated={handleCreatedToken}
|
||||
onClose={handleCancelCreateToken}
|
||||
/>
|
||||
{createdToken && <CreatedToken token={createdToken!} />}
|
||||
<p>TODO list</p>
|
||||
</MatrixGWRouteContainer>
|
||||
);
|
||||
}
|
||||
|
||||
function CreatedToken(p: { token: TokenWithSecret }): React.ReactElement {
|
||||
return (
|
||||
<Alert severity="success" style={{ margin: "10px" }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
}}
|
||||
>
|
||||
<div style={{ textAlign: "center", marginRight: "10px" }}>
|
||||
<div style={{ padding: "15px", backgroundColor: "white" }}>
|
||||
<QRCodeCanvas
|
||||
value={`matrixgw://api=${encodeURIComponent(
|
||||
APIClient.ActualBackendURL()
|
||||
)}&id=${p.token.id}&secret=${p.token.secret}`}
|
||||
/>
|
||||
</div>
|
||||
<br />
|
||||
<em>Mobile App Qr Code</em>
|
||||
</div>
|
||||
<div>
|
||||
<AlertTitle>Token successfully created</AlertTitle>
|
||||
The API token <i>{p.token.name}</i> was successfully created. Please
|
||||
note the following information as they won't be available after.
|
||||
<br />
|
||||
<br />
|
||||
API URL: <CopyTextChip text={APIClient.ActualBackendURL()} />
|
||||
<br />
|
||||
Token ID: <CopyTextChip text={p.token.id.toString()} />
|
||||
<br />
|
||||
Token secret: <CopyTextChip text={p.token.secret} />
|
||||
</div>
|
||||
</div>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user