2021-03-12 05:23:46 -05:00
|
|
|
import { Button, Modal, Grid } from 'react-bootstrap'
|
2023-10-19 04:33:26 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-03-12 05:23:46 -05:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import AccessibleModal from '../../../shared/components/accessible-modal'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-06-03 09:44:23 -04:00
|
|
|
import { useEditorContext } from '../../../shared/context/editor-context'
|
2023-10-17 04:41:40 -04:00
|
|
|
import { lazy, Suspense } from 'react'
|
|
|
|
import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
|
|
|
|
|
|
|
|
const ReadOnlyTokenLink = lazy(() =>
|
|
|
|
import('./link-sharing').then(({ ReadOnlyTokenLink }) => ({
|
|
|
|
// re-export as default -- lazy can only handle default exports.
|
|
|
|
default: ReadOnlyTokenLink,
|
|
|
|
}))
|
|
|
|
)
|
|
|
|
|
|
|
|
const ShareModalBody = lazy(() => import('./share-modal-body'))
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
export default function ShareProjectModalContent({
|
|
|
|
show,
|
|
|
|
cancel,
|
|
|
|
animation,
|
|
|
|
inFlight,
|
2021-04-27 03:52:58 -04:00
|
|
|
error,
|
2021-03-12 05:23:46 -05:00
|
|
|
}) {
|
2023-10-19 04:33:26 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-06-03 09:44:23 -04:00
|
|
|
const { isRestrictedTokenMember } = useEditorContext({
|
|
|
|
isRestrictedTokenMember: PropTypes.bool,
|
|
|
|
})
|
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
return (
|
|
|
|
<AccessibleModal show={show} onHide={cancel} animation={animation}>
|
|
|
|
<Modal.Header closeButton>
|
2023-10-19 04:33:26 -04:00
|
|
|
<Modal.Title>{t('share_project')}</Modal.Title>
|
2021-03-12 05:23:46 -05:00
|
|
|
</Modal.Header>
|
|
|
|
|
|
|
|
<Modal.Body className="modal-body-share">
|
|
|
|
<Grid fluid>
|
2023-10-17 04:41:40 -04:00
|
|
|
<Suspense fallback={<FullSizeLoadingSpinner minHeight="15rem" />}>
|
|
|
|
{isRestrictedTokenMember ? (
|
|
|
|
<ReadOnlyTokenLink />
|
|
|
|
) : (
|
|
|
|
<ShareModalBody />
|
|
|
|
)}
|
|
|
|
</Suspense>
|
2021-03-12 05:23:46 -05:00
|
|
|
</Grid>
|
|
|
|
</Modal.Body>
|
|
|
|
|
|
|
|
<Modal.Footer className="modal-footer-share">
|
|
|
|
<div className="modal-footer-left">
|
|
|
|
{inFlight && <Icon type="refresh" spin />}
|
|
|
|
{error && (
|
|
|
|
<span className="text-danger error">
|
|
|
|
<ErrorMessage error={error} />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="modal-footer-right">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
onClick={cancel}
|
2022-12-07 05:51:44 -05:00
|
|
|
bsStyle={null}
|
|
|
|
className="btn-secondary"
|
2021-03-12 05:23:46 -05:00
|
|
|
disabled={inFlight}
|
|
|
|
>
|
2023-10-19 04:33:26 -04:00
|
|
|
{t('close')}
|
2021-03-12 05:23:46 -05:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal.Footer>
|
|
|
|
</AccessibleModal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
ShareProjectModalContent.propTypes = {
|
|
|
|
cancel: PropTypes.func.isRequired,
|
|
|
|
show: PropTypes.bool,
|
|
|
|
animation: PropTypes.bool,
|
|
|
|
inFlight: PropTypes.bool,
|
2021-04-27 03:52:58 -04:00
|
|
|
error: PropTypes.string,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function ErrorMessage({ error }) {
|
2023-10-19 04:33:26 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
switch (error) {
|
|
|
|
case 'cannot_invite_non_user':
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('cannot_invite_non_user')
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'cannot_verify_user_not_robot':
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('cannot_verify_user_not_robot')
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'cannot_invite_self':
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('cannot_invite_self')
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'invalid_email':
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('invalid_email')
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'too_many_requests':
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('too_many_requests')
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
default:
|
2023-10-19 04:33:26 -04:00
|
|
|
return t('generic_something_went_wrong')
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ErrorMessage.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired,
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|