import React, { useState } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import useSWR from "swr"; // store hooks import { Button } from "@plane/ui"; import { ApiTokenListItem, CreateApiTokenModal } from "@/components/api-token"; import { PageHead } from "@/components/core"; import { EmptyState } from "@/components/empty-state"; import { WorkspaceSettingHeader } from "@/components/headers"; import { APITokenSettingsLoader } from "@/components/ui"; import { EmptyStateType } from "@/constants/empty-state"; import { API_TOKENS_LIST } from "@/constants/fetch-keys"; import { EUserWorkspaceRoles } from "@/constants/workspace"; import { useUser, useWorkspace } from "@/hooks/store"; // layouts import { AppLayout } from "@/layouts/app-layout"; import { WorkspaceSettingLayout } from "@/layouts/settings-layout"; // component // ui // services import { NextPageWithLayout } from "@/lib/types"; import { APITokenService } from "@/services/api_token.service"; // types // constants const apiTokenService = new APITokenService(); const ApiTokensPage: NextPageWithLayout = observer(() => { // states const [isCreateTokenModalOpen, setIsCreateTokenModalOpen] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { membership: { currentWorkspaceRole }, } = 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 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;