Login:Src:Components: add RemovePortalForm, DeactivatePortalForm, ContinuePortalForm, ChangePhoneForm and AuthHandler

This commit is contained in:
Darya Umrikhina 2024-08-07 13:54:47 +04:00
parent 2bfde3088c
commit 5a787f4e89
5 changed files with 572 additions and 0 deletions

View File

@ -0,0 +1,113 @@
// (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
"use client";
import { toastr } from "@docspace/shared/components/toast";
import { getCookie } from "@docspace/shared/utils";
import { deleteCookie } from "@docspace/shared/utils/cookie";
import { useSearchParams } from "next/navigation";
import { useContext, useEffect } from "react";
import { ConfirmRouteContext } from "../ConfirmRoute";
import AppLoader from "@docspace/shared/components/app-loader";
import { TError } from "@/types";
import { frameCallEvent } from "@docspace/shared/utils/common";
import { combineUrl } from "@docspace/shared/utils/combineUrl";
import { loginWithConfirmKey } from "@docspace/shared/api/user";
const AuthHandler = () => {
let searchParams = useSearchParams();
const { linkData } = useContext(ConfirmRouteContext);
const { email = "", key = "" } = linkData;
useEffect(() => {
loginWithConfirmKey({
ConfirmData: {
Email: email,
Key: key,
},
})
?.then((res) => {
//console.log("Login with confirm key success", res);
frameCallEvent({ event: "onAuthSuccess" });
const url = searchParams.get("referenceUrl");
const redirectUrl = getCookie("x-redirect-authorization-uri");
deleteCookie("x-redirect-authorization-uri");
if (redirectUrl) {
window.location.replace(redirectUrl);
return;
}
if (url && url.includes("oauth2")) {
const newUrl = location.search.split("referenceUrl=")[1];
window.location.replace(newUrl);
return;
}
if (url) {
try {
new URL(url);
return window.location.replace(url);
} catch {
return window.location.replace(
combineUrl(window.location.origin, url),
);
}
}
if (typeof res === "string") window.location.replace(res);
else window.location.replace("/");
})
.catch((error) => {
const knownError = error as TError;
let errorMessage: string;
if (typeof knownError === "object") {
errorMessage =
knownError?.response?.data?.error?.message ||
knownError?.statusText ||
knownError?.message ||
"";
} else {
errorMessage = knownError;
}
frameCallEvent({ event: "onAppError", data: error });
toastr.error(error);
});
});
return <AppLoader />;
};
export default AuthHandler;

View File

@ -0,0 +1,87 @@
// (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
"use client";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, ButtonSize } from "@docspace/shared/components/button";
import {
InputSize,
InputType,
TextInput,
} from "@docspace/shared/components/text-input";
import { Text } from "@docspace/shared/components/text";
import withLoader from "@/HOCs/withLoader";
const ChangePhoneForm = () => {
const { t } = useTranslation(["Confirm", "Common"]);
const [currentNumber, setCurrentNumber] = useState("+00000000000");
return (
<>
<div className="subtitle">
<Text fontSize="16px" fontWeight="600" className="phone-title">
{t("EnterPhone")}
</Text>
<Text>
{t("CurrentNumber")}: {currentNumber}
</Text>
<Text>
{t("PhoneSubtitle", { productName: t("Common:ProductName") })}
</Text>
</div>
<TextInput
className="phone-input"
id="phone"
name="phone"
type={InputType.phone}
size={InputSize.large}
scale={true}
isAutoFocussed={true}
tabIndex={1}
hasError={false}
guide={false}
value=""
/>
<Button
primary
scale
size={ButtonSize.medium}
label={t("GetCode")}
tabIndex={2}
isDisabled={false}
/>
</>
);
};
export default withLoader(ChangePhoneForm);

View File

