2021-06-23 05:37:08 -04:00
|
|
|
import { useCallback } from 'react'
|
2021-03-12 05:23:46 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2021-06-25 04:13:17 -04:00
|
|
|
import { useShareProjectContext } from './share-project-modal'
|
2021-03-12 05:23:46 -05:00
|
|
|
import Icon from '../../../shared/components/icon'
|
2022-05-18 09:46:10 -04:00
|
|
|
import { Button, Col, Row } from 'react-bootstrap'
|
|
|
|
import Tooltip from '../../../shared/components/tooltip'
|
2021-05-12 06:28:03 -04:00
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
2021-03-12 05:23:46 -05:00
|
|
|
import MemberPrivileges from './member-privileges'
|
|
|
|
import { resendInvite, revokeInvite } from '../utils/api'
|
2021-06-25 04:13:17 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
export default function Invite({ invite, isAdmin }) {
|
|
|
|
return (
|
|
|
|
<Row className="project-invite">
|
|
|
|
<Col xs={7}>
|
|
|
|
<div>{invite.email}</div>
|
|
|
|
|
|
|
|
<div className="small">
|
|
|
|
<Trans i18nKey="invite_not_accepted" />
|
|
|
|
.
|
|
|
|
{isAdmin && <ResendInvite invite={invite} />}
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
|
|
|
|
<Col xs={3} className="text-left">
|
|
|
|
<MemberPrivileges privileges={invite.privileges} />
|
|
|
|
</Col>
|
|
|
|
|
|
|
|
{isAdmin && (
|
|
|
|
<Col xs={2} className="text-center">
|
|
|
|
<RevokeInvite invite={invite} />
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Invite.propTypes = {
|
|
|
|
invite: PropTypes.object.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
isAdmin: PropTypes.bool.isRequired,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function ResendInvite({ invite }) {
|
|
|
|
const { monitorRequest } = useShareProjectContext()
|
2022-01-10 10:47:10 -05:00
|
|
|
const { _id: projectId } = useProjectContext()
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
// const buttonRef = useRef(null)
|
|
|
|
//
|
|
|
|
const handleClick = useCallback(
|
|
|
|
() =>
|
2022-01-10 10:47:10 -05:00
|
|
|
monitorRequest(() => resendInvite(projectId, invite)).finally(() => {
|
2021-03-12 05:23:46 -05:00
|
|
|
// NOTE: disabled as react-bootstrap v0.33.1 isn't forwarding the ref to the `button`
|
|
|
|
// if (buttonRef.current) {
|
|
|
|
// buttonRef.current.blur()
|
|
|
|
// }
|
|
|
|
document.activeElement.blur()
|
|
|
|
}),
|
2022-01-10 10:47:10 -05:00
|
|
|
[invite, monitorRequest, projectId]
|
2021-03-12 05:23:46 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
bsStyle="link"
|
|
|
|
className="btn-inline-link"
|
|
|
|
onClick={handleClick}
|
|
|
|
// ref={buttonRef}
|
|
|
|
>
|
|
|
|
<Trans i18nKey="resend" />
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
2022-05-18 09:46:10 -04:00
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
ResendInvite.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
invite: PropTypes.object.isRequired,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function RevokeInvite({ invite }) {
|
2021-05-12 06:28:03 -04:00
|
|
|
const { t } = useTranslation()
|
2021-03-12 05:23:46 -05:00
|
|
|
const { updateProject, monitorRequest } = useShareProjectContext()
|
2022-01-10 10:47:10 -05:00
|
|
|
const { _id: projectId, invites } = useProjectContext()
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
function handleClick(event) {
|
|
|
|
event.preventDefault()
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
monitorRequest(() => revokeInvite(projectId, invite)).then(() => {
|
2021-03-12 05:23:46 -05:00
|
|
|
updateProject({
|
2022-01-10 10:47:10 -05:00
|
|
|
invites: invites.filter(existing => existing !== invite),
|
2021-03-12 05:23:46 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-05-18 09:46:10 -04:00
|
|
|
<Tooltip
|
|
|
|
id="revoke-invite"
|
|
|
|
description={<Trans i18nKey="revoke_invite" />}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2021-03-12 05:23:46 -05:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
bsStyle="link"
|
|
|
|
onClick={handleClick}
|
2021-05-12 06:28:03 -04:00
|
|
|
aria-label={t('revoke')}
|
2021-03-12 05:23:46 -05:00
|
|
|
className="btn-inline-link"
|
|
|
|
>
|
|
|
|
<Icon type="times" />
|
|
|
|
</Button>
|
2022-05-18 09:46:10 -04:00
|
|
|
</Tooltip>
|
2021-03-12 05:23:46 -05:00
|
|
|
)
|
|
|
|
}
|
2022-05-18 09:46:10 -04:00
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
RevokeInvite.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
invite: PropTypes.object.isRequired,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|