From a7e52c36a0cd6c9651171d48bec68de61e33de33 Mon Sep 17 00:00:00 2001 From: Yazeed Loonat Date: Fri, 13 Dec 2024 10:44:35 -0700 Subject: [PATCH 1/4] feat: before app submission refresh access token --- shared-helpers/src/auth/Timeout.tsx | 2 +- shared-helpers/src/locales/es.json | 5 + shared-helpers/src/locales/general.json | 5 + shared-helpers/src/locales/tl.json | 5 + shared-helpers/src/locales/vi.json | 5 + shared-helpers/src/locales/zh.json | 5 + .../src/pages/applications/review/terms.tsx | 95 +++++++++++++------ 7 files changed, 93 insertions(+), 29 deletions(-) diff --git a/shared-helpers/src/auth/Timeout.tsx b/shared-helpers/src/auth/Timeout.tsx index b1c368742d..779a2471db 100644 --- a/shared-helpers/src/auth/Timeout.tsx +++ b/shared-helpers/src/auth/Timeout.tsx @@ -12,7 +12,7 @@ import { Button, Dialog } from "@bloom-housing/ui-seeds" import { t } from "@bloom-housing/ui-components" import { NavigationContext } from "@bloom-housing/doorway-ui-components" import { MessageContext } from "../utilities/MessageContext" - + const PROMPT_TIMEOUT = 60000 const events = ["mousemove", "keypress", "scroll"] diff --git a/shared-helpers/src/locales/es.json b/shared-helpers/src/locales/es.json index d4a981808f..1ef9b975f0 100644 --- a/shared-helpers/src/locales/es.json +++ b/shared-helpers/src/locales/es.json @@ -1146,6 +1146,11 @@ "region.name": "Región local", "search.filters": "Filtros", "search.totalResults": "Resultados totales", + "session.voided.header": "La sesión expiró", + "session.voided.context1": "Has cerrado sesión y tu solicitud de ", + "session.voided.context2": " no fue presentado. Inicie sesión nuevamente para enviar su solicitud.", + "session.voided.context3": "Serás redirigido a la página de inicio de sesión.", + "session.voided.ok": "DE ACUERDO", "states.AK": "Alaska", "states.AL": "Alabama", "states.AR": "Arkansas", diff --git a/shared-helpers/src/locales/general.json b/shared-helpers/src/locales/general.json index b9bc492c98..d8a1005111 100644 --- a/shared-helpers/src/locales/general.json +++ b/shared-helpers/src/locales/general.json @@ -1099,6 +1099,11 @@ "region.name": "Local Region", "search.filters": "Filters", "search.totalResults": "Total results", + "session.voided.header": "Session expired", + "session.voided.context1": "You've been signed out and your application for ", + "session.voided.context2": " was not submitted. Please sign in again to submit your application.", + "session.voided.context3": "You will be redirected to the sign in page.", + "session.voided.ok": "OK", "states.AK": "Alaska", "states.AL": "Alabama", "states.AR": "Arkansas", diff --git a/shared-helpers/src/locales/tl.json b/shared-helpers/src/locales/tl.json index 58bf7e80b9..8a3bf900d0 100644 --- a/shared-helpers/src/locales/tl.json +++ b/shared-helpers/src/locales/tl.json @@ -1111,6 +1111,11 @@ "region.name": "Lokal na rehiyon", "search.filters": "Mga filter", "search.totalResults": "Kabuuang mga resulta", + "session.voided.header": "Nag-expire na ang session", + "session.voided.context1": "Na-sign out ka at ang iyong aplikasyon para sa ", + "session.voided.context2": " ay hindi naisumite. Mangyaring mag-sign in muli upang isumite ang iyong aplikasyon.", + "session.voided.context3": "Ire-redirect ka sa pahina ng pag-sign in.", + "session.voided.ok": "OK", "states.AK": "Alaska", "states.AL": "Alabama", "states.AR": "Arkansas", diff --git a/shared-helpers/src/locales/vi.json b/shared-helpers/src/locales/vi.json index 1775e83b63..ac7233a752 100644 --- a/shared-helpers/src/locales/vi.json +++ b/shared-helpers/src/locales/vi.json @@ -1149,6 +1149,11 @@ "region.name": "Địa phương", "search.filters": "Bộ lọc", "search.totalResults": "Tổng kết quả", + "session.voided.header": "Phiên đã hết hạn", + "session.voided.context1": "Bạn đã đăng xuất và đơn đăng ký của bạn ", + "session.voided.context2": " đã không được nộp. Vui lòng đăng nhập lại để gửi đơn đăng ký của bạn.", + "session.voided.context3": "Bạn sẽ được chuyển hướng đến trang đăng nhập.", + "session.voided.ok": "ĐƯỢC RỒI", "states.AK": "Alaska", "states.AL": "Alabama", "states.AR": "Arkansas", diff --git a/shared-helpers/src/locales/zh.json b/shared-helpers/src/locales/zh.json index 6b76813021..c26f107287 100644 --- a/shared-helpers/src/locales/zh.json +++ b/shared-helpers/src/locales/zh.json @@ -1149,6 +1149,11 @@ "region.name": "當地地區", "search.filters": "筛选器", "search.totalResults": "總結果", + "session.voided.header": "會話已過期", + "session.voided.context1": "您已退出並且您的申請 ", + "session.voided.context2": " 沒有提交。請重新登入以提交您的申請。", + "session.voided.context3": "您將被重新導向到登入頁面。", + "session.voided.ok": "好的", "states.AK": "Alaska(阿拉斯加州)", "states.AL": "Alabama(阿拉巴馬州)", "states.AR": "Arkansas(阿肯色州)", diff --git a/sites/public/src/pages/applications/review/terms.tsx b/sites/public/src/pages/applications/review/terms.tsx index 2ad01b0f56..fb3c6533db 100644 --- a/sites/public/src/pages/applications/review/terms.tsx +++ b/sites/public/src/pages/applications/review/terms.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from "react" +import React, { useCallback, useContext, useEffect, useState } from "react" import { useRouter } from "next/router" import { useForm } from "react-hook-form" import Markdown from "markdown-to-jsx" @@ -20,14 +20,22 @@ import { MultiselectQuestionsApplicationSectionEnum, } from "@bloom-housing/shared-helpers/src/types/backend-swagger" import ApplicationFormLayout from "../../../layouts/application-form" -import { Button } from "@bloom-housing/ui-seeds" +import { Button, Dialog } from "@bloom-housing/ui-seeds" const ApplicationTerms = () => { const router = useRouter() const { conductor, application, listing } = useFormConductor("terms") - const { applicationsService, profile } = useContext(AuthContext) + const { applicationsService, authService, loadProfile, profile } = useContext(AuthContext) const [apiError, setApiError] = useState(false) const [submitting, setSubmitting] = useState(false) + const [sessionVoided, setSessionVoided] = useState(false) + + const closeCallback = useCallback(() => { + setSubmitting(false) + conductor.reset() + void router.push("/sign-in") + loadProfile() + }, [conductor, router, loadProfile]) let currentPageSection = 4 if (listingSectionQuestions(listing, MultiselectQuestionsApplicationSectionEnum.programs)?.length) @@ -63,33 +71,41 @@ const ApplicationTerms = () => { // @ts-ignore delete application.demographics.spokenLanguageNotListed - applicationsService - .submit({ - body: { - ...application, - reviewStatus: ApplicationReviewStatusEnum.pending, - listings: { - id: listing.id, - }, - appUrl: window.location.origin, - ...(profile && { - user: { - id: profile.id, + authService + .requestNewToken() + .then(() => { + applicationsService + .submit({ + body: { + ...application, + reviewStatus: ApplicationReviewStatusEnum.pending, + listings: { + id: listing.id, + }, + appUrl: window.location.origin, + ...(profile && { + user: { + id: profile.id, + }, + }), + // TODO remove this once this call is changed to the new backend }, - }), - // TODO remove this once this call is changed to the new backend - }, - }) - .then((result) => { - conductor.currentStep.save({ confirmationCode: result.confirmationCode }) - return router.push("/applications/review/confirmation") + }) + .then((result) => { + conductor.currentStep.save({ confirmationCode: result.confirmationCode }) + return router.push("/applications/review/confirmation") + }) + .catch((err) => { + setSubmitting(false) + setApiError(true) + window.scrollTo(0, 0) + console.error(`Error creating application: ${err}`) + throw err + }) }) - .catch((err) => { - setSubmitting(false) - setApiError(true) - window.scrollTo(0, 0) - console.error(`Error creating application: ${err}`) - throw err + .catch((e) => { + console.error(e) + setSessionVoided(true) }) } @@ -103,6 +119,29 @@ const ApplicationTerms = () => { return ( + + + {t("session.voided.header")} + + +

+ {t("session.voided.context1")} + {listing.name} + {t("session.voided.context2")} +

+

{t("session.voided.context3")}

+
+ + + +
Date: Sun, 15 Dec 2024 11:23:06 -0600 Subject: [PATCH 2/4] fix: correctly redirect to login --- sites/public/src/pages/applications/review/terms.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sites/public/src/pages/applications/review/terms.tsx b/sites/public/src/pages/applications/review/terms.tsx index fb3c6533db..e7ad79458d 100644 --- a/sites/public/src/pages/applications/review/terms.tsx +++ b/sites/public/src/pages/applications/review/terms.tsx @@ -31,11 +31,9 @@ const ApplicationTerms = () => { const [sessionVoided, setSessionVoided] = useState(false) const closeCallback = useCallback(() => { - setSubmitting(false) conductor.reset() - void router.push("/sign-in") - loadProfile() - }, [conductor, router, loadProfile]) + loadProfile("/sign-in") + }, [conductor, loadProfile]) let currentPageSection = 4 if (listingSectionQuestions(listing, MultiselectQuestionsApplicationSectionEnum.programs)?.length) @@ -104,6 +102,9 @@ const ApplicationTerms = () => { }) }) .catch((e) => { + // We need to have a valid user when submitting an application. + // If there session is no longer valid we should send them back to login + // This can happen either by auth token being too old or the user logged in a different session and voided this one console.error(e) setSessionVoided(true) }) From 1ad37d3f6c37d08e52ed9056c869660f2d0a966b Mon Sep 17 00:00:00 2001 From: Morgan Ludtke Date: Mon, 16 Dec 2024 16:00:05 -0600 Subject: [PATCH 3/4] fix: review comment --- sites/public/src/pages/applications/review/terms.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/public/src/pages/applications/review/terms.tsx b/sites/public/src/pages/applications/review/terms.tsx index e7ad79458d..2bc675abc6 100644 --- a/sites/public/src/pages/applications/review/terms.tsx +++ b/sites/public/src/pages/applications/review/terms.tsx @@ -103,7 +103,7 @@ const ApplicationTerms = () => { }) .catch((e) => { // We need to have a valid user when submitting an application. - // If there session is no longer valid we should send them back to login + // If their session is no longer valid we should send them back to login // This can happen either by auth token being too old or the user logged in a different session and voided this one console.error(e) setSessionVoided(true) From 37d69c4f6753d75b32fda3573c5abcd6f88bdf18 Mon Sep 17 00:00:00 2001 From: Morgan Ludtke Date: Tue, 17 Dec 2024 17:07:59 -0600 Subject: [PATCH 4/4] fix: adding await --- sites/public/src/pages/applications/review/terms.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sites/public/src/pages/applications/review/terms.tsx b/sites/public/src/pages/applications/review/terms.tsx index 2bc675abc6..7f07737dc3 100644 --- a/sites/public/src/pages/applications/review/terms.tsx +++ b/sites/public/src/pages/applications/review/terms.tsx @@ -30,10 +30,10 @@ const ApplicationTerms = () => { const [submitting, setSubmitting] = useState(false) const [sessionVoided, setSessionVoided] = useState(false) - const closeCallback = useCallback(() => { - conductor.reset() - loadProfile("/sign-in") - }, [conductor, loadProfile]) + const closeCallback = useCallback(async () => { + await router.push("/sign-in") + void loadProfile() + }, [router, loadProfile]) let currentPageSection = 4 if (listingSectionQuestions(listing, MultiselectQuestionsApplicationSectionEnum.programs)?.length)