Skip to content

Commit

Permalink
fix: updated application checks (#656)
Browse files Browse the repository at this point in the history
* fix: updated application checks

* fix: remove button differences
  • Loading branch information
ColinBuyck authored Jan 4, 2024
1 parent 64b34d4 commit 70afb70
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
35 changes: 33 additions & 2 deletions sites/public/__tests__/components/listing/GetApplication.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("<Applications>", () => {
zipCode: "90210",
}}
preview={false}
listingStatus="active"
listingName={"Listing name"}
/>
)
Expand Down Expand Up @@ -56,12 +57,13 @@ describe("<Applications>", () => {
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(
<GetApplication
onlineApplicationURL={"online-app-url"}
Expand All @@ -81,12 +83,40 @@ describe("<Applications>", () => {
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(
<GetApplication
onlineApplicationURL={"online-app-url"}
applicationsOpen={true}
applicationsOpenDate={"November 20th, 2021"}
paperApplications={[
{ fileURL: "file-url-en", languageString: "English" },
{ fileURL: "file-url-es", languageString: "Spanish" },
]}
paperMethod={true}
postmarkedApplicationsReceivedByDate={"November 30th, 2021"}
applicationPickUpAddressOfficeHours={"M-F 9am-5pm"}
applicationPickUpAddress={{
city: "City",
state: "State",
street2: "Street 2",
street: "Pick Up Address Street",
zipCode: "90210",
}}
preview={true}
listingStatus="pending"
listingName={"Listing name"}
/>
)
expect(getByText("Apply Online").closest("a")?.getAttribute("href")).toBe("online-app-url")
})
it("hides buttons if application is not open", () => {
const { getByText, queryByText } = render(
<GetApplication
Expand All @@ -108,6 +138,7 @@ describe("<Applications>", () => {
zipCode: "90210",
}}
preview={false}
listingStatus="active"
listingName={"Listing name"}
/>
)
Expand Down
9 changes: 6 additions & 3 deletions sites/public/src/components/listing/GetApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -86,7 +89,7 @@ const GetApplication = (props: ApplicationsProps) => {
)}
{props.applicationsOpen && props.onlineApplicationURL && (
<>
{props.preview ? (
{disableApplyButton ? (
<Button disabled className="w-full mb-2" data-testid={"listing-view-apply-button"}>
{props.strings?.applyOnline ?? t("listings.apply.applyOnline")}
</Button>
Expand Down
2 changes: 2 additions & 0 deletions sites/public/src/components/listing/ListingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ||
Expand Down
14 changes: 10 additions & 4 deletions sites/public/src/pages/applications/review/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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])

Expand Down
11 changes: 6 additions & 5 deletions sites/public/src/pages/applications/start/choose-language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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])

Expand Down
2 changes: 1 addition & 1 deletion sites/public/src/pages/preview/listings/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ListingPage(props: ListingProps) {
>
{t("listings.listingPreviewOnly")}
</AlertBox>
<ListingView listing={listing} preview={false} jurisdiction={props.jurisdiction} />
<ListingView listing={listing} preview={true} jurisdiction={props.jurisdiction} />
</Layout>
)
}
Expand Down

0 comments on commit 70afb70

Please sign in to comment.