import React, { useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import useSWR from "swr"; import { useTheme } from "next-themes"; // store hooks import { useUser, useWorkspace } from "hooks/store"; // layouts import { AppLayout } from "layouts/app-layout"; import { WorkspaceSettingLayout } from "layouts/settings-layout"; // component import { WorkspaceSettingHeader } from "components/headers"; import { ApiTokenListItem, CreateApiTokenModal } from "components/api-token"; import { EmptyState, getEmptyStateImagePath } from "components/empty-state"; // ui import { Button } from "@plane/ui"; import { APITokenSettingsLoader } from "components/ui"; // services import { APITokenService } from "services/api_token.service"; // types import { NextPageWithLayout } from "lib/types"; // constants import { API_TOKENS_LIST } from "constants/fetch-keys"; import { EUserWorkspaceRoles } from "constants/workspace"; import { WORKSPACE_SETTINGS_EMPTY_STATE_DETAILS } from "constants/empty-state"; import { PageHead } from "components/core"; const apiTokenService = new APITokenService(); const ApiTokensPage: NextPageWithLayout = observer(() => { // states const [isCreateTokenModalOpen, setIsCreateTokenModalOpen] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // theme const { resolvedTheme } = useTheme(); // store hooks const { membership: { currentWorkspaceRole }, currentUser, } = useUser(); const { currentWorkspace } = useWorkspace(); const isAdmin = currentWorkspaceRole === EUserWorkspaceRoles.ADMIN; const { data: tokens } = useSWR(workspaceSlug && isAdmin ? API_TOKENS_LIST(workspaceSlug.toString()) : null, () => workspaceSlug && isAdmin ? apiTokenService.getApiTokens(workspaceSlug.toString()) : null ); const emptyStateDetail = WORKSPACE_SETTINGS_EMPTY_STATE_DETAILS["api-tokens"]; const isLightMode = resolvedTheme ? resolvedTheme === "light" : currentUser?.theme.theme === "light"; const emptyStateImage = getEmptyStateImagePath("workspace-settings", "api-tokens", isLightMode); const pageTitle = currentWorkspace?.name ? `${currentWorkspace.name} - API Tokens` : undefined; if (!isAdmin) return ( <>

You are not authorized to access this page.

); if (!tokens) { return ; } return ( <> setIsCreateTokenModalOpen(false)} />
{tokens.length > 0 ? ( <>

API tokens

{tokens.map((token) => ( ))}
) : (

API tokens

)}
); }); ApiTokensPage.getLayout = function getLayout(page: React.ReactElement) { return ( }> {page} ); }; export default ApiTokensPage;