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'
|
2021-06-25 04:13:17 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2023-03-16 08:32:48 -04:00
|
|
|
import { useLocation } from '../../../shared/hooks/use-location'
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
export default function TransferOwnershipModal({ member, cancel }) {
|
|
|
|
const [inflight, setInflight] = useState(false)
|
|
|
|
const [error, setError] = useState(false)
|
2023-03-16 08:32:48 -04:00
|
|
|
const location = useLocation()
|
2021-03-12 05:23:46 -05:00
|
|
|
|
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(() => {
|
2023-03-16 08:32:48 -04:00
|
|
|
location.reload()
|
2021-03-12 05:23:46 -05:00
|
|
|
})
|
|
|
|
.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-09-02 05:41:42 -04:00
|
|
|
// eslint-disable-next-line react/jsx-boolean-value
|
|
|
|
shouldUnescape={true}
|
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"
|
2022-12-07 05:51:44 -05:00
|
|
|
bsStyle={null}
|
|
|
|
className="btn-secondary"
|
2021-03-12 05:23:46 -05:00
|
|
|
onClick={cancel}
|
|
|
|
disabled={inflight}
|
|
|
|
>
|
|
|
|
<Trans i18nKey="cancel" />
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="button"
|
2022-12-07 05:51:08 -05:00
|
|
|
bsStyle="primary"
|
2021-03-12 05:23:46 -05:00
|
|
|
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
|
|
|
}
|