Skip to content

Commit

Permalink
* refactor Modal for PendingInvitations
Browse files Browse the repository at this point in the history
  • Loading branch information
CalamityC committed Apr 5, 2024
1 parent b1a795e commit f3deecf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
6 changes: 3 additions & 3 deletions rdmo/core/assets/js/components/FileUploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { useDropzone } from 'react-dropzone'

const FileUploadButton = ({ acceptedTypes, buttonProps, buttonText, onImportFile }) => {
const FileUploadButton = ({ acceptedTypes, buttonProps, buttonLabel, onImportFile }) => {
const { getRootProps, getInputProps } = useDropzone({
accept: acceptedTypes,
onDrop: acceptedFiles => {
Expand All @@ -16,7 +16,7 @@ const FileUploadButton = ({ acceptedTypes, buttonProps, buttonText, onImportFile
<div {...getRootProps()}>
<input {...getInputProps()} />
<button className="btn" {...buttonProps}>
<i className="fa fa-download" aria-hidden="true"></i> {buttonText}
<i className="fa fa-download" aria-hidden="true"></i> {buttonLabel}
</button>
</div>
)
Expand All @@ -25,7 +25,7 @@ const FileUploadButton = ({ acceptedTypes, buttonProps, buttonText, onImportFile
FileUploadButton.propTypes = {
acceptedTypes: PropTypes.arrayOf(PropTypes.string),
buttonProps: PropTypes.object,
buttonText: PropTypes.string.isRequired,
buttonLabel: PropTypes.string.isRequired,
onImportFile: PropTypes.func.isRequired,
}

Expand Down
40 changes: 40 additions & 0 deletions rdmo/core/assets/js/components/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Modal as BootstrapModal } from 'react-bootstrap'

const Modal = ({ bsSize, buttonLabel, buttonProps, title, show, onClose, onSave, children }) => {
return (
<BootstrapModal bsSize={bsSize} className="element-modal" onHide={onClose} show={show}>
<BootstrapModal.Header closeButton>
<h2 className="modal-title">{title}</h2>
</BootstrapModal.Header>
<BootstrapModal.Body>
{ children }
</BootstrapModal.Body>
<BootstrapModal.Footer>
<button type="button" className="btn btn-default" onClick={onClose}>
{gettext('Close')}
</button>
{ onSave ?
<button type="button" className="btn btn-primary" onClick={onSave} {...buttonProps}>
{buttonLabel ?? gettext('Save')}
</button>
: null
}
</BootstrapModal.Footer>
</BootstrapModal>
)
}

Modal.propTypes = {
bsSize: PropTypes.oneOf(['lg', 'large', 'sm', 'small']),
buttonLabel: PropTypes.string,
buttonProps: PropTypes.object,
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
onClose: PropTypes.func.isRequired,
onSave: PropTypes.func,
show: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
}

export default Modal
1 change: 1 addition & 0 deletions rdmo/core/assets/js/components/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as FileUploadButton } from './FileUploadButton'
export { default as Link } from './Link'
export { default as LinkButton } from './LinkButton'
export { default as Modal } from './Modal'
export * from './SearchAndFilter'
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Modal } from 'react-bootstrap'

const columnStyle = { color: '#666', width: '25%', paddingLeft: '10px' }
const tableStyle = { width: '100%' }

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

return (
<Modal 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}>
<table style={tableStyle}>
<tbody>
{invitations?.map(item => (
<tr key={item.id}>
Expand All @@ -35,26 +29,17 @@ const PendingInvitationsModal = ({ invitations, onClose, show }) => {
</tr>
))}
</tbody>
</table> }
</Modal.Body>
<Modal.Footer>
<button type="button" className="btn btn-default" onClick={onClose}>
{gettext('Close')}
</button>
</Modal.Footer>
</Modal>
</table>
)
}

PendingInvitationsModal.propTypes = {
PendingInvitations.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
export default PendingInvitations
2 changes: 1 addition & 1 deletion rdmo/projects/assets/js/components/helper/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as PendingInvitationsModal } from './PendingInvitationsModal'
export { default as PendingInvitations } from './PendingInvitations'
export { default as Table } from './Table'
15 changes: 7 additions & 8 deletions rdmo/projects/assets/js/components/main/Projects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect, useState} from 'react'
import PropTypes from 'prop-types'
import { PendingInvitationsModal, Table } from '../helper'
import { FileUploadButton, Link, SearchField } from 'rdmo/core/assets/js/components'
import { PendingInvitations, Table } from '../helper'
import { FileUploadButton, Link, Modal, SearchField } from 'rdmo/core/assets/js/components'
import useModal from 'rdmo/core/assets/js/hooks/useModal'
import { language } from 'rdmo/core/assets/js/utils'
import { getTitlePath, userIsManager, DATE_OPTIONS, HEADER_FORMATTERS, SORTABLE_COLUMNS } from '../../utils'
Expand All @@ -13,6 +13,7 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
const { myProjects } = config

const [showModal, openModal, closeModal] = useModal()
const modalProps = {title: gettext('Pending invitations'), show: showModal, onClose: closeModal }

const [showTopButton, setShowTopButton] = useState(false)

Expand Down Expand Up @@ -156,7 +157,7 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
<FileUploadButton
acceptedTypes={['application/xml', 'text/xml']}
buttonProps={{'className': 'btn btn-link'}}
buttonText={gettext('Import project')}
buttonLabel={gettext('Import project')}
onImportFile={handleImport}
/>
</div>
Expand Down Expand Up @@ -192,11 +193,9 @@ const Projects = ({ config, configActions, currentUserObject, projectsActions, p
sortableColumns={SORTABLE_COLUMNS}
visibleColumns={visibleColumns}
/>
<PendingInvitationsModal
invitations={invites}
show={showModal}
onClose={closeModal}
/>
<Modal {...modalProps}>
<PendingInvitations invitations={invites} />
</Modal>
</>
)
}
Expand Down

0 comments on commit f3deecf

Please sign in to comment.