2021-06-23 05:37:08 -04:00
|
|
|
import { useState } from 'react'
|
2021-03-12 05:23:46 -05:00
|
|
|
import { Modal, Button } from 'react-bootstrap'
|
|
|
|
import { Trans } from 'react-i18next'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import { transferProjectOwnership } from '../utils/api'
|
|
|
|
import AccessibleModal from '../../../shared/components/accessible-modal'
|
2022-07-20 08:32:56 -04:00
|
|
|
import { reload } from '../../../shared/components/location'
|
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 TransferOwnershipModal({ member, cancel }) {
|
|
|
|
const [inflight, setInflight] = useState(false)
|
|
|
|
const [error, setError] = useState(false)
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
const { _id: projectId, name: projectName } = useProjectContext()
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
function confirm() {
|
|
|
|
setError(false)
|
|
|
|
setInflight(true)
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
transferProjectOwnership(projectId, member)
|
2021-03-12 05:23:46 -05:00
|
|
|
.then(() => {
|
|
|
|
reload()
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
setError(true)
|
|
|
|
setInflight(false)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AccessibleModal show onHide={cancel}>
|
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>
|
|
|
|
<Trans i18nKey="change_project_owner" />
|
|
|
|
</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
|
|
|
<p>
|
|
|
|
<Trans
|
|
|
|
i18nKey="project_ownership_transfer_confirmation_1"
|
2022-01-10 10:47:10 -05:00
|
|
|
values={{ user: member.email, project: projectName }}
|
2021-03-12 05:23:46 -05:00
|
|
|
components={[<strong key="strong-1" />, <strong key="strong-2" />]}
|
2022-08-18 04:16:16 -04:00
|
|
|
shouldUnescape
|
2021-03-12 05:23:46 -05:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<Trans i18nKey="project_ownership_transfer_confirmation_2" />
|
|
|
|
</p>
|
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<div className="modal-footer-left">
|
|
|
|
{inflight && <Icon type="refresh" spin />}
|
|
|
|
{error && (
|
|
|
|
<span className="text-danger">
|
|
|
|
<Trans i18nKey="generic_something_went_wrong" />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="modal-footer-right">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
bsStyle="default"
|
|
|
|
onClick={cancel}
|
|
|
|
disabled={inflight}
|
|
|
|
>
|
|
|
|
<Trans i18nKey="cancel" />
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
bsStyle="success"
|
|
|
|
onClick={confirm}
|
|
|
|
disabled={inflight}
|
|
|
|
>
|
|
|
|
<Trans i18nKey="change_owner" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal.Footer>
|
|
|
|
</AccessibleModal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
TransferOwnershipModal.propTypes = {
|
|
|
|
member: PropTypes.object.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
cancel: PropTypes.func.isRequired,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|