2023-11-27 06:44:06 +00:00
|
|
|
import { useState } from "react";
|
2023-11-15 10:26:57 +00:00
|
|
|
import { XCircle } from "lucide-react";
|
2023-11-27 06:44:06 +00:00
|
|
|
// components
|
|
|
|
import { DeleteApiTokenModal } from "components/api-token";
|
|
|
|
// ui
|
|
|
|
import { Tooltip } from "@plane/ui";
|
|
|
|
// helpers
|
2024-01-02 09:15:51 +00:00
|
|
|
import { renderFormattedDate, calculateTimeAgo } from "helpers/date-time.helper";
|
2023-11-27 06:44:06 +00:00
|
|
|
// types
|
2023-11-15 10:26:57 +00:00
|
|
|
import { IApiToken } from "types/api_token";
|
|
|
|
|
2023-11-27 06:44:06 +00:00
|
|
|
type Props = {
|
2023-11-15 10:26:57 +00:00
|
|
|
token: IApiToken;
|
2023-11-27 06:44:06 +00:00
|
|
|
};
|
2023-11-15 10:26:57 +00:00
|
|
|
|
2023-11-27 06:44:06 +00:00
|
|
|
export const ApiTokenListItem: React.FC<Props> = (props) => {
|
|
|
|
const { token } = props;
|
|
|
|
// states
|
|
|
|
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DeleteApiTokenModal isOpen={deleteModalOpen} onClose={() => setDeleteModalOpen(false)} tokenId={token.id} />
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="group relative flex flex-col justify-center border-b border-custom-border-200 px-4 py-3">
|
2023-11-27 06:44:06 +00:00
|
|
|
<Tooltip tooltipContent="Delete token">
|
|
|
|
<button
|
|
|
|
onClick={() => setDeleteModalOpen(true)}
|
2023-12-10 10:18:10 +00:00
|
|
|
className="absolute right-4 hidden place-items-center group-hover:grid"
|
2023-11-27 06:44:06 +00:00
|
|
|
>
|
|
|
|
<XCircle className="h-4 w-4 text-red-500" />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex w-4/5 items-center">
|
|
|
|
<h5 className="truncate text-sm font-medium">{token.label}</h5>
|
2023-11-27 06:44:06 +00:00
|
|
|
<span
|
|
|
|
className={`${
|
|
|
|
token.is_active ? "bg-green-500/10 text-green-500" : "bg-custom-background-80 text-custom-text-400"
|
2023-12-10 10:18:10 +00:00
|
|
|
} ml-2 flex h-4 max-h-fit items-center rounded-sm px-2 text-xs font-medium`}
|
2023-11-27 06:44:06 +00:00
|
|
|
>
|
|
|
|
{token.is_active ? "Active" : "Expired"}
|
|
|
|
</span>
|
|
|
|
</div>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="mt-1 flex w-full flex-col justify-center">
|
2023-11-27 06:44:06 +00:00
|
|
|
{token.description.trim() !== "" && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<p className="mb-1 max-w-[70%] break-words text-sm">{token.description}</p>
|
2023-11-27 06:44:06 +00:00
|
|
|
)}
|
2023-12-10 10:18:10 +00:00
|
|
|
<p className="mb-1 text-xs leading-6 text-custom-text-400">
|
2023-11-15 10:26:57 +00:00
|
|
|
{token.is_active
|
2023-11-27 06:44:06 +00:00
|
|
|
? token.expired_at
|
|
|
|
? `Expires ${renderFormattedDate(token.expired_at!)}`
|
|
|
|
: "Never expires"
|
2024-01-02 09:15:51 +00:00
|
|
|
: `Expired ${calculateTimeAgo(token.expired_at)}`}
|
2023-11-15 10:26:57 +00:00
|
|
|
</p>
|
2023-11-27 06:44:06 +00:00
|
|
|
</div>
|
2023-11-15 10:26:57 +00:00
|
|
|
</div>
|
2023-11-27 06:44:06 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|