// import Tippy from '@tippyjs/react'; import dayjs from 'dayjs'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useGetBotAPIKeysQuery } from '../../../app/services/user'; import IconDelete from '../../../assets/icons/delete.svg'; import IconAdd from '../../../assets/icons/add.svg'; import CreateAPIKeyModal from './CreateAPIKeyModal'; import DeleteAPIKeyModal from './DeleteAPIKeyModal'; import clsx from 'clsx'; type Props = { uid: number } // const APIKeyTable = () => { // return //
; // }; type DeleteAPIKeyProps = { uid: number, kid: number } const tdClass = "p-1 whitespace-nowrap text-xs text-gray-500 align-middle px-1"; const BotAPIKeys = ({ uid }: Props) => { const { t } = useTranslation("setting", { keyPrefix: "bot" }); const [currentUid, setCurrentUid] = useState(); const [deleteApiKey, setDeleteApiKey] = useState(); const { data, refetch } = useGetBotAPIKeysQuery(uid); const toggleCreateModal = (param?: number) => { if (!param) refetch(); setCurrentUid(param); }; const toggleDeleteModal = (param?: DeleteAPIKeyProps) => { if (!param) refetch(); setDeleteApiKey(param); }; if (!data) return null; const colWidths = ["w-20", "w-[166px]", "w-36", "w-15", "w-10"]; return (
{[t("col_key_name"), t('col_key_value'), t('col_key_create_time'), t('col_key_last_used'), ""].map((title, idx) => )} {data.length > 0 ? data.map(ak => { const { id, name, key, created_at, last_used } = ak; return ; }) : }
{title}
{name} {`${key.slice(0, 4)} ... ... ${key.slice(-6)}`} {dayjs(created_at).format("YYYY-MM-DD HH:mm:ss")} {last_used ? dayjs(last_used).format("YYYY-MM-DD HH:mm:ss") : "Unused"}
No API Key Yet
{currentUid && } {deleteApiKey && }
); }; export default BotAPIKeys;