diff --git a/packages/client/src/pages/PortalSettings/categories/data-import/GoogleWorkspace/Stepper/index.tsx b/packages/client/src/pages/PortalSettings/categories/data-import/GoogleWorkspace/Stepper/index.tsx index 663c368a12..f4a9ed8f39 100644 --- a/packages/client/src/pages/PortalSettings/categories/data-import/GoogleWorkspace/Stepper/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/data-import/GoogleWorkspace/Stepper/index.tsx @@ -34,8 +34,8 @@ import SelectFileStep from "../../components/SelectFileStep"; import SelectUsersStep from "../../components/SelectUsersStep"; import SelectUsersTypeStep from "../../components/SelectUsersTypeStep"; import ImportStep from "../../components/ImportStep"; +import ImportProcessingStep from "../../components/ImportProcessingStep"; -import ImportProcessingStep from "./ImportProcessingStep"; import ImportCompleteStep from "./ImportCompleteStep"; import { TFunciton } from "../../types"; @@ -134,7 +134,7 @@ export const getStepsData = ( { title: t("Settings:DataImportProcessing"), description: t("Settings:ImportProcessingDescription"), - component: , + component: , }, { title: t("Settings:DataImportComplete"), diff --git a/packages/client/src/pages/PortalSettings/categories/data-import/NextcloudWorkspace/Stepper/index.tsx b/packages/client/src/pages/PortalSettings/categories/data-import/NextcloudWorkspace/Stepper/index.tsx index 696baf7cd8..6d5e976f9d 100644 --- a/packages/client/src/pages/PortalSettings/categories/data-import/NextcloudWorkspace/Stepper/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/data-import/NextcloudWorkspace/Stepper/index.tsx @@ -35,8 +35,8 @@ import SelectUsersStep from "../../components/SelectUsersStep"; import AddEmailsStep from "../../components/AddEmailsStep"; import SelectUsersTypeStep from "../../components/SelectUsersTypeStep"; import ImportStep from "../../components/ImportStep"; +import ImportProcessingStep from "../../components/ImportProcessingStep"; -import ImportProcessingStep from "./ImportProcessingStep"; import ImportCompleteStep from "./ImportCompleteStep"; import { TFunciton } from "../../types"; @@ -142,7 +142,7 @@ export const getStepsData = ( { title: t("Settings:DataImportProcessing"), description: t("Settings:ImportProcessingDescription"), - component: , + component: , }, { title: t("Settings:DataImportComplete"), diff --git a/packages/client/src/pages/PortalSettings/categories/data-import/OnlyofficeWorkspace/Stepper/index.tsx b/packages/client/src/pages/PortalSettings/categories/data-import/OnlyofficeWorkspace/Stepper/index.tsx index 2b908f2814..d4cd7fc6b2 100644 --- a/packages/client/src/pages/PortalSettings/categories/data-import/OnlyofficeWorkspace/Stepper/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/data-import/OnlyofficeWorkspace/Stepper/index.tsx @@ -35,8 +35,8 @@ import SelectFileStep from "../../components/SelectFileStep"; import SelectUsersStep from "../../components/SelectUsersStep"; import SelectUsersTypeStep from "../../components/SelectUsersTypeStep"; import ImportStep from "../../components/ImportStep"; +import ImportProcessingStep from "../../components/ImportProcessingStep"; -import ImportProcessingStep from "./ImportProcessingStep"; import ImportCompleteStep from "./ImportCompleteStep"; import { TFunciton } from "../../types"; @@ -140,7 +140,7 @@ export const getStepsData = ( { title: t("Settings:DataImportProcessing"), description: t("Settings:ImportProcessingDescription"), - component: , + component: , }, { title: t("Settings:DataImportComplete"), diff --git a/packages/client/src/pages/PortalSettings/categories/data-import/components/ImportProcessingStep.tsx b/packages/client/src/pages/PortalSettings/categories/data-import/components/ImportProcessingStep.tsx new file mode 100644 index 0000000000..a5998ff032 --- /dev/null +++ b/packages/client/src/pages/PortalSettings/categories/data-import/components/ImportProcessingStep.tsx @@ -0,0 +1,135 @@ +// (c) Copyright Ascensio System SIA 2009-2024 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +import { useState, useEffect, useRef } from "react"; +import { inject, observer } from "mobx-react"; + +import { ProgressBar } from "@docspace/shared/components/progress-bar"; + +import { toastr } from "@docspace/shared/components/toast"; +import { Wrapper } from "../StyledDataImport"; +import { + ImportProcessingStepProps, + InjectedImportProcessingStepProps, +} from "../types"; + +const FAIL_TRIES = 2; + +const ImportProcessingStep = (props: ImportProcessingStepProps) => { + const { + t, + migratorName, + + incrementStep, + setIsLoading, + proceedFileMigration, + getMigrationStatus, + } = props as InjectedImportProcessingStepProps; + + const [percent, setPercent] = useState(0); + const [isVisible, setIsVisible] = useState(false); + + const [failTries, setFailTries] = useState(FAIL_TRIES); + + const uploadInterval = useRef(); + + const handleFileMigration = async () => { + setIsLoading(true); + setPercent(0); + setIsVisible(true); + try { + await proceedFileMigration(migratorName); + + uploadInterval.current = window.setInterval(async () => { + const res = await getMigrationStatus(); + + if (!res && failTries) { + setFailTries((prevTries) => prevTries - 1); + return; + } + + if (!res) { + toastr.error(t("Common:SomethingWentWrong")); + clearInterval(uploadInterval.current); + return; + } + + setPercent(res.progress); + + if (res.progress > 10) { + setIsVisible(false); + } else { + setIsVisible(true); + } + + if (res.isCompleted || res.progress === 100) { + clearInterval(uploadInterval.current); + setIsLoading(false); + setIsVisible(false); + setPercent(100); + setTimeout(() => { + incrementStep(); + }, 1000); + } + }, 1000); + } catch (error) { + toastr.error(error || t("Common:SomethingWentWrong")); + setIsLoading(false); + } + }; + + useEffect(() => { + handleFileMigration(); + + return () => clearInterval(uploadInterval.current); + }, []); + + return ( + + + + ); +}; + +export default inject(({ importAccountsStore }) => { + const { + incrementStep, + setIsLoading, + proceedFileMigration, + getMigrationStatus, + } = importAccountsStore; + + return { + incrementStep, + setIsLoading, + proceedFileMigration, + getMigrationStatus, + }; +})(observer(ImportProcessingStep)); diff --git a/packages/client/src/pages/PortalSettings/categories/data-import/types/index.ts b/packages/client/src/pages/PortalSettings/categories/data-import/types/index.ts index 6278baca3a..106ab2aebf 100644 --- a/packages/client/src/pages/PortalSettings/categories/data-import/types/index.ts +++ b/packages/client/src/pages/PortalSettings/categories/data-import/types/index.ts @@ -434,3 +434,16 @@ export interface InjectedImportStepProps extends ImportStepProps { setImportOptions: TStore["importAccountsStore"]["setImportOptions"]; user: TStore["userStore"]["user"]; } + +export interface ImportProcessingStepProps { + t: TFunciton; + migratorName: TWorkspaceService; +} + +export interface InjectedImportProcessingStepProps + extends ImportProcessingStepProps { + incrementStep: TStore["importAccountsStore"]["incrementStep"]; + setIsLoading: TStore["importAccountsStore"]["setIsLoading"]; + proceedFileMigration: TStore["importAccountsStore"]["proceedFileMigration"]; + getMigrationStatus: TStore["importAccountsStore"]["getMigrationStatus"]; +}