Skip to content

Commit

Permalink
* use Modal for Pending invitations display
Browse files Browse the repository at this point in the history
  • Loading branch information
CalamityC committed Apr 4, 2024
1 parent ed23bb6 commit 64ac5be
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 86 deletions.
11 changes: 11 additions & 0 deletions rdmo/core/assets/js/hooks/useModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useState } from 'react'

const useModal = () => {
const [show, setShow] = useState(false)
const open = () => setShow(true)
const close = () => setShow(false)

return [show, open, close]
}

export default useModal
80 changes: 0 additions & 80 deletions rdmo/projects/assets/js/components/helper/PendingInvitations.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Modal } from 'react-bootstrap'

const columnStyle = { color: '#666', width: '25%', paddingLeft: '10px' }
// const tableStyle = { border: '1px solid #ccc', borderCollapse: 'collapse', width: '100%' }
const tableStyle = { width: '100%' }

const PendingInvitationsModal = ({ invitations, onClose, show }) => {
const baseUrl = window.location.origin

return (
<Modal bsSize="large" show={show} onHide={onClose} className="element-modal">
<Modal.Header closeButton>
<h2 className="modal-title">{gettext('Pending invitations')}</h2>
</Modal.Header>
<Modal.Body>
{ <table style={tableStyle}>
<tbody>
{invitations?.map(item => (
<tr key={item.id}>
<td style={columnStyle}>
<b>{item.project_title}</b>
{/* <a href={`${baseUrl}/projects/${item.project}`} target="_blank" rel="noopener noreferrer">{item.project_title}</a>
{' '.repeat(maxProjectTitleLength - item.project_title.length)} */}
{/* <a href={`${baseUrl}/projects/join/${item.project}`} target="_blank" rel="noopener noreferrer"><b>{item.project_title}</b></a> */}
</td>
{/* <td style={columnStyle}>{gettext(item.role)}</td> */}
<td style={columnStyle}>{gettext(item.role).charAt(0).toUpperCase() + gettext(item.role).slice(1)}</td>
<td style={columnStyle}>
<button className="btn btn-link" onClick={() => { window.location.href = `${baseUrl}/projects/join/${item.project}` }}>{gettext('Accept')}</button>
</td>
<td style={columnStyle}>
<button className="btn btn-link" onClick={() => { window.location.href = `${baseUrl}/projects/cancel/${item.project}` }}>{gettext('Decline')}</button>
</td>
</tr>
))}
</tbody>
</table> }
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-default" onClick={onClose}>
{gettext('Close')}
</button>
</Modal.Footer>
</Modal>
)
// return (
// <div className="mb-20">
// <table style={tableStyle}>
// <tbody>
// <td style={columnStyle} colSpan="4"><h5>{gettext('Pending invitations')}</h5></td>
// {invitations.map(item => (
// <tr key={item.id}>
// <td style={columnStyle}>
// <b>{item.project_title}</b>
// {/* <a href={`${baseUrl}/projects/${item.project}`} target="_blank" rel="noopener noreferrer">{item.project_title}</a>
// {' '.repeat(maxProjectTitleLength - item.project_title.length)} */}
// {/* <a href={`${baseUrl}/projects/join/${item.project}`} target="_blank" rel="noopener noreferrer"><b>{item.project_title}</b></a> */}
// </td>
// {/* <td style={columnStyle}>{gettext(item.role)}</td> */}
// <td style={columnStyle}>{gettext(item.role).charAt(0).toUpperCase() + gettext(item.role).slice(1)}</td>
// <td style={columnStyle}>
// <button className="btn btn-link" onClick={() => { window.location.href = `${baseUrl}/projects/join/${item.project}` }}>{gettext('Accept')}</button>
// </td>
// <td style={columnStyle}>
// <button className="btn btn-link" onClick={() => { window.location.href = `${baseUrl}/projects/cancel/${item.project}` }}>{gettext('Decline')}</button>
// </td>
// </tr>
// ))}
// </tbody>
// </table>
// </div>
// )
}

PendingInvitationsModal.propTypes = {
invitations: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
project_title: PropTypes.string.isRequired,
project: PropTypes.number.isRequired,
role: PropTypes.string.isRequired,
})),
onClose: PropTypes.func.isRequired,
show: PropTypes.bool.isRequired,
}

export default PendingInvitationsModal
20 changes: 14 additions & 6 deletions rdmo/projects/assets/js/components/main/Projects.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import PropTypes from 'prop-types'
import Table from '../helper/Table'
import PendingInvitations from '../helper/PendingInvitations'
import PendingInvitationsModal from '../helper/PendingInvitationsModal'
import Link from 'rdmo/core/assets/js/components/Link'
import { SearchField } from 'rdmo/core/assets/js/components/SearchAndFilter'
import FileUploadButton from 'rdmo/core/assets/js/components/FileUploadButton'
import useModal from 'rdmo/core/assets/js/hooks/useModal'
import language from 'rdmo/core/assets/js/utils/language'
import userIsManager from '../../utils/userIsManager'
import { get, isNil, isEmpty } from 'lodash'
Expand All @@ -14,6 +15,8 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
const { currentUser } = currentUserObject
const { myProjects } = config

const [showModal, openModal, closeModal] = useModal()

const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' })
}
Expand Down Expand Up @@ -170,6 +173,11 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
<div className="mb-10" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<h2 className="ml-10 mt-0">{headline}</h2>
<div className="icon-container ml-auto">
{ !isEmpty(invites) && myProjects &&
<button className="btn btn-link mr-10" onClick={openModal}>
{gettext('Pending invitations')}
</button>
}
<button className="btn btn-link mr-10" onClick={handleNew}>
<i className="fa fa-plus" aria-hidden="true"></i> {gettext('New project')}
</button>
Expand All @@ -181,11 +189,6 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
/>
</div>
</div>
{ !isEmpty(invites) && myProjects &&
<PendingInvitations
invitations={invites}
/>
}
<span>{parseInt(displayedRows) > projects.length ? projects.length : displayedRows} {gettext('of')} {projects.length} {gettext('projects are displayed')}</span>
<div className="panel-body">
<div className="row">
Expand Down Expand Up @@ -216,6 +219,11 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
sortableColumns={sortableColumns}
visibleColumns={visibleColumns}
/>
<PendingInvitationsModal
invitations={invites}
show={showModal}
onClose={closeModal}
/>
</>
)
}
Expand Down

0 comments on commit 64ac5be

Please sign in to comment.