From c229a05e6d2de4ee1e4ef250f661c412d47aa45f Mon Sep 17 00:00:00 2001 From: Darya Umrikhina Date: Tue, 20 Aug 2024 03:31:22 +0400 Subject: [PATCH] Client:Src:helpers: remove old ConfirmRoute --- packages/client/src/helpers/confirmRoute.js | 258 -------------------- 1 file changed, 258 deletions(-) delete mode 100644 packages/client/src/helpers/confirmRoute.js diff --git a/packages/client/src/helpers/confirmRoute.js b/packages/client/src/helpers/confirmRoute.js deleted file mode 100644 index 0a3a784f9f..0000000000 --- a/packages/client/src/helpers/confirmRoute.js +++ /dev/null @@ -1,258 +0,0 @@ -// (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 React from "react"; -import { useLocation, Navigate } from "react-router-dom"; -import { inject, observer } from "mobx-react"; -import { useTranslation } from "react-i18next"; - -import { Loader } from "@docspace/shared/components/loader"; -import Section from "@docspace/shared/components/section"; -import { checkConfirmLink } from "@docspace/shared/api/user"; //TODO: Move AuthStore -import { getObjectByLocation } from "@docspace/shared/utils/common"; -import { combineUrl } from "@docspace/shared/utils/combineUrl"; - -import SectionWrapper from "SRC_DIR/components/Section"; -import { AuthenticatedAction, ValidationResult } from "SRC_DIR/helpers/enums"; -import { getCookie } from "@docspace/shared/utils"; -import { LANGUAGE } from "@docspace/shared/constants"; - -const ConfirmRoute = ({ - doAuthenticated, - isAuthenticated, - storeIsLoaded, - logout, - defaultPage, - children, - culture, -}) => { - const { i18n } = useTranslation(["Confirm", "Common", "Wizard"]); - - const [state, setState] = React.useState({ - linkData: {}, - isLoaded: false, - roomData: {}, - }); - - React.useEffect(() => { - if (location.search.includes("culture")) return; - const lng = getCookie(LANGUAGE); - - storeIsLoaded && i18n.changeLanguage(lng); - }, [storeIsLoaded]); - - const location = useLocation(); - - const getData = React.useCallback(() => { - const queryParams = getObjectByLocation(location); - const url = location.pathname; - const posSeparator = url.lastIndexOf("/"); - - const type = !!posSeparator ? url?.slice(posSeparator + 1) : ""; - const confirmLinkData = Object.assign({ type }, queryParams); - - return { type, confirmLinkData }; - }, [location.pathname]); - - const { type, confirmLinkData } = getData(); - - if (!type && confirmLinkData.type) - return ( - - ); - - React.useEffect(() => { - if (!storeIsLoaded) return; - - if (isAuthenticated && doAuthenticated != AuthenticatedAction.None) { - if (doAuthenticated == AuthenticatedAction.Redirect) - return window.location.replace(defaultPage); - - if (doAuthenticated == AuthenticatedAction.Logout) logout(false); - } - - const { search } = location; - - const { confirmLinkData } = getData(); - - let path = ""; - if (!isAuthenticated) { - path = "/login"; - } - - checkConfirmLink(confirmLinkData) - .then((res) => { - const validationResult = res.result; - - switch (validationResult) { - case ValidationResult.Ok: - const confirmHeader = search.slice(1); - const linkData = { - ...confirmLinkData, - confirmHeader, - }; - - const roomData = { - roomId: res?.roomId, - title: res?.title, - }; - - console.log("checkConfirmLink", { - confirmLinkData, - validationResult, - linkData, - }); - - setState((val) => ({ ...val, isLoaded: true, linkData, roomData })); - break; - case ValidationResult.UserExisted: - const finalUrl = res?.roomId - ? `/rooms/shared/${res?.roomId}/filter?folder=${res?.roomId}` - : defaultPage; - - console.log("user already exists", { - confirmLinkData, - validationResult, - finalUrl, - }); - - window.location.replace(finalUrl); - break; - case ValidationResult.Invalid: - console.error("invalid link", { - confirmLinkData, - validationResult, - }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error?messageKey=21", - ); - - break; - case ValidationResult.Expired: - console.error("expired link", { - confirmLinkData, - validationResult, - }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error", - ); - break; - case ValidationResult.TariffLimit: - console.error("tariff limit", { - confirmLinkData, - validationResult, - }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error?messageKey=20", - ); - break; - case ValidationResult.QuotaFailed: - console.error("access below quota", { - confirmLinkData, - validationResult, - }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error", - ); - break; - case ValidationResult.UserExcluded: - console.error("user excluded", { - confirmLinkData, - validationResult, - }); - window.location.replace(defaultPage); - break; - default: - console.error("unknown link", { - confirmLinkData, - validationResult, - }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error", - ); - break; - } - }) - .catch((error) => { - if (error?.response?.status === 403) { - window.DocSpace.navigate("/access-restricted", { - state: { isRestrictionError: true }, - replace: true, - }); - - return; - } - - console.error("FAILED checkConfirmLink", { error, confirmLinkData }); - window.location.href = combineUrl( - window.ClientConfig?.proxy?.url, - path, - "/error", - ); - }); - }, [getData, doAuthenticated, isAuthenticated, storeIsLoaded, logout]); - - // console.log(`ConfirmRoute render`, this.props, this.state); - - return !state.isLoaded ? ( - - - - - - ) : ( - React.cloneElement(children, { - linkData: state.linkData, - roomData: state.roomData, - }) - ); -}; - -ConfirmRoute.defaultProps = { - doAuthenticated: AuthenticatedAction.None, -}; - -export default inject(({ authStore, settingsStore }) => { - const { isAuthenticated, logout, isLoaded } = authStore; - const { defaultPage, culture } = settingsStore; - return { - isAuthenticated, - logout, - storeIsLoaded: isLoaded, - defaultPage, - culture, - }; -})(observer(ConfirmRoute));