forgeplus-react/src/forge/SecuritySetting/bot/disposition/index.jsx

80 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useEffect, useState } from "react";
import { Button, message, Modal } from "antd";
import { Link } from "react-router-dom";
import { getImageUrl } from 'educoder';
import nullBot from '../../../../softbot/image/notBot.png';
import { getAllInstallBots, deleteInstallBot } from "../../../../softbot/api";
import './index.scss';
// 配置已安装的bot
function DispositionBot(props){
const {current_user} = props;
const [botList, setBotList] = useState(undefined);
const [delBotId, setDelBotId] = useState(undefined);
const [visible, setVisible] = useState(false);
const [reload, setReload] = useState(undefined);
useEffect(()=>{
getAllInstallBots({
"user_id": current_user && current_user.user_id
}).then(res=>{
if(res && res.code === 200){
setBotList(res.data.install_bots);
}
})
}, [reload])
function delInstallBot(){
deleteInstallBot({
user_id: current_user && current_user.user_id,
bot_id: delBotId,
password: ""
}).then(res=>{
if(res && res.code === 200){
message.success('卸载成功');
setVisible(false);
setReload(Math.random());
}
})
}
return <div>
<div className="dispositionHead font-18">Bot配置</div>
{/* bot列表显示区域 */}
{botList && (botList.length > 0 ? <div className="setBotListBox">
{botList.map((item, index)=>{return <div className="disBotItem" key={index}>
<div className="botNameLeft">
<img src={getImageUrl(item.logo)} alt="" className="imgBox mr20"/>
<Link className="font-15 botName" to={`/settings/dispositionBot/${item.bot_id}`}>{item.bot_name}</Link>
<span className={`statusBox font-12 ml10 ${item.state === 0 ? '' : 'active'}`}>{item.state === 0 ? '挂起' : '启用'}</span>
</div>
<div>
<Button className="themeCorBorBut" style={{width: '68px', height: '36px'}}><Link to={`/settings/dispositionBot/${item.bot_id}`}>配置</Link></Button>
<Button className="dangerBorBut ml20" style={{width: '68px', height: '36px'}} onClick={()=>{setDelBotId(item.bot_id);setVisible(true)}}>卸载</Button>
</div>
</div>})}
</div> : <div className="nullBotsBox mt80">
<img src={nullBot} alt="" width={62}/>
<p className="font-18 showBigTip">您当前暂未安装任何Bot</p>
<div className="showTip font-14">Bot可以帮助项目贡献者处理繁杂的项目任务比如关闭疑修合并请求等以节约时间精力提升开发效率快去市场中挑选一个适合您项目的Bot吧!</div>
<div className="borTip"></div>
<Button type="primary" style={{width: '112px', height: '36px', padding: 0}}><Link to={'/softbot'}>去Bot市场逛逛</Link></Button>
</div>)}
<Modal
className="f8HeadModal"
width="485px"
title="卸载Bot"
visible={visible}
maskClosable={false}
footer={[
<Button onClick={()=>{setVisible(false)}} className="mr30 grayBorBut whiteBackBut" style={{width:"104px", height: '36px'}}>取消</Button>,
<Button className="redFontBut grayBorBut whiteBackBut" style={{width:"104px", height: '36px'}} onClick={delInstallBot}>确认卸载</Button>
]}
onCancel={()=>{setVisible(false)}}
>
<div className="font-16 titleTip mt20"><span className="circleRed font-18">!</span>Bot</div>
<div className="deleteTip">卸载后将回收所有分配给该bot的权限</div>
</Modal>
</div>
}
export default DispositionBot;