2022-04-16 02:58:34 +00:00
|
|
|
import { PlusIcon } from "@heroicons/react/outline";
|
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
import { Dialog, DialogContent } from "@calcom/ui/Dialog";
|
|
|
|
import ApiKeyDialogForm from "@ee/components/apiKeys/ApiKeyDialogForm";
|
|
|
|
import ApiKeyListItem, { TApiKeys } from "@ee/components/apiKeys/ApiKeyListItem";
|
|
|
|
|
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
|
|
|
import { trpc } from "@lib/trpc";
|
|
|
|
|
|
|
|
import { List } from "@components/List";
|
2022-06-01 17:24:41 +00:00
|
|
|
import { ShellSubHeading } from "@components/Shell";
|
|
|
|
import SkeletonLoader from "@components/apps/SkeletonLoader";
|
2022-04-16 02:58:34 +00:00
|
|
|
|
2022-05-26 17:07:14 +00:00
|
|
|
import LicenseRequired from "../LicenseRequired";
|
|
|
|
|
|
|
|
function ApiKeyListContainer() {
|
2022-04-16 02:58:34 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
const query = trpc.useQuery(["viewer.apiKeys.list"]);
|
|
|
|
|
|
|
|
const [newApiKeyModal, setNewApiKeyModal] = useState(false);
|
|
|
|
const [editModalOpen, setEditModalOpen] = useState(false);
|
2022-05-26 17:07:14 +00:00
|
|
|
const [apiKeyToEdit, setApiKeyToEdit] = useState<(TApiKeys & { neverExpires?: boolean }) | null>(null);
|
2022-04-16 02:58:34 +00:00
|
|
|
return (
|
2022-06-01 17:24:41 +00:00
|
|
|
<div className="border-b border-gray-200 py-8 pl-2 pr-1">
|
|
|
|
<ShellSubHeading
|
|
|
|
className="mt-2"
|
|
|
|
title={t("api_keys")}
|
|
|
|
subtitle={t("api_keys_subtitle")}
|
|
|
|
actions={
|
|
|
|
<Button
|
|
|
|
color="secondary"
|
|
|
|
size="icon"
|
|
|
|
StartIcon={PlusIcon}
|
|
|
|
onClick={() => setNewApiKeyModal(true)}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-05-26 17:07:14 +00:00
|
|
|
<LicenseRequired>
|
|
|
|
<QueryCell
|
|
|
|
query={query}
|
2022-06-01 17:24:41 +00:00
|
|
|
customLoader={<SkeletonLoader />}
|
2022-05-26 17:07:14 +00:00
|
|
|
success={({ data }) => (
|
|
|
|
<>
|
|
|
|
{data.length > 0 && (
|
2022-06-01 17:24:41 +00:00
|
|
|
<List className="mt-6">
|
2022-05-26 17:07:14 +00:00
|
|
|
{data.map((item) => (
|
|
|
|
<ApiKeyListItem
|
|
|
|
key={item.id}
|
|
|
|
apiKey={item}
|
|
|
|
onEditApiKey={() => {
|
|
|
|
setApiKeyToEdit(item);
|
|
|
|
setEditModalOpen(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
)}
|
2022-04-16 02:58:34 +00:00
|
|
|
|
2022-05-26 17:07:14 +00:00
|
|
|
{/* New api key dialog */}
|
|
|
|
<Dialog open={newApiKeyModal} onOpenChange={(isOpen) => !isOpen && setNewApiKeyModal(false)}>
|
|
|
|
<DialogContent>
|
|
|
|
<ApiKeyDialogForm
|
|
|
|
title={t("create_api_key")}
|
|
|
|
handleClose={() => setNewApiKeyModal(false)}
|
|
|
|
/>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
{/* Edit api key dialog */}
|
|
|
|
<Dialog open={editModalOpen} onOpenChange={(isOpen) => !isOpen && setEditModalOpen(false)}>
|
|
|
|
<DialogContent>
|
|
|
|
{apiKeyToEdit && (
|
|
|
|
<ApiKeyDialogForm
|
|
|
|
title={t("edit_api_key")}
|
|
|
|
key={apiKeyToEdit.id}
|
|
|
|
handleClose={() => setEditModalOpen(false)}
|
|
|
|
defaultValues={apiKeyToEdit}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</>
|
2022-04-16 02:58:34 +00:00
|
|
|
)}
|
2022-05-26 17:07:14 +00:00
|
|
|
/>
|
|
|
|
</LicenseRequired>
|
2022-06-01 17:24:41 +00:00
|
|
|
</div>
|
2022-04-16 02:58:34 +00:00
|
|
|
);
|
|
|
|
}
|
2022-05-26 17:07:14 +00:00
|
|
|
|
|
|
|
export default ApiKeyListContainer;
|