import { useEffect } from "react";
// import dayjs from "dayjs";
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useUpdateAvatarByAdminMutation } from '../../../app/services/user';
import { useAppSelector } from '../../../app/store';
import AvatarUploader from '../../../common/component/AvatarUploader';
import Button from '../../../common/component/styled/Button';
import IconDelete from '../../../assets/icons/delete.svg';
import CreateModal from './CreateModal';
import WebhookEdit from './WebhookEdit';
import WebhookModal from './WebhookModal';
import DeleteModal from './DeleteModal';
import BotAPIKeys from './BotAPIKeys';
import { toast } from 'react-hot-toast';
type TipProps = { title: string, desc: string };
const Tip = ({ title, desc }: TipProps) => {
return
;
};
const tdClass = "px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 align-top";
type WebhookParams = { webhook?: string, uid: number };
type DeleteParams = { name: string, uid: number };
export default function BotConfig() {
const [updateAvatar, { isSuccess: updateAvatarSuccess }] = useUpdateAvatarByAdminMutation();
const [createModalVisible, setCreateModalVisible] = useState(false);
const [currWebhookParams, setCurrWebhookParams] = useState(undefined);
const [currDeleteParams, setCurrDeleteParams] = useState(undefined);
const bots = useAppSelector(store => Object.values(store.users.byId).filter(u => !!u.is_bot));
const { t } = useTranslation("setting", { keyPrefix: "bot" });
const toggleCreateModalVisible = () => {
setCreateModalVisible(prev => !prev);
};
const toggleWebhookModalVisible = (obj?: WebhookParams) => {
console.log("webhook modal", obj);
setCurrWebhookParams(obj);
};
const toggleDeleteModalVisible = (obj?: DeleteParams) => {
setCurrDeleteParams(obj);
};
useEffect(() => {
if (updateAvatarSuccess) {
toast.success("Update Bot Avatar Successfully!");
}
}, [updateAvatarSuccess]);
return (
<>
{t("manage")}
{t("manage_desc")}
{[t("col_avatar"), t('col_name'), t('col_api_key'), t('col_webhook'), t('col_opt')].map(title => |
{title}
| )}
{bots.map(bot => {
const { uid, name, avatar } = bot;
return
|
#{uid}
|
{name}
|
|
|
{/* */}
|
;
})}
{createModalVisible && }
{currWebhookParams && }
{currDeleteParams && }
>
);
}