Skip to content

Commit

Permalink
routing on login for ACB students joined using referal link and alrea…
Browse files Browse the repository at this point in the history
…dy enrolled ACB students
  • Loading branch information
psd9988 committed Nov 29, 2023
1 parent 3161dea commit 95d10ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.inlineSuggest.showToolbar": "onHover"
}
46 changes: 36 additions & 10 deletions src/pages/Login/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { Redirect } from "react-router-dom";
import { Redirect, useHistory, useLocation } from "react-router-dom";
import GoogleLogin from "react-google-login";
import axios from "axios";
import { actions as userActions } from "../../components/User/redux/action";
Expand All @@ -14,12 +14,10 @@ import useMediaQuery from "@mui/material/useMediaQuery";
import GoogleIcon from "./assets/GoogleIcon";
import useStyles from "./styles";
import { breakpoints } from "../../theme/constant";
import { useParams } from "react-router-dom";

function Login(props) {
// for amazon coding bootcamp redirect:-
const { utm_medium } = useParams();
// console.log(utm_medium);
const history = useHistory();
const location = useLocation();
const [queryString, setqueryString] = useState(null);
const user = useSelector(({ User }) => User);
const dispatch = useDispatch();
Expand Down Expand Up @@ -71,6 +69,11 @@ function Login(props) {
pathway.data.pathways.find((pathway) => pathway.code === "PRGPYT");
const pythonPathwayId = pythonPathway && pythonPathway.id;

const amazonPathway =
pathway.data &&
pathway.data.pathways.find((pathway) => pathway.code === "ACB");
const amazonPathwayId = amazonPathway && amazonPathway.id;

const rolesLandingPages = {
volunteer: PATHS.CLASS,
admin: PATHS.PARTNERS,
Expand All @@ -89,7 +92,18 @@ function Login(props) {
},
data: { referrer: queryString },
})
.then((res) => {})
.then((res) => {
// For ACB Students joining using referrer link redirection below:-
const queryParams = new URLSearchParams(location.search);
const referrer = queryParams.get("referrer");
if (referrer.includes("amazon")) {
history.push(
interpolatePath(PATHS.PATHWAY_COURSE, {
pathwayId: amazonPathwayId,
})
);
}
})
.catch((err) => {});
}
if (props.location.state == "/volunteer-with-us") {
Expand All @@ -102,6 +116,22 @@ function Login(props) {
if (props.location.state) {
return <Redirect to={props.location.state.from.pathname} />;
}

// For already registered ACB Students redirection below:-
if (
data?.user?.partner_id == 932 &&
!data?.user?.rolesList.includes("partner") &&
!data?.user?.rolesList.includes("admin")
) {
return (
<Redirect
to={interpolatePath(PATHS.PATHWAY_COURSE, {
pathwayId: amazonPathwayId,
})}
/>
);
}

return (
<>
{pythonPathwayId && (
Expand All @@ -114,11 +144,7 @@ function Login(props) {
}

if (rolesList != false) {

if (!(rolesList.includes("partner") || rolesList.includes("admin"))) {
if (utm_medium.includes("amazon")) {
return <Redirect to={"/pathway/:7"} />;
}
return <Redirect to={PATHS.COURSE} />;
}
} else if (rolesList.length == 0) {
Expand Down

0 comments on commit 95d10ce

Please sign in to comment.