diff --git a/apps/condo/domains/common/components/HeaderActions.tsx b/apps/condo/domains/common/components/HeaderActions.tsx index 966b7b5c416..8e038a0b5b1 100644 --- a/apps/condo/domains/common/components/HeaderActions.tsx +++ b/apps/condo/domains/common/components/HeaderActions.tsx @@ -1,9 +1,10 @@ import { Tabs } from 'antd' -import Router from 'next/router' +import { useRouter } from 'next/router' import React from 'react' import { useIntl } from '@open-condo/next/intl' +import { isSafeUrl } from '@condo/domains/common/utils/url.utils' import { RemoveTabsLineWrapper } from '@condo/domains/user/components/containers/styles' interface ITabsActionsProps { @@ -16,16 +17,25 @@ export const TabsAuthAction: React.FC = (props) => { const registerTab = intl.formatMessage({ id: 'pages.auth.RegistrationTitle' }) const signInTab = intl.formatMessage({ id: 'pages.auth.SignInTitle' }) + const router = useRouter() + const { query: { next } } = router + const isValidNextUrl = next && !Array.isArray(next) && isSafeUrl(next) + return ( Router.push(activeKey)} + onChange={(activeKey) => { + if (activeKey === 'signin') { + router.push(isValidNextUrl ? `/auth/signin?next=${encodeURIComponent(next)}` : '/auth/signin') + } else if (activeKey === 'register') { + router.push(isValidNextUrl ? `/auth/register?step=inputPhone&next=${encodeURIComponent(next)}` : '/auth/register') + }}} centered animated={false} > - - + + ) diff --git a/apps/condo/domains/user/components/auth/InputPhoneForm.tsx b/apps/condo/domains/user/components/auth/InputPhoneForm.tsx index 3ee511310b8..cddcd799c39 100644 --- a/apps/condo/domains/user/components/auth/InputPhoneForm.tsx +++ b/apps/condo/domains/user/components/auth/InputPhoneForm.tsx @@ -1,6 +1,6 @@ import { Col, Form, Row, RowProps, Typography } from 'antd' import getConfig from 'next/config' -import Router from 'next/router' +import { useRouter } from 'next/router' import React, { useCallback, useContext, useMemo, useState } from 'react' import { useMutation } from '@open-condo/next/apollo' @@ -9,18 +9,17 @@ import { FormattedMessage } from '@open-condo/next/intl' import { Button } from '@condo/domains/common/components/Button' import { TabsAuthAction } from '@condo/domains/common/components/HeaderActions' -import { SberIconWithoutLabel } from '@condo/domains/common/components/icons/SberIcon' +import { LoginWithSBBOLButton } from '@condo/domains/common/components/LoginWithSBBOLButton' import { PhoneInput } from '@condo/domains/common/components/PhoneInput' import { colors } from '@condo/domains/common/constants/style' import { runMutation } from '@condo/domains/common/utils/mutations.utils' import { normalizePhone } from '@condo/domains/common/utils/phone' +import { isSafeUrl } from '@condo/domains/common/utils/url.utils' import { getClientSideSenderInfo } from '@condo/domains/common/utils/userid.utils' import { ResponsiveCol } from '@condo/domains/user/components/containers/ResponsiveCol' import { TOO_MANY_REQUESTS } from '@condo/domains/user/constants/errors' import { START_CONFIRM_PHONE_MUTATION } from '@condo/domains/user/gql' - - import { RegisterContext } from './RegisterContextProvider' @@ -32,7 +31,7 @@ const FORM_PARAGRAPH_STYLES: React.CSSProperties = { fontSize: '12px', } const FORM_TYPOGRAPHY_STYLES: React.CSSProperties = { - textAlign:'center', + textAlign: 'center', } const FORM_PHONE_STYLES: React.CSSProperties = { borderRadius: 8, @@ -53,7 +52,6 @@ export const InputPhoneForm: React.FC = ({ onFinish }) => const SMSTooManyRequestsErrorMsg = intl.formatMessage({ id: 'pages.auth.TooManyRequests' }) const WrongPhoneFormatErrorMsg = intl.formatMessage({ id: 'api.common.WRONG_PHONE_FORMAT' }) const RegisterMsg = intl.formatMessage({ id: 'Register' }) - const LoginBySBBOLMsg = intl.formatMessage({ id: 'LoginBySBBOL' }) const ConsentContent = intl.formatMessage({ id: 'pages.auth.register.info.ConsentContent' }) const PrivacyPolicyContent = intl.formatMessage({ id: 'pages.auth.register.info.PrivacyPolicyContent' }) const TermsOfUseContent = intl.formatMessage({ id: 'pages.auth.register.info.termsOfUseContent' }) @@ -62,6 +60,9 @@ export const InputPhoneForm: React.FC = ({ onFinish }) => const { publicRuntimeConfig: { hasSbbolAuth } } = getConfig() + const router = useRouter() + const { query: { next } } = router + const redirectUrl = (next && !Array.isArray(next) && isSafeUrl(next)) ? next : '/' const { setToken, setPhone, handleCaptchaVerify } = useContext(RegisterContext) const [isLoading, setIsLoading] = useState(false) const [startPhoneVerify] = useMutation(START_CONFIRM_PHONE_MUTATION) @@ -119,7 +120,7 @@ export const InputPhoneForm: React.FC = ({ onFinish }) => onCompleted: (data) => { const { data: { result: { token } } } = data setToken(token) - Router.push(`/auth/register?token=${token}`) + router.push(`/auth/register?token=${token}`) onFinish() }, // Skip notification @@ -136,7 +137,7 @@ export const InputPhoneForm: React.FC = ({ onFinish }) => return ( - +
= ({ onFinish }) => - - + + diff --git a/apps/condo/domains/user/components/auth/SignInForm.tsx b/apps/condo/domains/user/components/auth/SignInForm.tsx index 68524c8e17a..669ce9ac802 100644 --- a/apps/condo/domains/user/components/auth/SignInForm.tsx +++ b/apps/condo/domains/user/components/auth/SignInForm.tsx @@ -1,6 +1,6 @@ import { Col, Form, Row, RowProps, Typography } from 'antd' import getConfig from 'next/config' -import Router, { useRouter } from 'next/router' +import { useRouter } from 'next/router' import React, { useCallback, useMemo, useState } from 'react' import { useMutation } from '@open-condo/next/apollo' @@ -139,7 +139,7 @@ export const SignInForm = (): React.ReactElement => { link: ( Router.push('/auth/forgot')}> + onClick={() => router.push('/auth/forgot')}> {ResetMsg} ), @@ -169,8 +169,8 @@ export const SignInForm = (): React.ReactElement => { - - + + diff --git a/apps/condo/pages/auth/signin.tsx b/apps/condo/pages/auth/signin.tsx index 9225230611e..cee7b4b63a9 100644 --- a/apps/condo/pages/auth/signin.tsx +++ b/apps/condo/pages/auth/signin.tsx @@ -18,7 +18,7 @@ const SignInPage: AuthPage = () => { {SignInTitleMsg} - +