From 90c626feb7254fb7dee02a5d60abf799b19eb0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E7=AB=A5=E5=B4=87?= Date: Tue, 21 Jun 2022 14:56:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=82=80=E8=AF=B7=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/UrlTool.js | 1 + src/forge/Invite/Index.js | 69 +++++++++++++------ src/forge/Invite/index.scss | 1 + src/forge/Main/Detail.js | 44 ++++++------ src/forge/Settings/Collaborator.js | 4 +- .../Settings/CollaboratorMemberByLink.jsx | 25 ++++--- src/forge/users/InfosUser.js | 2 +- 7 files changed, 85 insertions(+), 61 deletions(-) diff --git a/src/common/UrlTool.js b/src/common/UrlTool.js index 53540e38..24512d67 100644 --- a/src/common/UrlTool.js +++ b/src/common/UrlTool.js @@ -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}` diff --git a/src/forge/Invite/Index.js b/src/forge/Invite/Index.js index 24097e9f..71272b27 100644 --- a/src/forge/Invite/Index.js +++ b/src/forge/Invite/Index.js @@ -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 (
{data &&
} + title={
} width="548px" closable={true} - onCancel={() => setVisible(false)} + onCancel={() => { setVisible(false); history.push(`/${current_user.login}`) }} centered okText={'接受'} cancelText={'拒绝'} onOk={accept} - onCancel={refuse} - // icon={} + maskClosable={false} > - {data.ownerName}/{data.projectName} + {detail.project && detail.project.owner.name}/{detail.project && detail.project.name}
- {data.userName} 邀请您以{identify[data.role]}的身份加入此代码库 + {detail.user && detail.user.name} 邀请您以{identify[detail.role]}的身份加入此代码库 是否接受邀请?
} diff --git a/src/forge/Invite/index.scss b/src/forge/Invite/index.scss index 5735abb3..87912b65 100644 --- a/src/forge/Invite/index.scss +++ b/src/forge/Invite/index.scss @@ -41,6 +41,7 @@ display: flex; justify-content: center; align-items: center; + overflow: hidden; img{ width: 100%; } diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index 5e76a1c1..b6b90b9b 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -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 && - // {project.author.name} - // } - // / - // {projectDetail && projectDetail.name} + 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, diff --git a/src/forge/Settings/Collaborator.js b/src/forge/Settings/Collaborator.js index bc8b01ce..d22862aa 100644 --- a/src/forge/Settings/Collaborator.js +++ b/src/forge/Settings/Collaborator.js @@ -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" && {setNav("2");setNewId(undefined);setNewGroupId(undefined)}}>团队管理} { - (nav === "1" || nav === "3") && + nav === "1" && } { diff --git a/src/forge/Settings/CollaboratorMemberByLink.jsx b/src/forge/Settings/CollaboratorMemberByLink.jsx index e231e3bb..ea34ec8f 100644 --- a/src/forge/Settings/CollaboratorMemberByLink.jsx +++ b/src/forge/Settings/CollaboratorMemberByLink.jsx @@ -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 })} - { setIs_apply(e.target.checked) }}>是否需要管理员审核 + { setIs_apply(e.target.checked) }}>需要管理员审核
邀请链接
{this.get_projects()}} className="list-r-Search" value={search} onChange={this.changeSearchValue}