Skip to content

Commit 852e2f5

Browse files
committed
fix: apply button
1 parent d83491c commit 852e2f5

4 files changed

Lines changed: 95 additions & 12 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
section.app-container.focus-container
2+
.row.collapse
3+
.medium-6.medium-centered.columns.fixed-width
4+
short-form-nav
5+
.app-card.form-card
6+
short-form-header
7+
h2.app-card_question
8+
| {{ 'c9_plus_housing_program.title' | translate }}
9+
p.form-note.margin-bottom.text-center translate="c9_plus_housing_program.subtitle" translate-value-plus-housing-program-url="https://www.sf.gov/reports--february-2024--plus-housing-waitlist/"
10+
11+
.app-inner.inset
12+
.form-group
13+
p.form-note.margin-bottom translate="label.please_select_one"
14+
.radio-group.padding-top--half role="radiogroup" aria-label="{{ 'c9_plus_housing_program.title' | translate }}"
15+
16+
radio-block-item value='Yes' user='application' name='plusHousingProgramParticipantAnswer' ng-required='true' on-change='customEducatorCheckScreening' ng-class="{ error: inputInvalid('customEducatorScreeningAnswer') }"
17+
| {{ 't.yes' | translate }}
18+
div.form-group.margin-left--2x ng-if="plusHousingProgramParticipant()" ng-class="{ error: inputInvalidOnTouched('customEducatorJobClassificationNumber') }"
19+
// Plus Housing Program Number text field
20+
label.form-label for="plusHousingProgramNumber"
21+
| {{ 'c9_plus_housing_program.enter_your_plus_housing_program_number' | translate }}
22+
p.form-note.margin-bottom--half translate="c9_plus_housing_program.look_for_your_program_number"
23+
input(
24+
ng-model="application.plusHousingProgramNumber"
25+
ng-required="true"
26+
name="plusHousingProgramNumber"
27+
/ placeholder="{{'' | translate}}"
28+
type="text"
29+
autocomplete="off"
30+
style="margin-bottom:0;"
31+
/ ui-validate="'customEducatorBrightwellValidJobClassificationNumber($value)'"
32+
/ aria-describedby="employee_id_error_1 employee_id_error_2"
33+
)
34+
/ small#employee_id_error_1.error.margin-bottom ng-if="inputInvalidOnTouched('customEducatorJobClassificationNumber')"
35+
/ | {{ 'a3a_custom_educator_brightwell_screening.we_could_not_find_that_employee_id' | translate }}
36+
/ small#employee_id_error_2.error.margin-bottom ng-if="inputInvalidOnTouched('customEducatorJobClassificationNumber')"
37+
/ | {{ 'a3a_custom_educator_brightwell_screening.still_not_working' | translate }}
38+
/ ul.bullet-list
39+
/ li.margin-bottom-none
40+
/ | SFUSD: housing@sfusd.edu
41+
/ li.margin-bottom-none
42+
/ | City College: ccsfhousing@ccsf.edu
43+
44+
radio-block-item value='No' user='application' name='customEducatorScreeningAnswer' ng-required='true' on-change='customEducatorCheckScreening' ng-class="{ error: inputInvalid('customEducatorScreeningAnswer') }"
45+
| {{ 't.no' | translate }}
46+
47+
.button-pager
48+
.button-pager_row.primary.text-center
49+
input#submit.button.primary.radius type="submit" value="{{'t.next' | translate}}" ng-disabled="inputInvalid('customEducatorScreeningAnswer') || eligibilityErrors.length > 0"

app/javascript/__tests__/modules/listingDetailsAside/ListingDetailsApply.test.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from "react"
22
import { render, screen } from "@testing-library/react"
33
import { MemoryRouter } from "react-router"
4+
import { useAuth } from "@clerk/clerk-react"
45
import { ListingDetailsApply } from "../../../modules/listingDetailsAside/ListingDetailsApply"
56
import { openSaleListing } from "../../data/RailsSaleListing/listing-sale-open"
67
import { closedRentalListing } from "../../data/RailsRentalListing/listing-rental-closed"
78
import { habitatListing } from "../../data/RailsSaleListing/listing-sale-habitat"
89
import { setupUserContext } from "../../__util__/accountUtils"
9-
import { getAddProfilePath } from "../../../util/routeUtil"
10+
import { getAddProfilePath, getSignInPath } from "../../../util/routeUtil"
1011
import { useFeatureFlag } from "../../../hooks/useFeatureFlag"
1112
import { UNLEASH_FLAG } from "../../../modules/constants"
1213

