forgeplus-react/src/forge/Team/Setting/TeamSettingCommon.jsx

179 lines
6.2 KiB
React
Raw Normal View History

2021-01-28 11:48:21 +08:00
import React, { forwardRef , useCallback , useEffect, useState } from 'react';
import { Form , Input , Radio ,Checkbox , Divider , Button } from 'antd';
2020-06-28 15:53:46 +08:00
import { WhiteBack , FlexAJ } from '../../Component/layout';
import Title from '../../Component/Title';
2020-06-24 10:10:47 +08:00
import styled from 'styled-components';
2021-01-28 11:48:21 +08:00
import UploadImage from '../Component/UploadImage';
import axios from 'axios';
2021-02-03 15:53:15 +08:00
import Modals from '../Component/Modals';
2021-01-28 11:48:21 +08:00
import { getImageUrl } from 'educoder';
2020-06-24 10:10:47 +08:00
const TextArea = Input.TextArea;
const Div = styled.div`{
padding:20px 30px;
}`
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
};
export default Form.create()(
2021-02-02 12:22:47 +08:00
forwardRef(({ form , organizeDetail , showNotification , history , current_user , updateFunc })=>{
2021-01-28 11:48:21 +08:00
const [ image , setImage ] = useState(undefined);
const [ imageFlag , setImageFlag ] = useState(false);
const [ password , setPassword ] = useState(undefined);
2021-01-29 17:26:08 +08:00
const [ passwordFlag , setPasswordFlag ] = useState(false);
2021-02-03 15:53:15 +08:00
const [ visible , setVisible ] = useState(false);
2021-01-29 17:26:08 +08:00
const { getFieldDecorator , validateFields , setFieldsValue } = form;
2021-01-28 11:48:21 +08:00
useEffect(()=>{
if(organizeDetail){
setFieldsValue({
...organizeDetail
})
setImage(organizeDetail.avatar_url);
}
},[organizeDetail])
2020-06-24 10:10:47 +08:00
const helper = useCallback(
2021-01-28 11:48:21 +08:00
(label, name, rules, widget , isRequired , flag ) => (
2020-06-24 10:10:47 +08:00
<div>
<span className={isRequired?"required":""}>{label}</span>
<Form.Item>
2021-01-28 11:48:21 +08:00
{getFieldDecorator(name, { rules, validateFirst: true , valuePropName:flag ? "checked":"value" })(widget)}
2020-06-24 10:10:47 +08:00
</Form.Item>
</div>
),
[]
);
2021-01-28 11:48:21 +08:00
// 更新
function updateDetail(){
validateFields((error,values)=>{
if(!error){
const url = `/organizations/${organizeDetail.id}.json`;
axios.patch(url,{
...values,image:imageFlag ? image : undefined
}).then(result=>{
if(result && result.data){
showNotification("组织信息更新成功!");
2021-02-02 12:22:47 +08:00
if(values.name !== organizeDetail.name){
console.log("false111");
history.push(`/organize/${values.name}/setting`);
}
updateFunc && updateFunc(values.name,values.description);
2021-01-28 11:48:21 +08:00
}
}).catch(error=>{})
}
})
}
function getImage(image){
setImageFlag(true);
setImage(image);
}
// 删除组织
function deleteOrganize(){
2021-01-29 17:26:08 +08:00
if(!password){
setPasswordFlag(true);
}else{
setPasswordFlag(false);
2021-02-03 15:53:15 +08:00
setVisible(true);
2021-01-29 17:26:08 +08:00
}
2021-01-28 11:48:21 +08:00
}
2021-02-03 15:53:15 +08:00
function onOk(password){
const url = `/organizations/${organizeDetail.id}.json`;
axios.delete(url,{
params:{ password }
}).then(result=>{
if(result && result.data){
// 删除后跳转到个人中心的组织页面
history.push(`/users/${current_user && current_user.login}/organizes`);
}
})
setVisible(false);
}
2020-06-24 10:10:47 +08:00
return(
<div>
<WhiteBack>
<Title>基本设置</Title>
<Div>
<Form>
{helper(
"组织名称:",
"name",
[{ required: true, message: "请输入组织名称" }],
<Input placeholder="请输入组织名称" />,true
)}
{helper(
"组织描述:",
2021-01-28 11:48:21 +08:00
"description",
2020-06-24 10:10:47 +08:00
[],
<TextArea placeholder="请输入组织名称" />
)}
{helper(
"官方网站:",
2021-01-28 11:48:21 +08:00
"website",
2020-06-24 10:10:47 +08:00
[],
<Input placeholder="请输入官方网站" />
)}
{helper(
'所在地区:',
2021-01-28 11:48:21 +08:00
"location",
2020-06-24 10:10:47 +08:00
[],
2021-01-28 11:48:21 +08:00
<Input placeholder="请输入城市"/>
2020-06-24 10:10:47 +08:00
)}
{helper(
'可见性:',
2021-01-28 11:48:21 +08:00
"visibility",
2020-06-24 10:10:47 +08:00
[],
<Radio.Group>
2021-01-28 11:48:21 +08:00
<Radio value="common" style={radioStyle}>公开</Radio>
<Radio value="limited" style={radioStyle}>受限<span>仅对登录用户可见</span></Radio>
2021-02-03 18:41:01 +08:00
<Radio value="privacy" style={radioStyle}>私有<span>仅对组织成员可见</span></Radio>
2020-06-24 10:10:47 +08:00
</Radio.Group>
)}
{helper(
'权限:',
2021-01-28 11:48:21 +08:00
"repo_admin_change_team_access",
2020-06-24 10:10:47 +08:00
[],
2021-01-28 11:48:21 +08:00
<Checkbox style={radioStyle}>仓库管理员可以添加或移除团队的访问权限</Checkbox>,false,true
2020-06-24 10:10:47 +08:00
)}
<Divider/>
{helper(
'最大仓库数:',
2021-01-28 11:48:21 +08:00
"max_repo_creation",
2020-06-24 10:10:47 +08:00
[],
<Input value="-1" style={{width:"350px"}}/>
)}
2021-01-28 11:48:21 +08:00
<p>选择头像:</p>
<UploadImage url={getImageUrl(`images/${image}`)} getImage={getImage}/>
<Button type={"primary"} onClick={updateDetail}>更新仓库设置</Button>
2020-06-24 10:10:47 +08:00
</Form>
</Div>
</WhiteBack>
<WhiteBack className="padding20 mt20">
<div className="warningBox">
<div className="warningTitle">删除当前组织</div>
<div className="warningContent">
<p className="font-16 mb15">删除操作会永久清除该组织的信息并且不可恢复</p>
<FlexAJ>
<div>
<span className="required">密码</span>
2021-01-29 17:26:08 +08:00
<Input type="password" placeholder="请输入当前用户的登录密码" style={{width:"350px"}} value={password} onChange={(e)=>setPassword(e.target.value)}/>
{ passwordFlag && <span className="color-red ml10">请输入密码</span>}
2020-06-24 10:10:47 +08:00
</div>
2021-01-28 11:48:21 +08:00
<a className="warningDelete" onClick={deleteOrganize}>删除组织</a>
2021-02-03 15:53:15 +08:00
<Modals visible={visible} okText={"确定"} cancelText={"取消"} onCancel={()=>setVisible(false)} onOk={()=>onOk(password)}>
<p className="font-16 edu-txt-center">确定要删除当前组织吗</p>
</Modals>
2020-06-24 10:10:47 +08:00
</FlexAJ>
</div>
</div>
</WhiteBack>
</div>
)
})
)