From 70afb70c1ee7d64ca84f45020a275854b9a4cd01 Mon Sep 17 00:00:00 2001 From: ColinBuyck <53269332+ColinBuyck@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:54:42 -0800 Subject: [PATCH] fix: updated application checks (#656) * fix: updated application checks * fix: remove button differences --- .../listing/GetApplication.test.tsx | 35 +++++++++++++++++-- .../src/components/listing/GetApplication.tsx | 9 +++-- .../src/components/listing/ListingView.tsx | 2 ++ .../src/pages/applications/review/summary.tsx | 14 +++++--- .../applications/start/choose-language.tsx | 11 +++--- .../src/pages/preview/listings/[id].tsx | 2 +- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/sites/public/__tests__/components/listing/GetApplication.test.tsx b/sites/public/__tests__/components/listing/GetApplication.test.tsx index 098e9657df..387b0ab8eb 100644 --- a/sites/public/__tests__/components/listing/GetApplication.test.tsx +++ b/sites/public/__tests__/components/listing/GetApplication.test.tsx @@ -26,6 +26,7 @@ describe("", () => { zipCode: "90210", }} preview={false} + listingStatus="active" listingName={"Listing name"} /> ) @@ -56,12 +57,13 @@ describe("", () => { zipCode: "90210", }} preview={false} + listingStatus="active" listingName={"Listing name"} /> ) expect(queryByTestId("get-application-section")).toBeNull() }) - it("disables apply online button in preview state", () => { + it("disables apply online button if draft listing and not in preview state", () => { const { getByText } = render( ", () => { street: "Pick Up Address Street", zipCode: "90210", }} - preview={true} + preview={false} + listingStatus="pending" listingName={"Listing name"} /> ) expect(getByText("Apply Online").closest("button")?.disabled).toBe(true) }) + it("enables apply online button if draft listing and in preview state", () => { + const { getByText } = render( + + ) + expect(getByText("Apply Online").closest("a")?.getAttribute("href")).toBe("online-app-url") + }) it("hides buttons if application is not open", () => { const { getByText, queryByText } = render( ", () => { zipCode: "90210", }} preview={false} + listingStatus="active" listingName={"Listing name"} /> ) diff --git a/sites/public/src/components/listing/GetApplication.tsx b/sites/public/src/components/listing/GetApplication.tsx index 92099c9d35..90ca1171ba 100644 --- a/sites/public/src/components/listing/GetApplication.tsx +++ b/sites/public/src/components/listing/GetApplication.tsx @@ -16,6 +16,7 @@ import { FieldGroup, } from "@bloom-housing/ui-components" import { downloadExternalPDF } from "../../lib/helpers" +import { ListingStatus } from "@bloom-housing/backend-core" export interface PaperApplication { fileURL: string @@ -41,7 +42,9 @@ export interface ApplicationsProps { paperMethod?: boolean /** The date mailed applications must be received by */ postmarkedApplicationsReceivedByDate?: string - /** Whether or not to hide actionable application buttons */ + /** Informs whether or not to hide actionable application buttons */ + listingStatus?: string + /** Whether or not to block submission of test application */ preview?: boolean strings?: { applicationsOpenInFuture?: string @@ -59,8 +62,8 @@ const GetApplication = (props: ApplicationsProps) => { const showSection = props.onlineApplicationURL || (props.applicationsOpen && props.paperMethod && !!props.paperApplications?.length) + const disableApplyButton = !props.preview && props.listingStatus !== ListingStatus.active const [showDownloadModal, setShowDownloadModal] = useState(false) - // eslint-disable-next-line @typescript-eslint/unbound-method const { register, watch } = useForm() const paperApplicationURL: string = watch( @@ -86,7 +89,7 @@ const GetApplication = (props: ApplicationsProps) => { )} {props.applicationsOpen && props.onlineApplicationURL && ( <> - {props.preview ? ( + {disableApplyButton ? ( diff --git a/sites/public/src/components/listing/ListingView.tsx b/sites/public/src/components/listing/ListingView.tsx index 973352acad..5f7fac4a41 100644 --- a/sites/public/src/components/listing/ListingView.tsx +++ b/sites/public/src/components/listing/ListingView.tsx @@ -320,6 +320,7 @@ export const ListingView = (props: ListingProps) => { let onlineApplicationURL if (hasMethod(listing.applicationMethods, ApplicationMethodType.Internal)) { onlineApplicationURL = `/applications/start/choose-language?listingId=${listing.id}` + onlineApplicationURL += `${props.preview ? "&preview=true" : ""}` } else if (hasMethod(listing.applicationMethods, ApplicationMethodType.ExternalLink)) { onlineApplicationURL = getMethod(listing.applicationMethods, ApplicationMethodType.ExternalLink) @@ -381,6 +382,7 @@ export const ListingView = (props: ListingProps) => { applicationPickUpAddress={getAddress(listing.applicationPickUpAddressType, "pickUp")} preview={props.preview} listingName={listing.name} + listingStatus={listing.status} /> {!( listing.status === ListingStatus.closed || diff --git a/sites/public/src/pages/applications/review/summary.tsx b/sites/public/src/pages/applications/review/summary.tsx index 57d62169fe..b300b6486c 100644 --- a/sites/public/src/pages/applications/review/summary.tsx +++ b/sites/public/src/pages/applications/review/summary.tsx @@ -26,7 +26,11 @@ import { listingSectionQuestions, } from "@bloom-housing/shared-helpers" import { UserStatus } from "../../../lib/constants" -import { ApplicationReviewStatus, ApplicationSection } from "@bloom-housing/backend-core" +import { + ApplicationReviewStatus, + ApplicationSection, + ListingStatus, +} from "@bloom-housing/backend-core" import { useRouter } from "next/router" const ApplicationSummary = () => { @@ -51,9 +55,11 @@ const ApplicationSummary = () => { }, [profile]) useEffect(() => { - if (listing?.status === "closed") { - setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert") - void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`) + if (listing && router.isReady) { + if (listing?.status !== ListingStatus.active) { + setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert") + void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`) + } } }, [listing, router]) diff --git a/sites/public/src/pages/applications/start/choose-language.tsx b/sites/public/src/pages/applications/start/choose-language.tsx index 776cdc20c2..ea9f341a4c 100644 --- a/sites/public/src/pages/applications/start/choose-language.tsx +++ b/sites/public/src/pages/applications/start/choose-language.tsx @@ -24,14 +24,13 @@ import { pushGtmEvent, AuthContext, } from "@bloom-housing/shared-helpers" - import FormsLayout from "../../../layouts/forms" import { AppSubmissionContext, retrieveApplicationConfig, } from "../../../lib/applications/AppSubmissionContext" import React, { useCallback, useContext, useEffect, useState } from "react" -import { Language } from "@bloom-housing/backend-core/types" +import { Language, ListingStatus } from "@bloom-housing/backend-core/types" import { useGetApplicationStatusProps } from "../../../lib/hooks" import { UserStatus } from "../../../lib/constants" @@ -82,9 +81,11 @@ const ApplicationChooseLanguage = () => { }, [router, conductor, context, listingId]) useEffect(() => { - if (listing?.status === "closed") { - setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert") - void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`) + if (listing && router.isReady) { + if (listing?.status !== ListingStatus.active && router.query.preview !== "true") { + setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert") + void router.push(`/${router.locale}/listing/${listing?.id}/${listing?.urlSlug}`) + } } }, [listing, router]) diff --git a/sites/public/src/pages/preview/listings/[id].tsx b/sites/public/src/pages/preview/listings/[id].tsx index be0fd0e39f..f93674ec5b 100644 --- a/sites/public/src/pages/preview/listings/[id].tsx +++ b/sites/public/src/pages/preview/listings/[id].tsx @@ -39,7 +39,7 @@ export default function ListingPage(props: ListingProps) { > {t("listings.listingPreviewOnly")} - + ) }