Skip to content

Commit

Permalink
refactor: created a util for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed Oct 23, 2024
1 parent 07ab16f commit 86e8e78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/common-components/RedirectLogistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AUTHN_PROGRESSIVE_PROFILING, RECOMMENDATIONS, REDIRECT,
} from '../data/constants';
import setCookie from '../data/utils/cookies';
import { redirectWindow } from '../data/utils/dataUtils';

const RedirectLogistration = (props) => {
const {
Expand Down Expand Up @@ -81,9 +82,7 @@ const RedirectLogistration = (props) => {
/>
);
}
setTimeout(() => {
window.location.href = finalRedirectUrl;
}, 400);
redirectWindow(finalRedirectUrl);
}

return null;
Expand Down
5 changes: 2 additions & 3 deletions src/common-components/SocialAuthProviders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LOGIN_PAGE, REGISTER_PAGE, SUPPORTED_ICON_CLASSES,
} from '../data/constants';
import { setCookie } from '../data/utils';
import { redirectWindow } from '../data/utils/dataUtils';

const SocialAuthProviders = (props) => {
const { formatMessage } = useIntl();
Expand All @@ -36,9 +37,7 @@ const SocialAuthProviders = (props) => {
setCookie('marketingEmailsOptIn', registrationFields?.configurableFormFields?.marketingEmailsOptIn);
}
const url = e.currentTarget.dataset.providerUrl;
setTimeout(() => {
window.location.href = getConfig().LMS_BASE_URL + url;
}, 400);
redirectWindow(getConfig().LMS_BASE_URL + url);
}

const socialAuth = socialAuthProviders.map((provider, index) => (
Expand Down
6 changes: 6 additions & 0 deletions src/data/utils/dataUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ export const isHostAvailableInQueryParams = () => {
const queryParams = getAllPossibleQueryParams();
return 'host' in queryParams;
};

export const redirectWindow = (redirectUrl) => {
setTimeout(() => {
window.location.href = redirectUrl;
}, 400);
};

0 comments on commit 86e8e78

Please sign in to comment.