From 4ea49cdc5ad6f31b6fd2c1beef623cf69729dec1 Mon Sep 17 00:00:00 2001 From: TTPL-RT-52 Date: Thu, 30 May 2024 16:09:42 +0530 Subject: [PATCH] Issue PS-652 fix:Login button position should be dynamic --- src/pages/login.tsx | 323 ++++++++++++++++++++++---------------------- 1 file changed, 158 insertions(+), 165 deletions(-) diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 8a5b6ce2..f6d5913b 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -6,7 +6,7 @@ import { InputAdornment, TextField, } from '@mui/material'; -import React, { useEffect, useMemo, useRef } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import Select, { SelectChangeEvent } from '@mui/material/Select'; import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar'; import { Visibility, VisibilityOff } from '@mui/icons-material'; @@ -16,7 +16,6 @@ import CloseIcon from '@mui/icons-material/Close'; import Image from 'next/image'; import Link from '@mui/material/Link'; import Loader from '../components/Loader'; -// import { getUserId } from '../services/ProfileService'; import MenuItem from '@mui/material/MenuItem'; import appLogo from '../../public/images/appLogo.png'; import config from '../../config.json'; @@ -24,8 +23,6 @@ import { getUserId } from '../services/ProfileService'; import { login } from '../services/LoginService'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useRouter } from 'next/router'; -import { useState } from 'react'; -// import { useLocation } from 'react-router-dom'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; @@ -35,7 +32,6 @@ interface State extends SnackbarOrigin { const LoginPage = () => { const { t } = useTranslation(); - // const { t, i18n } = useTranslation(); const [showPassword, setShowPassword] = useState(false); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); @@ -46,11 +42,12 @@ const LoginPage = () => { const [loading, setLoading] = useState(false); const [selectedLanguage, setSelectedLanguage] = useState('en'); const [language, setLanguage] = useState(selectedLanguage); + const theme = useTheme(); const router = useRouter(); - // const location = useLocation(); const passwordRef = useRef(null); + const loginButtonRef = useRef(null); const DEFAULT_POSITION: Pick = { vertical: 'bottom', @@ -98,7 +95,6 @@ const LoginPage = () => { event.preventDefault(); if (!usernameError && !passwordError) { setLoading(true); - event.preventDefault(); try { const response = await login({ username: username, @@ -158,27 +154,25 @@ const LoginPage = () => { const handleClose = () => { setState({ ...state, openModal: false }); }; - const action = useMemo( - () => ( - - - - - - ), - [t] - ); useEffect(() => { - if (passwordRef.current) { - passwordRef.current.scrollIntoView({ behavior: 'smooth', block: 'end' }); + const handlePasswordFocus = () => { + if (loginButtonRef.current) { + loginButtonRef.current.scrollIntoView({ + behavior: 'smooth', + block: 'center', + }); + } + }; + + const passwordField = passwordRef.current; + if (passwordField) { + passwordField.addEventListener('focus', handlePasswordFocus); + return () => { + passwordField.removeEventListener('focus', handlePasswordFocus); + }; } - }, [passwordRef]); + }, []); return (
@@ -186,7 +180,6 @@ const LoginPage = () => { display="flex" flexDirection="column" bgcolor={theme.palette.warning.A200} - height={'100vh'} > {loading && ( @@ -197,163 +190,164 @@ const LoginPage = () => { alignItems={'center'} justifyContent={'center'} zIndex={99} - sx={{ margin: '32px 0' }} + sx={{ margin: '32px 0 65px' }} > App Logo{' '} + + + + + + + - - - - - - - - - + + + - - - {showPassword ? : } - - - ), - }} - label={t('LOGIN_PAGE.PASSWORD')} - placeholder={t('LOGIN_PAGE.PASSWORD_PLACEHOLDER')} - value={password} - onChange={handlePasswordChange} - error={passwordError} - onFocus={() => - passwordRef.current?.scrollIntoView({ - behavior: 'smooth', - block: 'end', - }) - } - inputRef={passwordRef} - /> - + InputProps={{ + endAdornment: ( + + + {showPassword ? : } + + + ), + }} + label={t('LOGIN_PAGE.PASSWORD')} + placeholder={t('LOGIN_PAGE.PASSWORD_PLACEHOLDER')} + value={password} + onChange={handlePasswordChange} + error={passwordError} + inputRef={passwordRef} + /> + - - - {t('LOGIN_PAGE.FORGOT_PASSWORD')} - - - - setRememberMe(e.target.checked)} /> - {t('LOGIN_PAGE.REMEMBER_ME')} - - + - - + {t('LOGIN_PAGE.FORGOT_PASSWORD')} + + + + setRememberMe(e.target.checked)} /> + {t('LOGIN_PAGE.REMEMBER_ME')} + + + - {showToastMessage && ( - - )} + {showToastMessage && ( + + + + } + /> + )} ); }; @@ -362,7 +356,6 @@ export async function getStaticProps({ locale }: any) { return { props: { ...(await serverSideTranslations(locale, ['common'])), - // Will be passed to the page component as props }, }; }