diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/index.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/index.js index 70ee4f738a..21ddb5c649 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/index.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/index.js @@ -4,7 +4,7 @@ import { withTranslation } from "react-i18next"; import Text from "@appserver/components/text"; import { setDocumentTitle } from "../../../../../../helpers/utils"; import { MainContainer } from "../StyledSecurity"; -import TfaSection from "../sub-components/tfa"; +import TfaSection from "./tfa"; import MobileView from "./mobileView"; import { isMobile } from "react-device-detect"; import CategoryWrapper from "../sub-components/category-wrapper"; diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/tfa.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/tfa.js new file mode 100644 index 0000000000..44ed7e9266 --- /dev/null +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/security/access-portal/tfa.js @@ -0,0 +1,176 @@ +import React, { useState, useEffect } from "react"; +import styled from "styled-components"; +import { withRouter } from "react-router"; +import { withTranslation } from "react-i18next"; +import { inject, observer } from "mobx-react"; +import RadioButtonGroup from "@appserver/components/radio-button-group"; +import Button from "@appserver/components/button"; +import Text from "@appserver/components/text"; +import toastr from "@appserver/components/toast/toastr"; +import SectionLoader from "../sub-components/section-loader"; + +const MainContainer = styled.div` + width: 100%; + + .box { + margin-bottom: 24px; + } +`; + +const ButtonsWrapper = styled.div` + display: flex; + flex-direction: row; + gap: 8px; + align-items: center; + + @media (max-width: 375px) { + position: absolute; + bottom: 16px; + width: calc(100vw - 32px); + + .button { + height: 40px; + width: 100%; + } + + .reminder { + position: absolute; + bottom: 48px; + } + } +`; + +const TwoFactorAuth = (props) => { + const { t } = props; + const [type, setType] = useState("none"); + const [currentState, setCurrentState] = useState(""); + const [smsDisabled, setSmsDisabled] = useState(false); + const [appDisabled, setAppDisabled] = useState(false); + const [showReminder, setShowReminder] = useState(false); + const [isLoading, setIsLoading] = useState(false); + + const getSettings = async () => { + const { getTfaType, getTfaSettings } = props; + const type = await getTfaType(); + setType(type); + + const settings = await getTfaSettings(); + setSmsDisabled(settings[0].avaliable); + setAppDisabled(settings[1].avaliable); + }; + + useEffect(() => { + getSettings(); + setCurrentState(type); + setIsLoading(true); + }, []); + + const onSelectTfaType = (e) => { + if (type !== e.target.value) { + setType(e.target.value); + setShowReminder(true); + } + if (e.target.value === currentState) { + setShowReminder(false); + } + }; + + const onSaveClick = () => { + const { t, setTfaSettings, getTfaConfirmLink, history } = props; + + setTfaSettings(type).then((res) => { + toastr.success(t("SuccessfullySaveSettingsMessage")); + if (type !== "none") { + getTfaConfirmLink(res).then((link) => + history.push(link.replace(window.location.origin, "")) + ); + } + setType(type); + setShowReminder(false); + }); + }; + + const onCancelClick = () => { + setShowReminder(false); + setType(currentState); + }; + + if (!isLoading) return ; + return ( + + + + +