Skip to content

Commit

Permalink
fix(condo): DOMA-9899 keep deeplink when changing sign in to register (
Browse files Browse the repository at this point in the history
…#5074)

* fix(condo): DOMA-9899 keep deeplink when changing sign in to register

* fix(condo): DOMA-9899 conversion onChange is Tabs component

* fix(condo): DOMA-9899 first version of changes in sbball

* fix(condo): DOMA-9899 add encoded next, add redirect next sbbol auth

* fix(condo): DOMA-9899 fix lint code

* fix(condo): DOMA-9899 add different between two files
  • Loading branch information
tolmachev21 authored Aug 16, 2024
1 parent b74d2bb commit 1795271
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
18 changes: 14 additions & 4 deletions apps/condo/domains/common/components/HeaderActions.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,16 +17,25 @@ export const TabsAuthAction: React.FC<ITabsActionsProps> = (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 (
<RemoveTabsLineWrapper>
<Tabs
defaultActiveKey={currentActiveKey}
onChange={(activeKey) => 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}
>
<Tabs.TabPane key='/auth/register?step=inputPhone' tab={registerTab}/>
<Tabs.TabPane key='/auth/signin' tab={signInTab}/>
<Tabs.TabPane key='register' tab={registerTab}/>
<Tabs.TabPane key='signin' tab={signInTab}/>
</Tabs>
</RemoveTabsLineWrapper>
)
Expand Down
30 changes: 11 additions & 19 deletions apps/condo/domains/user/components/auth/InputPhoneForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'


Expand All @@ -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,
Expand All @@ -53,7 +52,6 @@ export const InputPhoneForm: React.FC<IInputPhoneFormProps> = ({ 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' })
Expand All @@ -62,6 +60,9 @@ export const InputPhoneForm: React.FC<IInputPhoneFormProps> = ({ 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)
Expand Down Expand Up @@ -119,7 +120,7 @@ export const InputPhoneForm: React.FC<IInputPhoneFormProps> = ({ 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
Expand All @@ -136,7 +137,7 @@ export const InputPhoneForm: React.FC<IInputPhoneFormProps> = ({ onFinish }) =>
return (
<Row justify='center'>
<Col span={16}>
<TabsAuthAction currentActiveKey='/auth/register'/>
<TabsAuthAction currentActiveKey='register' />
</Col>
<Col span={24}>
<Form
Expand Down Expand Up @@ -222,17 +223,8 @@ export const InputPhoneForm: React.FC<IInputPhoneFormProps> = ({ onFinish }) =>
<FormattedMessage id='Or'/>
</Col>
<Col span={24}>
<Form.Item>
<Button
key='submit'
type='sberAction'
secondary
icon={<SberIconWithoutLabel/>}
href='/api/sbbol/auth'
block
>
{LoginBySBBOLMsg}
</Button>
<Form.Item id='inputPhoneSBBOL'>
<LoginWithSBBOLButton redirect={redirectUrl} block checkTlsCert />
</Form.Item>
</Col>
</>
Expand Down
8 changes: 4 additions & 4 deletions apps/condo/domains/user/components/auth/SignInForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -139,7 +139,7 @@ export const SignInForm = (): React.ReactElement => {
link: (
<Typography.Link
style={{ color: colors.black }}
onClick={() => Router.push('/auth/forgot')}>
onClick={() => router.push('/auth/forgot')}>
{ResetMsg}
</Typography.Link>
),
Expand Down Expand Up @@ -169,8 +169,8 @@ export const SignInForm = (): React.ReactElement => {
<FormattedMessage id='Or'/>
</Col>
<Col span={24}>
<Form.Item>
<LoginWithSBBOLButton block checkTlsCert/>
<Form.Item id='signInSBBOL'>
<LoginWithSBBOLButton redirect={redirectUrl} block checkTlsCert/>
</Form.Item>
</Col>
</>
Expand Down
2 changes: 1 addition & 1 deletion apps/condo/pages/auth/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SignInPage: AuthPage = () => {
<Head><title>{SignInTitleMsg}</title></Head>
<Row justify='center'>
<Col span={16}>
<TabsAuthAction currentActiveKey='/auth/signin'/>
<TabsAuthAction currentActiveKey='signin'/>
</Col>
<Col span={24}>
<SignInForm/>
Expand Down

0 comments on commit 1795271

Please sign in to comment.