forked from Gitlink/forgeplus-react
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
import { Checkbox } from "antd";
|
|
import React, { useEffect, useState } from "react";
|
|
import axios from 'axios';
|
|
import './Index.scss';
|
|
|
|
function NoticeManager(props){
|
|
const {current_user} = props;
|
|
|
|
const [settingTypes, setSettingTypes] = useState();
|
|
const [userNotification, setUserNotification] = useState();
|
|
const [userEmail, setUserEmail] = useState();
|
|
|
|
function getUserSettings(){
|
|
axios.get(`/users/${current_user.login}/template_message_settings.json`).then((response)=>{
|
|
if(response && response.status === 200 ){
|
|
setUserEmail(response.data.email_body);
|
|
setUserNotification(response.data.notification_body);
|
|
}
|
|
})
|
|
}
|
|
|
|
useEffect(()=>{
|
|
axios.get("/template_message_settings.json").then((response)=>{
|
|
if(response && response.status === 200 ){
|
|
setSettingTypes(response.data.setting_types);
|
|
}
|
|
})
|
|
getUserSettings();
|
|
},[])
|
|
|
|
console.log('settingTypes',settingTypes);
|
|
console.log('userNotification',userNotification,'userEmail',userEmail);
|
|
return(
|
|
<div className="notice01">
|
|
<div className="sshHead">
|
|
<span className="text-shadow07">通知管理</span>
|
|
</div>
|
|
<div>
|
|
<span className="notice-manager-tip">您可以通过通知管理来选择接受通知的方式</span>
|
|
{settingTypes && settingTypes.map((item,key)=>{
|
|
return(
|
|
item.type_name && <div>
|
|
<div className="manager-cont-top">{item.type_name}</div>
|
|
{item.settings.map((i, k) => {
|
|
// console.log(userEmail[item.type.substring(item.type.indexOf("::")+2)+"::"+i.key]);
|
|
return (
|
|
<div className="manager-cont">
|
|
<div className="manager-cont-title">{i.name}</div>
|
|
<Checkbox defaultChecked='true' defaultChecked = {i.notification_disabled} checked={userNotification[item.type.substring(item.type.indexOf("::")+2)+"::"+i.key]}>站内信</Checkbox>
|
|
<Checkbox disabled = {i.email_disabled} defaultChecked={userEmail[item.type.substring(item.type.indexOf("::")+2)+"::"+i.key]}>邮件</Checkbox>
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
export default NoticeManager; |