From 86109eef9be95d8286d2b6d40d9812281b738919 Mon Sep 17 00:00:00 2001 From: Cade Wolcott Date: Tue, 26 Nov 2024 11:47:45 -0600 Subject: [PATCH 1/4] feat: allow redirect after sign in --- app/javascript/authentication/SignInForm.tsx | 4 ++-- app/javascript/pages/account/my-account.tsx | 1 + app/javascript/util/routeUtil.ts | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/javascript/authentication/SignInForm.tsx b/app/javascript/authentication/SignInForm.tsx index cbb63df6b..69c7538c3 100644 --- a/app/javascript/authentication/SignInForm.tsx +++ b/app/javascript/authentication/SignInForm.tsx @@ -13,7 +13,7 @@ import { } from "@bloom-housing/ui-components" import { useForm } from "react-hook-form" -import { getMyAccountPath } from "../util/routeUtil" +import { getSignInRedirectUrl } from "../util/routeUtil" import UserContext from "./context/UserContext" import EmailFieldset from "../pages/account/components/EmailFieldset" import PasswordFieldset from "../pages/account/components/PasswordFieldset" @@ -35,7 +35,7 @@ const SignInForm = () => { signIn(email, password) .then(() => { - window.location.href = getMyAccountPath() + window.location.href = getSignInRedirectUrl() window.scrollTo(0, 0) }) .catch(() => { diff --git a/app/javascript/pages/account/my-account.tsx b/app/javascript/pages/account/my-account.tsx index 578a4a381..06ba1193f 100644 --- a/app/javascript/pages/account/my-account.tsx +++ b/app/javascript/pages/account/my-account.tsx @@ -62,6 +62,7 @@ const MyAccount = (_props: MyAccountProps) => { const { profile, loading, initialStateLoaded } = React.useContext(UserContext) if (!profile && !loading && initialStateLoaded) { + window.sessionStorage.setItem("redirect", "account") // TODO: Redirect to React sign in page and show a message that user needs to sign in window.location.href = getSignInPath() return null diff --git a/app/javascript/util/routeUtil.ts b/app/javascript/util/routeUtil.ts index 6a85f17da..f19f7a0ee 100644 --- a/app/javascript/util/routeUtil.ts +++ b/app/javascript/util/routeUtil.ts @@ -74,3 +74,22 @@ export const getEligibilityEstimatorLink = localizedPathGetter("/eligibility-est // Footer export const getDisclaimerPath = localizedPathGetter("/disclaimer") export const getPrivacyPolicyPath = localizedPathGetter("/privacy") + +const SignInRedirects = { + account: getMyAccountPath(), + applications: getMyApplicationsPath(), + settings: getMyAccountSettingsPath(), + home: getHomepagePath(), +} + +const getRedirectUrl = (key: string): string => { + console.log("getting redirect for", key) + return SignInRedirects[key] || SignInRedirects.home +} + +export const getSignInRedirectUrl = () => { + const redirect = window.sessionStorage.getItem("redirect") + window.sessionStorage.removeItem("redirect") + + return getRedirectUrl(redirect || "account") +} From 24ea89d5a1c4f7171b34c655ae522d6a19c9ffde Mon Sep 17 00:00:00 2001 From: Cade Wolcott Date: Wed, 27 Nov 2024 14:37:44 -0600 Subject: [PATCH 2/4] feat: check for redirect after sign in --- app/javascript/authentication/SignInForm.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/authentication/SignInForm.tsx b/app/javascript/authentication/SignInForm.tsx index bcddc80be..7abddeaf3 100644 --- a/app/javascript/authentication/SignInForm.tsx +++ b/app/javascript/authentication/SignInForm.tsx @@ -14,7 +14,7 @@ import { import { Dialog, Link, Heading, Alert } from "@bloom-housing/ui-seeds" import { FieldValues, SubmitHandler, useForm } from "react-hook-form" -import { getMyAccountPath } from "../util/routeUtil" +import { getSignInRedirectUrl } from "../util/routeUtil" import EmailFieldset from "../pages/account/components/EmailFieldset" import PasswordFieldset from "../pages/account/components/PasswordFieldset" import "../pages/account/styles/account.scss" @@ -143,7 +143,7 @@ const SignInForm = () => { signIn(email, password) .then(() => { - window.location.href = getMyAccountPath() + window.location.href = getSignInRedirectUrl() window.scrollTo(0, 0) }) .catch((error: AxiosError<{ error: string; email: string }>) => { From b45150ed4e5a76070b7f64bf48518ec7b782cfd5 Mon Sep 17 00:00:00 2001 From: Cade Wolcott Date: Tue, 10 Dec 2024 15:05:16 -0600 Subject: [PATCH 3/4] feat: redirect and show requireLogin banner --- app/assets/json/translations/react/en.json | 1 + app/javascript/__tests__/pages/SignIn.test.tsx | 10 ++++++++++ app/javascript/pages/account/account-settings.tsx | 4 +++- app/javascript/pages/account/my-account.tsx | 3 ++- app/javascript/pages/account/my-applications.tsx | 3 +++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/assets/json/translations/react/en.json b/app/assets/json/translations/react/en.json index ad3ed0afe..3b4bb14cc 100644 --- a/app/assets/json/translations/react/en.json +++ b/app/assets/json/translations/react/en.json @@ -1575,6 +1575,7 @@ "signIn.fillInFaster": "Fill in applications faster", "signIn.forgotPassword": "Forgot password?", "signIn.loggedOutDueToInactivity": "We care about your security. We logged you out due to inactivity. Please sign in to continue.", + "signIn.loginRequired": "You must be signed in to see this page. Sign in to continue.", "signIn.newAccount.p1": "We sent a link to %{email}.", "signIn.newAccount.p2": "Follow the link in your email to finish creating your account. It expires after 24 hours.", "signIn.newAccount.sendEmailAgainButton": "Send email again", diff --git a/app/javascript/__tests__/pages/SignIn.test.tsx b/app/javascript/__tests__/pages/SignIn.test.tsx index dc6fd729e..3b05bdcf0 100644 --- a/app/javascript/__tests__/pages/SignIn.test.tsx +++ b/app/javascript/__tests__/pages/SignIn.test.tsx @@ -284,6 +284,16 @@ describe("", () => { }) }) + it("shows the sign in required banner", async () => { + window.sessionStorage.setItem("alert_message_secondary", t("signIn.loginRequired")) + + render() + window.sessionStorage.setItem("redirect", "account") + + await renderAndLoadAsync() + expect(screen.getByText(t("signIn.loginRequired"))).not.toBeNull() + }) + it("shows the timeout limit banner", async () => { const mockGetItem = jest.fn() const mockSetItem = jest.fn() diff --git a/app/javascript/pages/account/account-settings.tsx b/app/javascript/pages/account/account-settings.tsx index 7587410eb..6869f80c3 100644 --- a/app/javascript/pages/account/account-settings.tsx +++ b/app/javascript/pages/account/account-settings.tsx @@ -41,6 +41,7 @@ import { FormHeader, FormSection, getDobStringFromDobObject } from "../../util/a import { AxiosError } from "axios" import { ErrorSummaryBanner } from "./components/ErrorSummaryBanner" import { ExpandedAccountAxiosError, getErrorMessage } from "./components/util" +import { setSiteAlertMessage } from "../../components/SiteAlert" const Banner = ({ showBanner, @@ -456,7 +457,8 @@ const AccountSettingsPage = () => { const { profile, loading, initialStateLoaded } = React.useContext(UserContext) if (!profile && !loading && initialStateLoaded) { - // TODO: Redirect to React sign in page and show a message that user needs to sign in + window.sessionStorage.setItem("redirect", "settings") + setSiteAlertMessage(t("signIn.loginRequired"), "secondary") window.location.href = getSignInPath() return null } diff --git a/app/javascript/pages/account/my-account.tsx b/app/javascript/pages/account/my-account.tsx index 06ba1193f..6071b10d5 100644 --- a/app/javascript/pages/account/my-account.tsx +++ b/app/javascript/pages/account/my-account.tsx @@ -10,6 +10,7 @@ import { getSignInPath, } from "../../util/routeUtil" import { renderInlineMarkup } from "../../util/languageUtil" +import { setSiteAlertMessage } from "../../components/SiteAlert" interface MyAccountProps { assetPaths: unknown @@ -63,7 +64,7 @@ const MyAccount = (_props: MyAccountProps) => { if (!profile && !loading && initialStateLoaded) { window.sessionStorage.setItem("redirect", "account") - // TODO: Redirect to React sign in page and show a message that user needs to sign in + setSiteAlertMessage(t("signIn.loginRequired"), "secondary") window.location.href = getSignInPath() return null } diff --git a/app/javascript/pages/account/my-applications.tsx b/app/javascript/pages/account/my-applications.tsx index 35737ffce..d47ac6d5c 100644 --- a/app/javascript/pages/account/my-applications.tsx +++ b/app/javascript/pages/account/my-applications.tsx @@ -21,6 +21,7 @@ import "./styles/my-applications.scss" import { DoubleSubmittedModal } from "./components/DoubleSubmittedModal" import { AlreadySubmittedModal } from "./components/AlreadySubmittedModal" import { extractModalParamsFromUrl } from "./components/util" +import { setSiteAlertMessage } from "../../components/SiteAlert" export const noApplications = () => { return ( @@ -198,6 +199,8 @@ const MyApplications = () => { }, [authLoading, initialStateLoaded, profile]) if (!profile && !authLoading && initialStateLoaded) { + window.sessionStorage.setItem("redirect", "applications") + setSiteAlertMessage(t("signIn.loginRequired"), "secondary") window.location.href = getSignInPath() return null } From da08a114bc83d5e1d1b5c30a2b9218820310ce41 Mon Sep 17 00:00:00 2001 From: Cade Wolcott Date: Mon, 16 Dec 2024 14:07:35 -0600 Subject: [PATCH 4/4] fix: remove log --- app/javascript/util/routeUtil.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/javascript/util/routeUtil.ts b/app/javascript/util/routeUtil.ts index ee6221aed..f17f21adb 100644 --- a/app/javascript/util/routeUtil.ts +++ b/app/javascript/util/routeUtil.ts @@ -84,7 +84,6 @@ const SignInRedirects = { } const getRedirectUrl = (key: string): string => { - console.log("getting redirect for", key) return SignInRedirects[key] || SignInRedirects.home }