share-project-modal-content.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { useTranslation } from 'react-i18next'
  2. import { useEditorContext } from '@/shared/context/editor-context'
  3. import { lazy, Suspense, useState } from 'react'
  4. import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
  5. import ClickableElementEnhancer from '@/shared/components/clickable-element-enhancer'
  6. import {
  7. OLModal,
  8. OLModalBody,
  9. OLModalFooter,
  10. OLModalHeader,
  11. OLModalTitle,
  12. } from '@/shared/components/ol/ol-modal'
  13. import OLNotification from '@/shared/components/ol/ol-notification'
  14. import OLButton from '@/shared/components/ol/ol-button'
  15. import OLSpinner from '@/shared/components/ol/ol-spinner'
  16. import MaterialIcon from '@/shared/components/material-icon'
  17. import CopySharingLinkButton from '@/features/share-project-modal/components/copy-sharing-link-button'
  18. import ErrorMessage from '@/features/share-project-modal/components/error-message'
  19. import GiveFeedbackLink from '@/features/share-project-modal/components/give-feedback-link'
  20. import classNames from 'classnames'
  21. import { useFeatureFlag } from '@/shared/context/split-test-context'
  22. import { useShareProjectContext } from '@/features/share-project-modal/components/share-project-modal'
  23. import { ErrorBoundaryFallback } from '@/shared/components/error-boundary-fallback'
  24. import withErrorBoundary from '@/infrastructure/error-boundary'
  25. const ReadOnlyTokenLink = lazy(() =>
  26. import('./link-sharing').then(({ ReadOnlyTokenLink }) => ({
  27. // re-export as default -- lazy can only handle default exports.
  28. default: ReadOnlyTokenLink,
  29. }))
  30. )
  31. const ShareModalBody = lazy(() => import('./share-modal-body'))
  32. type ShareProjectModalContentProps = {
  33. cancel: () => void
  34. onShow: () => void
  35. show: boolean
  36. animation: boolean
  37. inFlight: boolean
  38. error: string | undefined
  39. projectName?: string
  40. }
  41. export default function ShareProjectModalContent({
  42. show,
  43. onShow,
  44. cancel,
  45. animation,
  46. inFlight,
  47. error,
  48. projectName,
  49. }: ShareProjectModalContentProps) {
  50. return (
  51. <OLModal show={show} onShow={onShow} onHide={cancel} animation={animation}>
  52. <ShareProjectModalContentInnerWithErrorBoundary
  53. inFlight={inFlight}
  54. error={error}
  55. projectName={projectName}
  56. cancel={cancel}
  57. />
  58. </OLModal>
  59. )
  60. }
  61. function ShareProjectModalContentInner({
  62. inFlight,
  63. error,
  64. projectName,
  65. cancel,
  66. }: Pick<
  67. ShareProjectModalContentProps,
  68. 'inFlight' | 'error' | 'projectName' | 'cancel'
  69. >) {
  70. const { t } = useTranslation()
  71. const isSharingUpdatesEnabled = useFeatureFlag('sharing-updates')
  72. const [isInvitedPeopleScreen, setIsInvitedPeopleScreen] = useState(false)
  73. const { successActionMessage, projectAccess } = useShareProjectContext()
  74. const { isRestrictedTokenMember, isProjectOwner } = useEditorContext()
  75. return (
  76. <>
  77. <OLModalHeader>
  78. <div className="d-flex flex-grow-1 justify-content-between">
  79. {isSharingUpdatesEnabled && isInvitedPeopleScreen ? (
  80. <OLButton
  81. variant="ghost"
  82. onClick={() => setIsInvitedPeopleScreen(false)}
  83. leadingIcon="arrow_back_ios_new"
  84. >
  85. {t('back')}
  86. </OLButton>
  87. ) : (
  88. <OLModalTitle>
  89. {isSharingUpdatesEnabled && projectName
  90. ? t('share_project_name', { projectName })
  91. : t('share_project')}
  92. </OLModalTitle>
  93. )}
  94. {isSharingUpdatesEnabled && isProjectOwner && <GiveFeedbackLink />}
  95. </div>
  96. </OLModalHeader>
  97. <OLModalBody
  98. className={classNames('modal-body-share modal-link-share', {
  99. 'modal-redesign': isSharingUpdatesEnabled,
  100. })}
  101. >
  102. <div
  103. className={classNames({
  104. 'container-fluid': !isSharingUpdatesEnabled,
  105. })}
  106. >
  107. <Suspense fallback={<FullSizeLoadingSpinner minHeight="15rem" />}>
  108. {isRestrictedTokenMember ? (
  109. <ReadOnlyTokenLink />
  110. ) : (
  111. <ShareModalBody
  112. isInvitedPeopleScreen={isInvitedPeopleScreen}
  113. setIsInvitedPeopleScreen={setIsInvitedPeopleScreen}
  114. error={error}
  115. />
  116. )}
  117. </Suspense>
  118. {!isSharingUpdatesEnabled && error && (
  119. <OLNotification
  120. type="error"
  121. content={<ErrorMessage error={error} />}
  122. className="mb-0 mt-3"
  123. />
  124. )}
  125. </div>
  126. </OLModalBody>
  127. <OLModalFooter>
  128. <div className="d-flex flex-grow-1 flex-wrap gap-2">
  129. {isSharingUpdatesEnabled ? (
  130. <>
  131. {!isInvitedPeopleScreen &&
  132. projectAccess &&
  133. (projectAccess === 'onlyInvitedPeople' ||
  134. projectAccess.startsWith('anyoneInXyzWithTheLink') ||
  135. projectAccess === 'anyoneWithTheLink') && (
  136. <CopySharingLinkButton />
  137. )}
  138. {successActionMessage && (
  139. <div className="ms-auto px-3 align-self-center">
  140. <div
  141. className="d-flex gap-2 align-items-center"
  142. role="status"
  143. aria-live="polite"
  144. >
  145. <MaterialIcon
  146. unfilled
  147. type="check_circle"
  148. className="text-success"
  149. />
  150. <span>{successActionMessage}</span>
  151. </div>
  152. </div>
  153. )}
  154. </>
  155. ) : (
  156. inFlight && <OLSpinner size="sm" />
  157. )}
  158. </div>
  159. <ClickableElementEnhancer
  160. onClick={cancel}
  161. as={OLButton}
  162. variant={isSharingUpdatesEnabled ? 'ghost' : 'secondary'}
  163. isLoading={isSharingUpdatesEnabled && inFlight}
  164. disabled={inFlight}
  165. >
  166. {t('close')}
  167. </ClickableElementEnhancer>
  168. </OLModalFooter>
  169. </>
  170. )
  171. }
  172. const ShareProjectModalContentInnerFallback = () => {
  173. const { t } = useTranslation()
  174. return (
  175. <>
  176. <OLModalHeader>
  177. <OLModalTitle>{t('generic_something_went_wrong')}</OLModalTitle>
  178. </OLModalHeader>
  179. <OLModalBody>
  180. <ErrorBoundaryFallback />
  181. </OLModalBody>
  182. </>
  183. )
  184. }
  185. const ShareProjectModalContentInnerWithErrorBoundary = withErrorBoundary(
  186. ShareProjectModalContentInner,
  187. () => <ShareProjectModalContentInnerFallback />
  188. )