Skip to content

Commit

Permalink
new backend field
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski committed Jul 1, 2021
1 parent 30265b0 commit 3815f29
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 16 deletions.
2 changes: 2 additions & 0 deletions backend/core/archer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ export const ArcherListing: Listing = {
waitlistMaxSize: 300,
name: "Archer Studios",
waitlistCurrentSize: 300,
waitlistOpenSpots: 0,
isWaitlistOpen: true,
// Addng displayWaitListSize for #707
displayWaitlistSize: false,
// TODO confirm not used anywhere
Expand Down
18 changes: 18 additions & 0 deletions backend/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,12 @@ export interface Listing {
/** */
requiredDocuments: string

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number

Expand Down Expand Up @@ -1959,6 +1965,12 @@ export interface ListingCreate {
/** */
requiredDocuments: string

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number

Expand Down Expand Up @@ -2151,6 +2163,12 @@ export interface ListingUpdate {
/** */
requiredDocuments: string

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number

Expand Down
12 changes: 12 additions & 0 deletions backend/core/src/listings/entities/listing.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,24 @@ class Listing extends BaseEntity {
@IsString({ groups: [ValidationsGroupsEnum.default] })
specialNotes?: string | null

@Column({ type: "boolean", nullable: true })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
isWaitlistOpen: boolean | null

@Column({ type: "integer", nullable: true })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsNumber({}, { groups: [ValidationsGroupsEnum.default] })
waitlistCurrentSize: number | null

@Column({ type: "integer", nullable: true })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
@IsNumber({}, { groups: [ValidationsGroupsEnum.default] })
waitlistOpenSpots: number | null

@Column({ type: "integer", nullable: true })
@Expose()
@IsOptional({ groups: [ValidationsGroupsEnum.default] })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class waitlistopenAndWaitlistopenspots1625108405070 implements MigrationInterface {
name = "waitlistopenAndWaitlistopenspots1625108405070"

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "listings" ADD "is_waitlist_open" boolean`)
await queryRunner.query(`ALTER TABLE "listings" ADD "waitlist_open_spots" integer`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "listings" DROP COLUMN "waitlist_open_spots"`)
await queryRunner.query(`ALTER TABLE "listings" DROP COLUMN "is_waitlist_open"`)
}
}
6 changes: 6 additions & 0 deletions backend/core/src/seeds/listings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,8 @@ const defaultListing: ListingSeedType = {
specialNotes: "Custom special notes text",
status: ListingStatus.active,
waitlistCurrentSize: null,
waitlistOpenSpots: null,
isWaitlistOpen: false,
waitlistMaxSize: null,
whatToExpect: {
allInfoWillBeVerified: "Custom all info will be verified text",
Expand Down Expand Up @@ -2543,6 +2545,8 @@ const tritonListing: ListingSeedType = {
status: ListingStatus.active,
waitlistCurrentSize: 400,
waitlistMaxSize: 600,
waitlistOpenSpots: 200,
isWaitlistOpen: true,
whatToExpect: null,
}

Expand Down Expand Up @@ -2609,6 +2613,8 @@ const coliseumListing: ListingSeedType = {
status: ListingStatus.active,
waitlistCurrentSize: 0,
waitlistMaxSize: 3000,
waitlistOpenSpots: 3000,
isWaitlistOpen: true,
whatToExpect: null,
}

Expand Down
18 changes: 18 additions & 0 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,12 @@ export interface Listing {
/** */
specialNotes?: string;

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number;

Expand Down Expand Up @@ -3517,6 +3523,12 @@ export interface ListingCreate {
/** */
specialNotes?: string;

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number;

Expand Down Expand Up @@ -3790,6 +3802,12 @@ export interface ListingUpdate {
/** */
specialNotes?: string;

/** */
isWaitlistOpen: boolean

/** */
waitlistOpenSpots: number

/** */
waitlistCurrentSize: number;

Expand Down
11 changes: 8 additions & 3 deletions sites/partners/src/listings/PaperListingForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import LeasingAgent from "./sections/LeasingAgent"
import AdditionalFees from "./sections/AdditionalFees"
import RankingsAndResults from "./sections/RankingsAndResults"

type FormListing = ListingCreate & ListingUpdate
export type FormListing = ListingCreate &
ListingUpdate & {
waitlistSizeQuestion?: boolean
}

type ListingFormProps = {
listing?: FormListing
Expand Down Expand Up @@ -79,8 +82,10 @@ const defaults: FormListing = {
rentalHistory: "",
requiredDocuments: "",
status: ListingStatus.pending,
waitlistCurrentSize: 0,
waitlistMaxSize: 0,
waitlistCurrentSize: null,
waitlistMaxSize: null,
isWaitlistOpen: null,
waitlistOpenSpots: null,
whatToExpect: [],
units: [],
accessibility: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { useFormContext } from "react-hook-form"
import { t, GridSection, Field, FieldGroup, GridCell } from "@bloom-housing/ui-components"

import { YesNoAnswer } from "../../../applications/PaperApplicationForm/FormTypes"
import { FormListing } from "../index"

const RankingsAndResults = () => {
type RankingsAndResultsProps = {
listing?: FormListing
}

const RankingsAndResults = ({ listing }: RankingsAndResultsProps) => {
const formMethods = useFormContext()

// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch } = formMethods

const waitlistOpen: YesNoAnswer = watch("waitlistOpenQuestion")
const showWaitlistSize: YesNoAnswer = watch("waitlistSizeQuestion")
const waitlistOpen: YesNoAnswer = watch("waitlistOpenQuestion", listing?.isWaitlistOpen)
const showWaitlistSize: YesNoAnswer = watch("waitlistSizeQuestion", listing?.waitlistMaxSize)

const yesNoRadioOptions = [
{
Expand Down Expand Up @@ -40,8 +45,17 @@ const RankingsAndResults = () => {
type="radio"
register={register}
fields={[
{ ...yesNoRadioOptions[0], id: "waitlistOpenYes" },
{ ...yesNoRadioOptions[1], id: "waitlistOpenNo" },
{
...yesNoRadioOptions[0],
id: "waitlistOpenYes",
defaultChecked: listing && listing.isWaitlistOpen,
},

{
...yesNoRadioOptions[1],
id: "waitlistOpenNo",
defaultChecked: listing && !listing.isWaitlistOpen,
},
]}
/>
</GridSection>
Expand All @@ -55,33 +69,41 @@ const RankingsAndResults = () => {
type="radio"
register={register}
fields={[
{ ...yesNoRadioOptions[0], id: "showWaitlistSizeYes" },
{ ...yesNoRadioOptions[1], id: "showWaitlistSizeNo" },
{
...yesNoRadioOptions[0],
id: "showWaitlistSizeYes",
defaultChecked: listing && listing.waitlistMaxSize !== null,
},
{
...yesNoRadioOptions[1],
id: "showWaitlistSizeNo",
defaultChecked: listing && !listing.waitlistMaxSize,
},
]}
/>
</GridSection>
)}
{showWaitlistSize === YesNoAnswer.Yes && (
<GridSection columns={3} className={"flex items-center"}>
<Field
name="maxWaitlistSize"
id="maxWaitlistSize"
name="waitlistMaxSize"
id="waitlistMaxSize"
register={register}
label={t("listings.waitlist.maxSizeQuestion")}
placeholder={t("listings.waitlist.maxSize")}
type={"number"}
/>
<Field
name="currentWaitlistSize"
id="currentWaitlistSize"
name="waitlistCurrentSize"
id="waitlistCurrentSize"
register={register}
label={t("listings.waitlist.currentSizeQuestion")}
placeholder={t("listings.waitlist.currentSize")}
type={"number"}
/>
<Field
name="openWaitlistSize"
id="openWaitlistSize"
name="waitlistOpenSpots"
id="waitlistOpenSpots"
register={register}
label={t("listings.waitlist.openSizeQuestion")}
placeholder={t("listings.waitlist.openSize")}
Expand Down

0 comments on commit 3815f29

Please sign in to comment.