Просмотр исходного кода

Merge pull request #19747 from overleaf/ab-v1-project-import-module

[web] Extract code to v1-projects module

GitOrigin-RevId: 8f8a99891d3a1505aafca08f06fb439d4b596899
Alexandre Bourdin 2 лет назад
Родитель
Сommit
34e7f3182b

+ 1 - 0
services/web/config/settings.defaults.js

@@ -900,6 +900,7 @@ module.exports = {
     userNotifications: [],
     managedGroupEnrollmentInvite: [],
     ssoCertificateInfo: [],
+    v1ImportDataScreen: [],
   },
 
   moduleImportSequence: [

+ 16 - 6
services/web/frontend/js/features/token-access/components/token-access-root.tsx

@@ -1,24 +1,34 @@
 import useWaitForI18n from '@/shared/hooks/use-wait-for-i18n'
 import withErrorBoundary from '@/infrastructure/error-boundary'
 import { GenericErrorBoundaryFallback } from '@/shared/components/generic-error-boundary-fallback'
-import { useCallback, useEffect, useRef, useState } from 'react'
+import { ElementType, useCallback, useEffect, useRef, useState } from 'react'
 import getMeta from '@/utils/meta'
 import { postJSON } from '@/infrastructure/fetch-json'
 import { debugConsole } from '@/utils/debugging'
 import { useLocation } from '@/shared/hooks/use-location'
-import {
-  V1ImportData,
-  V1ImportDataScreen,
-} from '@/features/token-access/components/v1-import-data-screen'
 import { AccessAttemptScreen } from '@/features/token-access/components/access-attempt-screen'
 import {
   RequireAcceptData,
   RequireAcceptScreen,
 } from '@/features/token-access/components/require-accept-screen'
 import Icon from '@/shared/components/icon'
+import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
 
 type Mode = 'access-attempt' | 'v1Import' | 'requireAccept'
 
+const [v1ImportDataScreenModule] = importOverleafModules(
+  'v1ImportDataScreen'
+) as {
+  import: { default: ElementType }
+}[]
+const V1ImportDataScreen = v1ImportDataScreenModule?.import.default
+
+export type V1ImportData = {
+  name?: string
+  status: string
+  projectId: string
+}
+
 function TokenAccessRoot() {
   const [mode, setMode] = useState<Mode>('access-attempt')
   const [inflight, setInflight] = useState(false)
@@ -124,7 +134,7 @@ function TokenAccessRoot() {
         />
       )}
 
-      {mode === 'v1Import' && v1ImportData && (
+      {V1ImportDataScreen && mode === 'v1Import' && v1ImportData && (
         <V1ImportDataScreen v1ImportData={v1ImportData} />
       )}
 

+ 0 - 84
services/web/frontend/js/features/token-access/components/v1-import-data-screen.tsx

@@ -1,84 +0,0 @@
-import { FC } from 'react'
-
-export type V1ImportData = {
-  name?: string
-  status: string
-  projectId: string
-}
-export const V1ImportDataScreen: FC<{ v1ImportData: V1ImportData }> = ({
-  v1ImportData,
-}) => {
-  return (
-    <div className="loading-screen">
-      <div className="container">
-        <div className="row">
-          <div className="col-sm-8 col-sm-offset-2">
-            <h1 className="text-center">
-              {v1ImportData.status === 'mustLogin'
-                ? 'Please log in'
-                : 'Overleaf v1 Project'}
-            </h1>
-
-            <img
-              className="v2-import__img"
-              src="/img/v1-import/v2-editor.png"
-              alt="The new V2 editor."
-            />
-
-            {v1ImportData.status === 'cannotImport' && (
-              <div>
-                <h2 className="text-center">
-                  Cannot Access Overleaf v1 Project
-                </h2>
-
-                <p className="text-center row-spaced-small">
-                  Please contact the project owner or{' '}
-                  <a href="/contact">contact support</a> for assistance.
-                </p>
-              </div>
-            )}
-
-            {v1ImportData.status === 'mustLogin' && (
-              <div>
-                <p className="text-center row-spaced-small">
-                  You will need to log in to access this project.
-                </p>
-
-                <div className="row-spaced text-center">
-                  <a
-                    className="btn btn-primary"
-                    href={`/login?redir=${encodeURIComponent(document.location.pathname)}`}
-                  >
-                    Log in to access project
-                  </a>
-                </div>
-              </div>
-            )}
-
-            {v1ImportData.status === 'canDownloadZip' && (
-              <div>
-                <p className="text-center row-spaced-small">
-                  <strong>{v1ImportData.name || 'This project'}</strong> has not
-                  yet been moved into the new version of Overleaf. This project
-                  was created anonymously and therefore cannot be automatically
-                  imported. Please download a zip file of the project and upload
-                  that to continue editing it. If you would like to delete this
-                  project after you have made a copy, please contact support.
-                </p>
-
-                <div className="row-spaced text-center">
-                  <a
-                    className="btn btn-primary"
-                    href={`/overleaf/project/${v1ImportData.projectId}/download/zip`}
-                  >
-                    Download project zip file
-                  </a>
-                </div>
-              </div>
-            )}
-          </div>
-        </div>
-      </div>
-    </div>
-  )
-}