-
{tokenInfo.data.name}
-
{tokenInfo.data.name}
+
{tokenInfo.method.toUpperCase()}
-
+
-
+
Expires on{" "}
- {Intl.DateTimeFormat("en-US", { dateStyle: "long" }).format(
- tokenInfo.data.expirationTime?.toDate(),
- )}
+ {dayjs(tokenInfo.data.expirationTime!.toDate()).format("MMM D, YYYY")}
- •
+ ·
- Created on{" "}
- {Intl.DateTimeFormat("en-US", { dateStyle: "long" }).format(
- tokenInfo.data.createdAt?.toDate(),
- )}
+ Created on {dayjs(tokenInfo.data.createdAt!.toDate()).format("MMM D, YYYY")}
@@ -450,31 +595,84 @@ function ListAccessTokensView() {
>
)}
>
- {tokens.length === 0 ? (
-
-
No Access Tokens
-
- Generate an access token for applications that need access to the Gitpod API.{" "}
-
-
-
New Access Token
-
-
+ {loading ? (
+
) : (
<>
-
-
Token Name
-
Permissions
-
Expires
-
-
- {tokens.map((t: PersonalAccessToken) => {
- return
;
- })}
+ {tokens.length === 0 ? (
+
+
+ No Access Tokens (PAT)
+
+
+ Generate a access token (PAT) for applications that need access to the Gitpod API.{" "}
+
+
+
New Access Token
+
+
+ ) : (
+ <>
+
+
Token Name
+
Permissions
+
Expires
+
+
+ {tokens.map((t: PersonalAccessToken) => (
+
setModalData({ token: t, action: TokenAction.Regerenrate }),
+ },
+ {
+ title: "Delete",
+ href: "",
+ customFontStyle:
+ "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300",
+ onClick: () => setModalData({ token: t, action: TokenAction.Delete }),
+ },
+ ]}
+ />
+ ))}
+ >
+ )}
>
)}
+
+ {modalData?.action === TokenAction.Delete && (
+ handleDeleteToken(modalData.token.id)}
+ onClose={() => setModalData(undefined)}
+ />
+ )}
+ {modalData?.action === TokenAction.Regerenrate && (
+ handleRegenerateToken(modalData.token.id, expirationDate)}
+ onClose={() => setModalData(undefined)}
+ />
+ )}
>
);
}
-
-export default PersonalAccessTokens;
diff --git a/components/dashboard/src/settings/TokenEntry.tsx b/components/dashboard/src/settings/TokenEntry.tsx
deleted file mode 100644
index 2271ccf09287d1..00000000000000
--- a/components/dashboard/src/settings/TokenEntry.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright (c) 2022 Gitpod GmbH. All rights reserved.
- * Licensed under the GNU Affero General Public License (AGPL).
- * See License-AGPL.txt in the project root for license information.
- */
-
-import { PersonalAccessToken } from "@gitpod/public-api/lib/gitpod/experimental/v1/tokens_pb";
-import { useState } from "react";
-import { ContextMenuEntry } from "../components/ContextMenu";
-import { ItemFieldContextMenu } from "../components/ItemsList";
-import { personalAccessTokensService } from "../service/public-api";
-import { ShowTokenModal } from "./PersonalAccessTokens";
-import { settingsPathPersonalAccessTokenEdit } from "./settings.routes";
-
-function TokenEntry(props: { token: PersonalAccessToken; onDelete: (tokenId: string) => void }) {
- const [showDelModal, setShowDelModal] = useState(false);
-
- const menuEntries: ContextMenuEntry[] = [
- {
- title: "Edit",
- link: `${settingsPathPersonalAccessTokenEdit}/${props.token.id}`,
- },
- {
- title: "Delete",
- href: "",
- customFontStyle: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300",
- onClick: () => {
- setShowDelModal(true);
- },
- },
- ];
-
- const doDeletePAT = async () => {
- try {
- await personalAccessTokensService.deletePersonalAccessToken({ id: props.token.id });
- setShowDelModal(false);
- props.onDelete(props.token.id);
- } catch (e) {
- // TODO: show error
- }
- };
-
- const getDate = () => {
- if (!props.token.expirationTime) {
- return "";
- }
- const date = props.token.expirationTime?.toDate();
- return date.toDateString();
- };
-
- const defaultAllScope = ["function:*", "resource:default"];
-
- const getScopes = () => {
- if (!props.token.scopes) {
- return "";
- }
- if (props.token.scopes.every((v) => defaultAllScope.includes(v))) {
- return "Access the user's API";
- } else {
- return "No access";
- }
- };
-
- return (
- <>
-
-
- {props.token.name || ""}
-
-
- {getScopes()}
-
-
- {getDate()}
-
-
-
-
-
- {showDelModal && (
- {
- setShowDelModal(false);
- }}
- />
- )}
- >
- );
-}
-
-export default TokenEntry;