Skip to content

Commit

Permalink
fix: fix scroll issues (#99)
Browse files Browse the repository at this point in the history
Description:
Fix scroll issues on login, register and PP pages
VAN-1995

Co-authored-by: Ahtesham Quraish <[email protected]>
  • Loading branch information
ahtesham-quraish and Ahtesham Quraish authored Jul 2, 2024
1 parent fbee498 commit 5c6b646
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const getCountryCookieValue = () => {

export const moveScrollToTop = (ref) => {
if (ref?.current?.scrollIntoView) {
ref.current.scrollIntoView({ behavior: 'smooth', block: 'end' });
ref.current.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
};

Expand Down
16 changes: 11 additions & 5 deletions src/forms/login-popup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
TPA_AUTHENTICATION_FAILURE,
} from '../../data/constants';
import { useDispatch, useSelector } from '../../data/storeHooks';
import getAllPossibleQueryParams from '../../data/utils';
import getAllPossibleQueryParams, { moveScrollToTop } from '../../data/utils';
import {
trackForgotPasswordLinkClick, trackLoginPageViewed, trackLoginSuccess, trackRegisterFormToggled,
} from '../../tracking/trackers/login';
Expand All @@ -53,6 +53,7 @@ const LoginForm = () => {

const emailOrUsernameRef = useRef(null);
const socialAuthnButtonRef = useRef(null);
const errorAlertRef = useRef(null);

const loginResult = useSelector(state => state.login.loginResult);
const loginErrorCode = useSelector(state => state.login.loginError?.errorCode);
Expand Down Expand Up @@ -183,6 +184,9 @@ const LoginForm = () => {
if (validationErrors.emailOrUsername || validationErrors.password) {
setFormErrors({ ...validationErrors });
setErrorCode({ type: INVALID_FORM, context: {} });
if (moveScrollToTop) {
moveScrollToTop(errorAlertRef);
}
return;
}

Expand Down Expand Up @@ -222,10 +226,12 @@ const LoginForm = () => {
</div>
</>
)}
<LoginFailureAlert
errorCode={errorCode.type}
context={errorCode.context}
/>
<div ref={errorAlertRef}>
<LoginFailureAlert
errorCode={errorCode.type}
context={errorCode.context}
/>
</div>
{showResetPasswordSuccessBanner && <ResetPasswordSuccess />}
<ThirdPartyAuthAlert
currentProvider={currentProvider}
Expand Down
14 changes: 8 additions & 6 deletions src/forms/progressive-profiling-popup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ProgressiveProfilingForm = () => {
const { formatMessage } = useIntl();
const dispatch = useDispatch();

const progressiveProfilingHeadingRef = useRef(null);
const countryFieldRef = useRef(null);

const countryCookieValue = getCountryCookieValue();
const countryList = useMemo(() => getCountryList(getLocale()), []);
Expand Down Expand Up @@ -137,7 +137,7 @@ const ProgressiveProfilingForm = () => {
e.preventDefault();

if (hasFormErrors()) {
moveScrollToTop(progressiveProfilingHeadingRef);
moveScrollToTop(countryFieldRef);
return;
}
const eventProperties = {
Expand Down Expand Up @@ -177,14 +177,14 @@ const ProgressiveProfilingForm = () => {
if (hasFormErrors() && !hasCountry) {
setFormErrors({ ...formErrors, country: formatMessage(messages.progressiveProfilingCountryFieldErrorMessage) });
setSkipButtonState(FAILURE_STATE);
moveScrollToTop(progressiveProfilingHeadingRef);
moveScrollToTop(countryFieldRef);
} else if (!hasFormErrors() && !hasCountry) {
setFormErrors({
...formErrors,
country: formatMessage(messages.progressiveProfilingCountryFieldBlockingErrorMessage),
});
setSkipButtonState(FAILURE_STATE);
moveScrollToTop(progressiveProfilingHeadingRef);
moveScrollToTop(countryFieldRef);
} else if (hasCountry) {
// link tracker
trackProgressiveProfilingSkipLinkClick(redirectUrl)(e);
Expand All @@ -202,7 +202,6 @@ const ProgressiveProfilingForm = () => {
<h1
className="display-1 font-italic text-center mb-4"
data-testid="progressive-profiling-heading"
ref={progressiveProfilingHeadingRef}
>
{formatMessage(messages.progressiveProfilingFormHeading)}
</h1>
Expand All @@ -214,7 +213,10 @@ const ProgressiveProfilingForm = () => {
<h3 className="mb-2.5 mt-2">
{formatMessage(messages.progressiveProfilingCountryFieldTitle)}
</h3>
<p className="x-small">
<p
className="x-small"
ref={countryFieldRef}
>
{formatMessage(messages.progressiveProfilingCountryFieldInfoMessage)}
</p>
<Form.Group controlId="country" className="mb-4.5">
Expand Down

0 comments on commit 5c6b646

Please sign in to comment.