2021-06-23 05:37:08 -04:00
|
|
|
import { useState } from 'react'
|
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'
|
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'
|
2024-10-09 08:13:50 -04:00
|
|
|
import OLModal, {
|
|
|
|
OLModalBody,
|
|
|
|
OLModalFooter,
|
|
|
|
OLModalHeader,
|
|
|
|
OLModalTitle,
|
|
|
|
} from '@/features/ui/components/ol/ol-modal'
|
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
import { bsVersion } from '@/features/utils/bootstrap-5'
|
|
|
|
import { Spinner } from 'react-bootstrap-5'
|
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 (
|
2024-10-09 08:13:50 -04:00
|
|
|
<OLModal show onHide={cancel}>
|
|
|
|
<OLModalHeader closeButton>
|
|
|
|
<OLModalTitle>{t('change_project_owner')}</OLModalTitle>
|
|
|
|
</OLModalHeader>
|
|
|
|
<OLModalBody>
|
2021-03-12 05:23:46 -05:00
|
|
|
<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>
|
2024-10-09 08:13:50 -04:00
|
|
|
{error && (
|
|
|
|
<OLNotification
|
|
|
|
type="error"
|
|
|
|
content={t('generic_something_went_wrong')}
|
|
|
|
className="mb-0 mt-3"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</OLModalBody>
|
|
|
|
<OLModalFooter>
|
|
|
|
<div className={bsVersion({ bs3: 'pull-left', bs5: 'me-auto' })}>
|
|
|
|
{inflight && (
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="refresh" spin />}
|
|
|
|
bs5={
|
|
|
|
<Spinner
|
|
|
|
animation="border"
|
|
|
|
aria-hidden="true"
|
|
|
|
size="sm"
|
|
|
|
role="status"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2021-03-12 05:23:46 -05:00
|
|
|
)}
|
|
|
|
</div>
|
2024-10-09 08:13:50 -04:00
|
|
|
<OLButton variant="secondary" onClick={cancel} disabled={inflight}>
|
|
|
|
{t('cancel')}
|
|
|
|
</OLButton>
|
|
|
|
<OLButton variant="primary" onClick={confirm} disabled={inflight}>
|
|
|
|
{t('change_owner')}
|
|
|
|
</OLButton>
|
|
|
|
</OLModalFooter>
|
|
|
|
</OLModal>
|
2021-03-12 05:23:46 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|