修改邀请链接

This commit is contained in:
何童崇 2022-06-21 14:56:56 +08:00
parent 53869f95fa
commit 90c626feb7
7 changed files with 85 additions and 61 deletions

View File

@ -11,6 +11,7 @@ export function getImageUrl(path) {
// https://www.educoder.net
// https://testbdweb.trustie.net
// const local = 'http://localhost:3000'
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
const local = 'https://testforgeplus.trustie.net';
if (isDev) {
return `${local}/${path}`

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Modal, Button } from 'antd';
import React, { useState, useEffect } from 'react';
import { Modal, Button, } from 'antd';
import { Base64 } from 'js-base64';
import './index.scss';
import { Link } from 'react-router-dom';
@ -8,54 +8,79 @@ import axios from 'axios';
const identify = {
manager: "管理员",
developer: "开发人员",
reporter: "报告者"
developer: "开发者",
reporter: "报告者",
owner: "所有者",
}
function Invite({ history, current_user }) {
function Invite({ history, current_user, match, projectDetail, showNotification }) {
if (!current_user.login) {
let { pathname, search } = window.location;
window.location.href = `/login?go_page=${pathname}${search}`;
}
let permission = projectDetail && projectDetail.permission;
const { projectsId, owner } = match.params;
let inviteString = window.location.search && window.location.search.split('?invite=')[1];
let data = inviteString && JSON.parse(Base64.decode(inviteString));
const [detail, setDetail] = useState({});
const [visible, setVisible] = useState(true);
function accept() {
const url = `/users/${current_user.login}/applied_projects/${data.id}/accept.json`;
useEffect(() => {
if (permission && detail.role && detail.role == permission.toLocaleLowerCase() || permission == 'Owner') {
showNotification(`您已经是${identify[detail.role]}`)
setTimeout(() => {
history.push(`/${owner}/${projectsId}`);
}, 2000)
} else {
setVisible(true)
}
}, [permission, detail.role]);
useEffect(() => {
const url = `/${owner}/${projectsId}/project_invite_links/show_link.json?invite_sign=${data.sign}`;
axios.get(url).then(res => {
if (res && res.data) {
console.log(res)
setDetail(res.data);
} else {
showNotification('查询邀请链接失败');
}
})
}, [])
function accept() {
const url = `/${owner}/${projectsId}/project_invite_links/redirect_link.json?invite_sign=${data.sign}`;
axios.post(url).then(res => {
if (res && res.data.message == 'success') {
if (detail.is_apply) {
setVisible(false);
Modal.success({ content: '提交申请成功,请等待该仓库管理员审核' });
} else {
history.push(`/${owner}/${projectsId}`);
}
}
}).catch(error => { })
}
function refuse() {
const url = `/users/${current_user.login}/applied_projects/${data.id}/refuse.json`;
axios.get(url).then(res => {
if (res && res.data) {
console.log(res)
}
}).catch(error => { })
}
return (
<div className="">
{data && <Modal
visible={visible}
className="invite_development"
title={<div className="ownerImage"><img src={getImageUrl(data.ownerImage)} /></div>}
title={<div className="ownerImage"><img src={detail.project && getImageUrl(detail.project.owner.image_url)} /></div>}
width="548px"
closable={true}
onCancel={() => setVisible(false)}
onCancel={() => { setVisible(false); history.push(`/${current_user.login}`) }}
centered
okText={'接受'}
cancelText={'拒绝'}
onOk={accept}
onCancel={refuse}
// icon={<i className="iconfont icon-shanchuicon"></i>}
maskClosable={false}
>
<Link className="invite_project link" target="_blank" to={`/${data.ownerLogin}/${data.projectId}`}>{data.ownerName}/{data.projectName}</Link>
<Link className="invite_project link" target="_blank" to={`/${data.ownerLogin}/${data.projectId}`}>{detail.project && detail.project.owner.name}/{detail.project && detail.project.name}</Link>
<div className="invite_content">
<Link className="link" to={`/${data.userLogin}`}>{data.userName}</Link> {identify[data.role]}
<Link className="link" to={`/${detail.user && detail.user.login}`}>{detail.user && detail.user.name}</Link> {identify[detail.role]}
是否接受邀请
</div>
</Modal>}

View File

@ -41,6 +41,7 @@
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
img{
width: 100%;
}

View File

@ -4,6 +4,7 @@ import { Link, Route, Switch } from 'react-router-dom';
import { Content, AlignTop } from '../Component/layout';
import DetailBanner from './sub/DetailBanner';
import cookie from 'react-cookies';
import { Base64 } from 'js-base64';
import '../css/index.scss'
import './list.scss';
@ -371,32 +372,30 @@ class Detail extends Component {
if (window.location.pathname.includes('/invite')) {
let inviteString = window.location.search && window.location.search.split('?invite=')[1];
let data = inviteString && JSON.parse(Base64.decode(inviteString));
// this.setState({
// project: { author: { login:data. } }
// });
// {project && project.author &&
// <Link to={`/${project.author.login}`}>{project.author.name}</Link>
// }
// <span className="ml5 mr5">/</span>
// <Link to={`/${owner}/${projectsId}`} className="projectN mt6">{projectDetail && projectDetail.name}</Link>
const { project = {}, projectDetail = {} } = this.state
this.setState({
project: Object.assign(project, { author: { name: data.ownerName } }),
projectDetail: Object.assign(projectDetail, { name: data.projectName })
});
} else {
this.props.history.push('/nopage');
}
} else {
this.setState({
projectDetail: result.data,
project_id: result.data.project_id,
isManager: result.data.permission && (result.data.permission === "Manager" || result.data.permission === "Admin" || result.data.permission === "Owner"),
isReporter: result.data.permission && result.data.permission === "Reporter",
isDeveloper: result.data.permission && result.data.permission === "Developer",
http_url: result.data.clone_url,
praised: result.data.praised,
watched: result.data.watched,
watchers_count: result.data.watchers_count,
praises_count: result.data.praises_count,
forked_count: result.data.forked_count,
defaultBranch: result.data.default_branch
})
}
this.setState({
projectDetail: result.data,
project_id: result.data.project_id,
isManager: result.data.permission && (result.data.permission === "Manager" || result.data.permission === "Admin" || result.data.permission === "Owner"),
isReporter: result.data.permission && result.data.permission === "Reporter",
isDeveloper: result.data.permission && result.data.permission === "Developer",
http_url: result.data.clone_url,
praised: result.data.praised,
watched: result.data.watched,
watchers_count: result.data.watchers_count,
praises_count: result.data.praises_count,
forked_count: result.data.forked_count,
defaultBranch: result.data.default_branch
})
}
}).catch((error) => { })
}
@ -544,7 +543,6 @@ class Detail extends Component {
let pathname = checkPathname(projectsId, owner, url);
const { state } = this.props.history.location;
const common = {
getDetail: this.getDetail,
getBanner: this.getBanner,

View File

@ -7,7 +7,7 @@ import Group from './CollaboratorGroup';
import MemberByLink from './CollaboratorMemberByLink';
function Collaborator(props){
const [ nav , setNav] = useState("3");
const [ nav , setNav] = useState("1");
const [ newId , setNewId] = useState(undefined);
const [ newIdFlag , setNewIdFlag ] = useState(false);
const [ addOperation , setAddOperation] = useState(true);
@ -42,7 +42,7 @@ function Collaborator(props){
{author && author.type === "Organization" && <span style={{cursor:"pointer"}} className={nav === "2" ? "font-15 text-black ml30 color-blue":"font-15 text-black ml30"} onClick={()=>{setNav("2");setNewId(undefined);setNewGroupId(undefined)}}>团队管理</span>}
</span>
{
(nav === "1" || nav === "3") &&
nav === "1" &&
<AddMember getID={getID} login showNotification={props.showNotification}/>
}
{

View File

@ -17,28 +17,27 @@ function CollaboratorMemberByLink({ projectsId, owner, project_id, author, showN
const [role, setRole] = useState('developer');
const [is_apply, setIs_apply] = useState(true);
const [inviteUrl, setinviteUrl] = useState('dddd');
const [inviteUrl, setinviteUrl] = useState('');
const [copy, setCopy] = useState(false);
useEffect(() => {
const url = `/${owner}/${projectsId}/project_invite_links/generate_link.json`;
axios.post(url, {
role,
is_apply
const url = `/${owner}/${projectsId}/project_invite_links/current_link.json`;
axios.get(url, {
params: {
role,
is_apply
}
}).then(res => {
if (res && res.data) {
let params = {
id:res.data.id,
projectName: res.data.project.name,
projectId: res.data.project.identifier,
is_apply: res.data.is_apply,
role: res.data.role,
is_public: res.data.project.is_public,
ownerImage: res.data.project.owner.image_url,
// role: res.data.role,
ownerLogin: res.data.project.owner.login,
ownerName: res.data.project.owner.name,
userName: res.data.user.name,
userLogin:res.data.user.login,
// userName: res.data.user.name,
// userLogin: res.data.user.login,
sign:res.data.sign,
};
let urlParams = JSON.stringify(params);
let content = Base64.encode(urlParams);
@ -71,7 +70,7 @@ function CollaboratorMemberByLink({ projectsId, owner, project_id, author, showN
})}
</Select>
<Checkbox className='font-15 checkBox' onChange={e => { setIs_apply(e.target.checked) }}>是否需要管理员审核</Checkbox>
<Checkbox checked={is_apply} className='font-15 checkBox' onChange={e => { setIs_apply(e.target.checked) }}>需要管理员审核</Checkbox>
<div className='font-16 mt25 mb10'>邀请链接</div>
<Input

View File

@ -180,7 +180,7 @@ class InfosUser extends Component {
placeholder="输入项目名称关键字进行搜索"
enterButton="搜索"
size="large"
onSearch={this.get_projects}
onSearch={()=>{this.get_projects()}}
className="list-r-Search"
value={search}
onChange={this.changeSearchValue}