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'
|
2024-10-09 08:13:50 -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'
|
2024-02-05 06:47:01 -05:00
|
|
|
import ClickableElementEnhancer from '@/shared/components/clickable-element-enhancer'
|
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'
|
2023-10-17 04:41:40 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-10-27 04:43:50 -04:00
|
|
|
type ShareProjectModalContentProps = {
|
|
|
|
cancel: () => void
|
|
|
|
show: boolean
|
|
|
|
animation: boolean
|
|
|
|
inFlight: boolean
|
|
|
|
error: string | undefined
|
|
|
|
}
|
|
|
|
|
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,
|
2023-10-27 04:43:50 -04:00
|
|
|
}: ShareProjectModalContentProps) {
|
2023-10-19 04:33:26 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2023-10-27 04:43:50 -04:00
|
|
|
const { isRestrictedTokenMember } = useEditorContext()
|
2021-06-03 09:44:23 -04:00
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
return (
|
2024-10-09 08:13:50 -04:00
|
|
|
<OLModal show={show} onHide={cancel} animation={animation}>
|
|
|
|
<OLModalHeader closeButton>
|
|
|
|
<OLModalTitle>{t('share_project')}</OLModalTitle>
|
|
|
|
</OLModalHeader>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
2024-10-09 08:13:50 -04:00
|
|
|
<OLModalBody className="modal-body-share">
|
|
|
|
<div className="container-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
|
|
|
{error && (
|
2024-10-09 08:13:50 -04:00
|
|
|
<OLNotification
|
|
|
|
type="error"
|
|
|
|
content={<ErrorMessage error={error} />}
|
|
|
|
className="mb-0 mt-3"
|
|
|
|
/>
|
2021-03-12 05:23:46 -05:00
|
|
|
)}
|
|
|
|
</div>
|
2024-10-09 08:13:50 -04:00
|
|
|
</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
|
|
|
|
|
|
|
<ClickableElementEnhancer
|
|
|
|
onClick={cancel}
|
|
|
|
as={OLButton}
|
|
|
|
variant="secondary"
|
|
|
|
disabled={inFlight}
|
|
|
|
>
|
|
|
|
{t('close')}
|
|
|
|
</ClickableElementEnhancer>
|
|
|
|
</OLModalFooter>
|
|
|
|
</OLModal>
|
2021-03-12 05:23:46 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-10-27 04:43:50 -04:00
|
|
|
function ErrorMessage({ error }: Pick<ShareProjectModalContentProps, '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-27 04:43:50 -04:00
|
|
|
return <>{t('cannot_invite_non_user')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'cannot_verify_user_not_robot':
|
2023-10-27 04:43:50 -04:00
|
|
|
return <>{t('cannot_verify_user_not_robot')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'cannot_invite_self':
|
2023-10-27 04:43:50 -04:00
|
|
|
return <>{t('cannot_invite_self')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'invalid_email':
|
2023-10-27 04:43:50 -04:00
|
|
|
return <>{t('invalid_email')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
case 'too_many_requests':
|
2023-10-27 04:43:50 -04:00
|
|
|
return <>{t('too_many_requests')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
|
2024-07-12 05:00:26 -04:00
|
|
|
case 'invite_expired':
|
|
|
|
return <>{t('invite_expired')}</>
|
|
|
|
|
|
|
|
case 'invite_resend_limit_hit':
|
|
|
|
return <>{t('invite_resend_limit_hit')}</>
|
|
|
|
|
2021-03-12 05:23:46 -05:00
|
|
|
default:
|
2023-10-27 04:43:50 -04:00
|
|
|
return <>{t('generic_something_went_wrong')}</>
|
2021-03-12 05:23:46 -05:00
|
|
|
}
|
|
|
|
}
|