@@ -68,6 +69,17 @@ describe("ListingDetailsApply", () => {
6869
}))
6970
})
7071

72+
it("redirects signed out users to sign in", () => {
73+
setupUserContext({ loggedIn: false })
74+
75+
render(<ListingDetailsApply listing={openSaleListing} />)
76+
77+
expect(screen.getByRole("link", { name: /apply online/i })).toHaveAttribute(
78+
"href",
79+
getSignInPath()
80+
)
81+
})
82+
7183
it("redirects signed in users without a completed profile to the add profile page", () => {
7284
setupUserContext({ loggedIn: true, hasProfile: false })
7385

@@ -78,5 +90,31 @@ describe("ListingDetailsApply", () => {
7890
getAddProfilePath()
7991
)
8092
})
93+
94+
it("uses the listing application link for signed in users with a profile", () => {
95+
setupUserContext({ loggedIn: true, hasProfile: true })
96+
;(useAuth as jest.Mock).mockReturnValue({
97+
isLoaded: true,
98+
isSignedIn: true,
99+
})
100+
101+
render(<ListingDetailsApply listing={openSaleListing} />)
102+
103+
expect(screen.getByRole("link", { name: /apply online/i }).getAttribute("href")).toBe(
104+
`/listings/${openSaleListing.listingID}/apply-welcome/intro`
105+
)
106+
})
107+
108+
it("does not render apply online while Clerk auth is loading", () => {
109+
setupUserContext({ loggedIn: false })
110+
;(useAuth as jest.Mock).mockReturnValue({
111+
isLoaded: false,
112+
isSignedIn: false,
113+
})
114+
115+
render(<ListingDetailsApply listing={openSaleListing} />)
116+
117+
expect(screen.queryByRole("link", { name: /apply online/i })).toBeNull()
118+
})
81119
})
82120
})

app/javascript/__tests__/pages/SignInFlow.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import {
1010
restoreWindowLocation,
1111
} from "../__util__/renderUtils"
1212
import { setupUserContext } from "../__util__/accountUtils"
13-
import { AUTH_FLOW } from "../../modules/constants"
13+
import { AUTH_FLOW, UNLEASH_FLAG } from "../../modules/constants"
1414
import { authorizeHousingCounselor, getProfile } from "../../api/authApiService"
1515
import { useFeatureFlag } from "../../hooks/useFeatureFlag"
16-
import { UNLEASH_FLAG } from "../../modules/constants"
1716

1817
jest.mock("../../hooks/useFeatureFlag", () => ({
1918
useFeatureFlag: jest.fn(() => ({

app/javascript/modules/listingDetailsAside/ListingDetailsApply.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@ const ApplyButton = ({ href }: { href: string }) => (
8181
const ClerkApplyOnlineButton = ({ applyLink }: { applyLink: string }) => {
8282
const { isLoaded, isSignedIn } = useAuth()
8383
const { profile, initialStateLoaded } = useContext(UserContext)
84-
let redirectOrApplyUrl = ""
85-
if (isLoaded && isSignedIn && initialStateLoaded && profile) {
86-
redirectOrApplyUrl = applyLink
87-
} else if (isLoaded && !isSignedIn) {
88-
redirectOrApplyUrl = getSignInPath()
89-
} else if (isLoaded && isSignedIn && initialStateLoaded && !profile) {
90-
redirectOrApplyUrl = getAddProfilePath()
91-
}
9284

93-
return <ApplyButton href={redirectOrApplyUrl} />
85+
if (!isLoaded) return null
86+
if (!isSignedIn) return <ApplyButton href={getSignInPath()} />
87+
if (!initialStateLoaded) return null
88+
if (!profile) return <ApplyButton href={getAddProfilePath()} />
89+
90+
return <ApplyButton href={applyLink} />
9491
}
9592

9693
/**

0 commit comments

Comments
 (0)