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'
|
2023-10-19 04:33:26 -04:00
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
2021-03-12 05:23:46 -05:00
|
|
|
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 }) {
|
2023-10-19 04:33:26 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
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>
|
2023-10-19 04:33:26 -04:00
|
|
|
<Modal.Title>{t('change_project_owner')}</Modal.Title>
|
2021-03-12 05:23:46 -05:00
|
|
|
</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" />]}
|
2023-10-30 06:29:56 -04:00
|
|
|
shouldUnescape
|
2023-10-19 04:27:45 -04:00
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
2021-03-12 05:23:46 -05:00
|
|
|
/>
|
|
|
|
</p>
|
2023-10-19 04:33:26 -04:00
|
|
|
<p>{t('project_ownership_transfer_confirmation_2')}</p>
|
2021-03-12 05:23:46 -05:00
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<div className="modal-footer-left">
|
|
|
|
{inflight && <Icon type="refresh" spin />}
|
|
|
|
{error && (
|
|
|
|
<span className="text-danger">
|
2023-10-19 04:33:26 -04:00
|
|
|
{t('generic_something_went_wrong')}
|
2021-03-12 05:23:46 -05:00
|
|
|
</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}
|
|
|
|
>
|
2023-10-19 04:33:26 -04:00
|
|
|
{t('cancel')}
|
2021-03-12 05:23:46 -05:00
|
|
|
</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}
|
|
|
|
>
|
2023-10-19 04:33:26 -04:00
|
|
|
{t('change_owner')}
|
2021-03-12 05:23:46 -05:00
|
|
|
</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
|
|
|
}
|