diff --git a/client/src/App/App.jsx b/client/src/App/App.jsx index cbbaf4432..f499cb55c 100644 --- a/client/src/App/App.jsx +++ b/client/src/App/App.jsx @@ -7,13 +7,13 @@ import { connect } from "react-redux"; import { Route, Routes, useNavigate } from "react-router-dom"; import { createStructuredSelector } from "reselect"; import DocumentEditorContainer from "../components/document-editor/document-editor.container"; -import ErrorBoundary from "../components/error-boundary/error-boundary.component"; // Component Imports +import ErrorBoundary from "../components/error-boundary/error-boundary.component"; import LoadingSpinner from "../components/loading-spinner/loading-spinner.component"; import DisclaimerPage from "../pages/disclaimer/disclaimer.page"; import LandingPage from "../pages/landing/landing.page"; import TechPageContainer from "../pages/tech/tech.page.container"; import SimplifiedPartsPageContainer from "../pages/simplified-parts/simplified-parts.page.container.jsx"; -import { setOnline } from "../redux/application/application.actions"; +import { setIsPartsEntry, setOnline } from "../redux/application/application.actions"; import { selectOnline } from "../redux/application/application.selectors"; import { checkUserSession } from "../redux/user/user.actions"; import { selectBodyshop, selectCurrentEula, selectCurrentUser } from "../redux/user/user.selectors"; @@ -39,10 +39,11 @@ const mapStateToProps = createStructuredSelector({ const mapDispatchToProps = (dispatch) => ({ checkUserSession: () => dispatch(checkUserSession()), - setOnline: (isOnline) => dispatch(setOnline(isOnline)) + setOnline: (isOnline) => dispatch(setOnline(isOnline)), + setIsPartsEntry: (isParts) => dispatch(setIsPartsEntry(isParts)) }); -export function App({ bodyshop, checkUserSession, currentUser, online, setOnline, currentEula }) { +export function App({ bodyshop, checkUserSession, currentUser, online, setOnline, setIsPartsEntry, currentEula }) { const client = useSplitClient().client; const [listenersAdded, setListenersAdded] = useState(false); const { t } = useTranslation(); @@ -56,6 +57,12 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline checkUserSession(); }, [checkUserSession, setOnline]); + useEffect(() => { + const pathname = window.location.pathname; + const isParts = pathname.startsWith("/parts/"); + setIsPartsEntry(isParts); + }, [setIsPartsEntry]); + //const b = Grid.useBreakpoint(); // console.log("Breakpoints:", b); diff --git a/client/src/components/sign-in-form/sign-in-form.component.jsx b/client/src/components/sign-in-form/sign-in-form.component.jsx index 637042f54..a72eee218 100644 --- a/client/src/components/sign-in-form/sign-in-form.component.jsx +++ b/client/src/components/sign-in-form/sign-in-form.component.jsx @@ -10,6 +10,7 @@ import RomeLogo from "../../assets/RomeOnlineBlue.png"; import ImEXOnlineLogo from "../../assets/logo192.png"; import { emailSignInStart, sendPasswordReset } from "../../redux/user/user.actions"; import { selectCurrentUser, selectLoginLoading, selectSignInError } from "../../redux/user/user.selectors"; +import { selectIsPartsEntry } from "../../redux/application/application.selectors"; import InstanceRenderManager from "../../utils/instanceRenderMgr"; import AlertComponent from "../alert/alert.component"; import "./sign-in-form.styles.scss"; @@ -17,7 +18,8 @@ import "./sign-in-form.styles.scss"; const mapStateToProps = createStructuredSelector({ currentUser: selectCurrentUser, signInError: selectSignInError, - loginLoading: selectLoginLoading + loginLoading: selectLoginLoading, + isPartsEntry: selectIsPartsEntry }); const mapDispatchToProps = (dispatch) => ({ @@ -25,7 +27,7 @@ const mapDispatchToProps = (dispatch) => ({ sendPasswordReset: (email) => dispatch(sendPasswordReset(email)) }); -export function SignInComponent({ emailSignInStart, currentUser, signInError, sendPasswordReset, loginLoading }) { +export function SignInComponent({ emailSignInStart, currentUser, signInError, loginLoading, isPartsEntry }) { const { redirect } = queryString.parse(useLocation().search); const navigate = useNavigate(); @@ -38,15 +40,16 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se useEffect(() => { if (currentUser.authorized === true) { - navigate(redirect || "/manage/"); + navigate(redirect || (isPartsEntry ? "/parts/" : "/manage/")); } - }, [currentUser, redirect, navigate]); + }, [currentUser, redirect, navigate, isPartsEntry]); useEffect(() => { const handleSeamlessLogin = (event) => { console.log("Received message event:", event); // Log the received message event + if (event.data?.type !== "seamlessLoginRequest") return; // Filter to only handle relevant messages - console.log("Received seamless login request:", event.data); + const { email, password } = event.data || {}; // Use event.data instead of event.detail const requestOrigin = event.origin; // Use event.origin automatically @@ -62,7 +65,7 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se // Check if the user is already logged in if (currentUser.authorized === true) { console.log("User is already logged in, redirecting..."); - navigate(redirect || "/manage/"); + navigate(redirect || (isPartsEntry ? "/parts/" : "/manage/")); window.parent.postMessage({ type: "seamlessLoginResponse", status: "already_logged_in" }, requestOrigin || "*"); return; } @@ -72,12 +75,12 @@ export function SignInComponent({ emailSignInStart, currentUser, signInError, se window.parent.postMessage({ type: "seamlessLoginResponse", status: "login_attempted" }, requestOrigin || "*"); }; - window.addEventListener("message", handleSeamlessLogin); // Listen for "message" + window.addEventListener("message", handleSeamlessLogin); return () => { window.removeEventListener("message", handleSeamlessLogin); }; - }, [emailSignInStart, currentUser, navigate, redirect]); + }, [emailSignInStart, currentUser, navigate, redirect, isPartsEntry]); return (
diff --git a/client/src/redux/application/application.actions.js b/client/src/redux/application/application.actions.js index 4d362c6d8..430408b06 100644 --- a/client/src/redux/application/application.actions.js +++ b/client/src/redux/application/application.actions.js @@ -77,3 +77,8 @@ export const setWssStatus = (status) => ({ type: ApplicationActionTypes.SET_WSS_STATUS, payload: status }); + +export const setIsPartsEntry = (isParts) => ({ + type: ApplicationActionTypes.PARTS_ENTRY, + payload: isParts +}); diff --git a/client/src/redux/application/application.reducer.js b/client/src/redux/application/application.reducer.js index 6d5421e27..1ad66964d 100644 --- a/client/src/redux/application/application.reducer.js +++ b/client/src/redux/application/application.reducer.js @@ -104,6 +104,11 @@ const applicationReducer = (state = INITIAL_STATE, action) => { alerts: newAlertsMap }; } + case ApplicationActionTypes.PARTS_ENTRY: + return { + ...state, + isPartsEntry: action.payload + }; default: return state; } diff --git a/client/src/redux/application/application.selectors.js b/client/src/redux/application/application.selectors.js index 6b0d1c2c4..99ffd5b22 100644 --- a/client/src/redux/application/application.selectors.js +++ b/client/src/redux/application/application.selectors.js @@ -24,3 +24,4 @@ export const selectProblemJobs = createSelector([selectApplication], (applicatio export const selectUpdateAvailable = createSelector([selectApplication], (application) => application.updateAvailable); export const selectWssStatus = createSelector([selectApplication], (application) => application.wssStatus); export const selectAlerts = createSelector([selectApplication], (application) => application.alerts); +export const selectIsPartsEntry = createSelector([selectApplication], (application) => application.isPartsEntry); diff --git a/client/src/redux/application/application.types.js b/client/src/redux/application/application.types.js index 26c1b4c7d..7699eb9f3 100644 --- a/client/src/redux/application/application.types.js +++ b/client/src/redux/application/application.types.js @@ -14,6 +14,7 @@ const ApplicationActionTypes = { SET_PROBLEM_JOBS: "SET_PROBLEM_JOBS", SET_UPDATE_AVAILABLE: "SET_UPDATE_AVAILABLE", SET_WSS_STATUS: "SET_WSS_STATUS", - ADD_ALERTS: "ADD_ALERTS" + ADD_ALERTS: "ADD_ALERTS", + PARTS_ENTRY: "PARTS_ENTRY" }; export default ApplicationActionTypes;