@ -0,0 +1,120 @@
// (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
"use client";
import { useContext, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { Link } from "@docspace/shared/components/link";
import { Text } from "@docspace/shared/components/text";
import { toastr } from "@docspace/shared/components/toast";
import { Button, ButtonSize } from "@docspace/shared/components/button";
import withLoader from "@/HOCs/withLoader";
import { TError } from "@/types";
import { continuePortal } from "@/utils/actions";
import { ConfirmRouteContext } from "../ConfirmRoute";
import { ButtonsWrapper } from "../StyledConfirm.styled";
const ContinuePortalForm = () => {
const { t } = useTranslation(["Confirm", "Common"]);
const { linkData } = useContext(ConfirmRouteContext);
const [isReactivate, setIsReactivate] = useState(false);
const onRestoreClick = async () => {
try {
await continuePortal(linkData.confirmHeader);
setIsReactivate(true);
setTimeout(() => (window.location.href = "/"), 10000);
} catch (error) {
const knownError = error as TError;
let errorMessage: string;
if (typeof knownError === "object") {
errorMessage =
knownError?.response?.data?.error?.message ||
knownError?.statusText ||
knownError?.message ||
"";
} else {
errorMessage = knownError;
}
toastr.error(errorMessage);
console.error(errorMessage);
}
};
const onCancelClick = () => {
location.href = "/";
};
return (
<>
{isReactivate ? (
<Text>
<Trans t={t} i18nKey="SuccessReactivate" ns="Confirm">
Your account has been successfully reactivated. In 10 seconds you
will be redirected to the
<Link isHovered href="/">
portal
</Link>
</Trans>
</Text>
) : (
<>
<Text className="subtitle">
{t("PortalContinueTitle", {
productName: t("Common:ProductName"),
})}
</Text>
<ButtonsWrapper>
<Button
primary
scale
size={ButtonSize.medium}
label={t("Reactivate")}
tabIndex={1}
onClick={onRestoreClick}
/>
<Button
scale
size={ButtonSize.medium}
label={t("Common:CancelButton")}
tabIndex={1}
onClick={onCancelClick}
/>
</ButtonsWrapper>
</>
)}
</>
);
};
export default withLoader(ContinuePortalForm);

View File

@ -0,0 +1,127 @@
// (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
"use client";
import { useContext, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { Text } from "@docspace/shared/components/text";
import { Link } from "@docspace/shared/components/link";
import { Button, ButtonSize } from "@docspace/shared/components/button";
import { toastr } from "@docspace/shared/components/toast";
import withLoader from "@/HOCs/withLoader";
import { suspendPortal } from "@/utils/actions";
import { TError, WithLoaderProps } from "@/types";
import { URL_ONLYOFFICE } from "@/utils/constants";
import { ButtonsWrapper } from "../StyledConfirm.styled";
import { ConfirmRouteContext } from "../ConfirmRoute";
type DeactivatePortalProps = {
siteUrl?: string;
} & WithLoaderProps;
const DeactivatePortalForm = ({ siteUrl }: DeactivatePortalProps) => {
const { t } = useTranslation(["Confirm", "Common"]);
const { linkData } = useContext(ConfirmRouteContext);
const [isDeactivate, setIsDeactivate] = useState(false);
const url = siteUrl ? siteUrl : URL_ONLYOFFICE;
const onDeactivateClick = async () => {
try {
await suspendPortal(linkData.confirmHeader);
setIsDeactivate(true);
setTimeout(() => (window.location.href = url), 10000);
} catch (error) {
const knownError = error as TError;
let errorMessage: string;
if (typeof knownError === "object") {
errorMessage =
knownError?.response?.data?.error?.message ||
knownError?.statusText ||
knownError?.message ||
"";
} else {
errorMessage = knownError;
}
toastr.error(errorMessage);
console.error(errorMessage);
}
};
const onCancelClick = () => {
location.href = "/";
};
return (
<>
{isDeactivate ? (
<Text>
<Trans t={t} i18nKey="SuccessDeactivate" ns="Confirm">
Your account has been successfully deactivated. In 10 seconds you
will be redirected to the
<Link isHovered href={url}>
site
</Link>
</Trans>
</Text>
) : (
<>
<Text className="subtitle">
{t("PortalDeactivateTitle", {
productName: t("Common:ProductName"),
})}
</Text>
<ButtonsWrapper>
<Button
scale
primary
size={ButtonSize.medium}
label={t("Settings:Deactivate")}
tabIndex={1}
onClick={onDeactivateClick}
/>
<Button
scale
size={ButtonSize.medium}
label={t("Common:CancelButton")}
tabIndex={1}
onClick={onCancelClick}
/>
</ButtonsWrapper>
</>
)}
</>
);
};
export default withLoader(DeactivatePortalForm);

View File

@ -0,0 +1,125 @@
// (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
"use client";
import withLoader from "@/HOCs/withLoader";
import { Link } from "@docspace/shared/components/link";
import { Text } from "@docspace/shared/components/text";
import { Trans, useTranslation } from "react-i18next";
import { ButtonsWrapper } from "../StyledConfirm.styled";
import { Button, ButtonSize } from "@docspace/shared/components/button";
import { toastr } from "@docspace/shared/components/toast";
import { useContext, useState } from "react";
import { TError, WithLoaderProps } from "@/types";
import { ConfirmRouteContext } from "../ConfirmRoute";
import { URL_ONLYOFFICE } from "@/utils/constants";
import { deletePortal } from "@/utils/actions";
type RemovePortalFormProps = {
siteUrl?: string;
} & WithLoaderProps;
const RemovePortalForm = ({ siteUrl }: RemovePortalFormProps) => {
const { t } = useTranslation(["Confirm", "Common"]);
const { linkData } = useContext(ConfirmRouteContext);
const [isRemoved, setIsRemoved] = useState(false);
const url = siteUrl ? siteUrl : URL_ONLYOFFICE;
const onDeleteClick = async () => {
try {
const res = await deletePortal(linkData.confirmHeader);
setIsRemoved(true);
console.log("res", res);
setTimeout(() => (location.href = res ? res : url), 10000);
} catch (error) {
const knownError = error as TError;
let errorMessage: string;
if (typeof knownError === "object") {
errorMessage =
knownError?.response?.data?.error?.message ||
knownError?.statusText ||
knownError?.message ||
"";
} else {
errorMessage = knownError;
}
toastr.error(errorMessage);
console.error(errorMessage);
}
};
const onCancelClick = () => {
location.href = "/";
};
return (
<>
{isRemoved ? (
<Text>
<Trans t={t} i18nKey="SuccessRemoved" ns="Confirm">
Your account has been successfully removed. In 10 seconds you will
be redirected to the
<Link isHovered href={url}>
site
</Link>
</Trans>
</Text>
) : (
<>
<Text className="subtitle">
{t("PortalRemoveTitle", {
productName: t("Common:ProductName"),
})}
</Text>
<ButtonsWrapper>
<Button
primary
scale
size={ButtonSize.medium}
label={t("Common:Delete")}
tabIndex={1}
onClick={onDeleteClick}
/>
<Button
scale
size={ButtonSize.medium}
label={t("Common:CancelButton")}
tabIndex={1}
onClick={onCancelClick}
/>
</ButtonsWrapper>
</>
)}
</>
);
};
export default withLoader(RemovePortalForm);