* chore: user store code refactor * chore: general unauthorized screen asset added * chore: workspace setting sidebar options updated for guest and viewer * chore: NotAuthorizedView component code updated * chore: project setting layout code refactor * chore: workspace setting members and exports page permission validation added * chore: workspace members and exports settings page improvement * chore: project invite modal updated * chore: workspace setting unauthorized access empty state * chore: workspace setting unauthorized access empty state * chore: project settings sidebar permission updated * fix: project settings user role permission updated * chore: app sidebar role permission validation updated * chore: app sidebar role permission validation * chore: disabled page empty state validation * chore: app sidebar add project improvement * chore: guest role changes * fix: user favorite * chore: changed pages permission * chore: guest role changes * fix: app sidebar project item permission * fix: project setting empty state flicker * fix: workspace setting empty state flicker * chore: granted notification permission to viewer * chore: project invite and edit validation updated * chore: favorite validation added for guest and viewer role * chore: create view validation updated * chore: views permission changes * chore: create view empty state validation updated * chore: created ENUM for permissions --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com>
90 lines
3.1 KiB
TypeScript
90 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import React, { useState } from "react";
|
|
import { observer } from "mobx-react";
|
|
import { useParams } from "next/navigation";
|
|
import useSWR from "swr";
|
|
// ui
|
|
import { Button } from "@plane/ui";
|
|
// component
|
|
import { ApiTokenListItem, CreateApiTokenModal } from "@/components/api-token";
|
|
import { NotAuthorizedView } from "@/components/auth-screens";
|
|
import { PageHead } from "@/components/core";
|
|
import { EmptyState } from "@/components/empty-state";
|
|
import { APITokenSettingsLoader } from "@/components/ui";
|
|
// constants
|
|
import { EmptyStateType } from "@/constants/empty-state";
|
|
import { API_TOKENS_LIST } from "@/constants/fetch-keys";
|
|
// store hooks
|
|
import { useUser, useWorkspace } from "@/hooks/store";
|
|
// services
|
|
import { APITokenService } from "@/services/api_token.service";
|
|
|
|
const apiTokenService = new APITokenService();
|
|
|
|
const ApiTokensPage = observer(() => {
|
|
// states
|
|
const [isCreateTokenModalOpen, setIsCreateTokenModalOpen] = useState(false);
|
|
// router
|
|
const { workspaceSlug } = useParams();
|
|
// store hooks
|
|
const {
|
|
canPerformWorkspaceAdminActions,
|
|
membership: { currentWorkspaceRole },
|
|
} = useUser();
|
|
const { currentWorkspace } = useWorkspace();
|
|
|
|
const { data: tokens } = useSWR(
|
|
workspaceSlug && canPerformWorkspaceAdminActions ? API_TOKENS_LIST(workspaceSlug.toString()) : null,
|
|
() =>
|
|
workspaceSlug && canPerformWorkspaceAdminActions ? apiTokenService.getApiTokens(workspaceSlug.toString()) : null
|
|
);
|
|
|
|
const pageTitle = currentWorkspace?.name ? `${currentWorkspace.name} - API Tokens` : undefined;
|
|
|
|
if (currentWorkspaceRole && !canPerformWorkspaceAdminActions) {
|
|
return <NotAuthorizedView section="settings" />;
|
|
}
|
|
|
|
if (!tokens) {
|
|
return <APITokenSettingsLoader />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<PageHead title={pageTitle} />
|
|
<CreateApiTokenModal isOpen={isCreateTokenModalOpen} onClose={() => setIsCreateTokenModalOpen(false)} />
|
|
<section className="w-full overflow-y-auto md:pr-9 pr-4">
|
|
{tokens.length > 0 ? (
|
|
<>
|
|
<div className="flex items-center justify-between border-b border-custom-border-200 py-3.5">
|
|
<h3 className="text-xl font-medium">API tokens</h3>
|
|
<Button variant="primary" onClick={() => setIsCreateTokenModalOpen(true)}>
|
|
Add API token
|
|
</Button>
|
|
</div>
|
|
<div>
|
|
{tokens.map((token) => (
|
|
<ApiTokenListItem key={token.id} token={token} />
|
|
))}
|
|
</div>
|
|
</>
|
|
) : (
|
|
<div className="flex h-full w-full flex-col">
|
|
<div className="flex items-center justify-between gap-4 border-b border-custom-border-200 pb-3.5">
|
|
<h3 className="text-xl font-medium">API tokens</h3>
|
|
<Button variant="primary" onClick={() => setIsCreateTokenModalOpen(true)}>
|
|
Add API token
|
|
</Button>
|
|
</div>
|
|
<div className="h-full w-full flex items-center justify-center">
|
|
<EmptyState type={EmptyStateType.WORKSPACE_SETTINGS_API_TOKENS} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
</section>
|
|
</>
|
|
);
|
|
});
|
|
|
|
export default ApiTokensPage;
|