From adab010ae2af01481701b05c6ee2da3a26fe8f81 Mon Sep 17 00:00:00 2001 From: Emily Jablonski <65367387+emilyjablonski@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:42:32 -0600 Subject: [PATCH] fix: improve seed data and validity (#4099) --- api/prisma/constants.ts | 2 +- api/prisma/seed-dev.ts | 22 +++---- .../seed-helpers/alternate-contact-factory.ts | 43 ++++++++++++++ .../seed-helpers/application-factory.ts | 13 ++++- .../seed-helpers/household-member-factory.ts | 57 ++++++++++--------- .../seed-helpers/jurisdiction-factory.ts | 2 +- .../applications/alternate-contact.dto.ts | 14 +++-- .../dtos/applications/household-member.dto.ts | 13 +++-- .../alternate-contact-relationship-enum.ts | 7 +++ .../household-member-relationship-enum.ts | 17 ++++++ api/test/integration/application.e2e-spec.ts | 26 +++++---- .../integration/permission-tests/helpers.ts | 10 ++-- shared-helpers/src/types/backend-swagger.ts | 34 +++++++++-- shared-helpers/src/utilities/formKeys.ts | 29 +--------- .../applications/ApplicationsColDefs.ts | 6 +- .../sections/DetailsAlternateContact.tsx | 23 +++++--- .../PaperApplicationForm/FormMember.tsx | 3 +- .../lib/applications/formatApplicationData.ts | 8 ++- .../pages/applications/household/member.tsx | 3 +- 19 files changed, 223 insertions(+), 109 deletions(-) create mode 100644 api/prisma/seed-helpers/alternate-contact-factory.ts create mode 100644 api/src/enums/applications/alternate-contact-relationship-enum.ts create mode 100644 api/src/enums/applications/household-member-relationship-enum.ts diff --git a/api/prisma/constants.ts b/api/prisma/constants.ts index 6359552f55..cc9f0a8705 100644 --- a/api/prisma/constants.ts +++ b/api/prisma/constants.ts @@ -1,2 +1,2 @@ export const LISTINGS_TO_SEED = 10; -export const APPLICATIONS_PER_LISTINGS = 5; +export const APPLICATIONS_PER_LISTINGS = 10; diff --git a/api/prisma/seed-dev.ts b/api/prisma/seed-dev.ts index 41a4620357..17846d5d4e 100644 --- a/api/prisma/seed-dev.ts +++ b/api/prisma/seed-dev.ts @@ -85,21 +85,21 @@ export const devSeeding = async ( await reservedCommunityTypeFactoryAll(jurisdiction.id, prismaClient); - const householdSize = randomInt(0, 6); for (let index = 0; index < LISTINGS_TO_SEED; index++) { - const householdMembers = await householdMemberFactoryMany(householdSize); - const applications = []; - for (let j = 0; j <= APPLICATIONS_PER_LISTINGS; j++) { - applications.push( - await applicationFactory({ - householdSize, - unitTypeId: unitTypes[randomInt(0, 5)].id, - householdMember: householdMembers, - multiselectQuestions, - }), + for (let j = 0; j < APPLICATIONS_PER_LISTINGS; j++) { + const householdSize = randomInt(1, 6); + const householdMembers = await householdMemberFactoryMany( + householdSize - 1, ); + const app = await applicationFactory({ + householdSize, + unitTypeId: unitTypes[randomInt(0, 5)].id, + householdMember: householdMembers, + multiselectQuestions, + }); + applications.push(app); } const listing = await listingFactory(jurisdiction.id, prismaClient, { diff --git a/api/prisma/seed-helpers/alternate-contact-factory.ts b/api/prisma/seed-helpers/alternate-contact-factory.ts new file mode 100644 index 0000000000..d613b86754 --- /dev/null +++ b/api/prisma/seed-helpers/alternate-contact-factory.ts @@ -0,0 +1,43 @@ +import { Prisma } from '@prisma/client'; +import { randomInt } from 'crypto'; +import { randomAdjective, randomNoun } from './word-generator'; +import { AlternateContactRelationship } from '../../src/enums/applications/alternate-contact-relationship-enum'; +import { addressFactory } from './address-factory'; + +export const alternateContactFactory = + (): Prisma.AlternateContactCreateWithoutApplicationsInput => { + const relationshipKeys = Object.values(AlternateContactRelationship); + const firstName = randomNoun(); + const lastName = randomNoun(); + const relationshipType = + relationshipKeys[randomInt(relationshipKeys.length)]; + + if (relationshipType === AlternateContactRelationship.noContact) { + return { + firstName: undefined, + lastName: undefined, + type: relationshipType, + otherType: undefined, + phoneNumber: undefined, + emailAddress: undefined, + agency: undefined, + address: { create: addressFactory() }, + }; + } + return { + firstName: firstName, + lastName: lastName, + type: relationshipType, + otherType: + relationshipType === AlternateContactRelationship.other + ? randomAdjective() + : undefined, + phoneNumber: '(123) 123-1231', + emailAddress: `${firstName}.${lastName}@example.com`, + address: { create: addressFactory() }, + agency: + relationshipType === AlternateContactRelationship.caseManager + ? randomAdjective() + : undefined, + }; + }; diff --git a/api/prisma/seed-helpers/application-factory.ts b/api/prisma/seed-helpers/application-factory.ts index 916ac8437a..cabb74a2cd 100644 --- a/api/prisma/seed-helpers/application-factory.ts +++ b/api/prisma/seed-helpers/application-factory.ts @@ -17,6 +17,8 @@ import { } from './number-generator'; import { preferenceFactory } from './application-preference-factory'; import { demographicsFactory } from './demographic-factory'; +import { alternateContactFactory } from './alternate-contact-factory'; +import { randomBoolean } from './boolean-generator'; export const applicationFactory = async (optionalParams?: { householdSize?: number; @@ -41,6 +43,7 @@ export const applicationFactory = async (optionalParams?: { }; } const demographics = await demographicsFactory(); + const additionalPhone = randomBoolean(); return { confirmationCode: generateConfirmationCode(), applicant: { create: applicantFactory(optionalParams?.applicant) }, @@ -52,7 +55,9 @@ export const applicationFactory = async (optionalParams?: { submissionDate: new Date(), householdSize: optionalParams?.householdSize ?? 1, income: '40000', - incomePeriod: IncomePeriodEnum.perYear, + incomePeriod: randomBoolean() + ? IncomePeriodEnum.perYear + : IncomePeriodEnum.perMonth, preferences: preferenceFactory( optionalParams?.multiselectQuestions ? optionalParams.multiselectQuestions.filter( @@ -92,6 +97,7 @@ export const applicationFactory = async (optionalParams?: { demographics: { create: demographics, }, + alternateContact: { create: alternateContactFactory() }, userAccounts: optionalParams?.userId ? { connect: { @@ -99,6 +105,10 @@ export const applicationFactory = async (optionalParams?: { }, } : undefined, + incomeVouchers: randomBoolean(), + additionalPhoneNumber: additionalPhone ? '(456) 456-4564' : undefined, + additionalPhone, + additionalPhoneNumberType: additionalPhone ? 'cell' : undefined, }; }; @@ -109,6 +119,7 @@ export const applicantFactory = ( const lastName = randomNoun(); return { firstName: firstName, + middleName: randomBoolean() ? randomNoun() : undefined, lastName: lastName, emailAddress: `${firstName}.${lastName}@example.com`, noEmail: false, diff --git a/api/prisma/seed-helpers/household-member-factory.ts b/api/prisma/seed-helpers/household-member-factory.ts index 4f0dd570eb..82de1eb4e1 100644 --- a/api/prisma/seed-helpers/household-member-factory.ts +++ b/api/prisma/seed-helpers/household-member-factory.ts @@ -1,6 +1,8 @@ import { Prisma, YesNoEnum } from '@prisma/client'; +import { randomInt } from 'crypto'; +import { HouseholdMemberRelationship } from '../../src/enums/applications/household-member-relationship-enum'; import { addressFactory } from './address-factory'; -import { randomAdjective, randomNoun } from './word-generator'; +import { randomNoun } from './word-generator'; import { randomBirthDay, randomBirthMonth, @@ -8,38 +10,39 @@ import { } from './number-generator'; import { randomBoolean } from './boolean-generator'; -export const householdMemberFactorySingle = - (): Prisma.HouseholdMemberCreateWithoutApplicationsInput => { - const firstName = randomNoun(); - const lastName = randomNoun(); - const randomYesNo = randomBoolean() === true ? YesNoEnum.yes : YesNoEnum.no; - return { - firstName: firstName, - middleName: randomNoun(), - lastName: lastName, - // Question: why are these strings? - birthMonth: randomBirthMonth(), - birthDay: randomBirthDay(), - birthYear: randomBirthYear(), - sameAddress: randomYesNo, - // Question: should this be an enum? - relationship: randomAdjective(), - workInRegion: randomYesNo, - householdMemberAddress: randomBoolean - ? undefined - : { create: addressFactory() }, - householdMemberWorkAddress: { - create: addressFactory(), - }, - }; +export const householdMemberFactorySingle = ( + index: number, +): Prisma.HouseholdMemberCreateWithoutApplicationsInput => { + const firstName = randomNoun(); + const lastName = randomNoun(); + + const relationshipKeys = Object.values(HouseholdMemberRelationship); + + return { + firstName: firstName, + middleName: randomNoun(), + lastName: lastName, + // Question: why are these strings? + birthMonth: randomBirthMonth(), + birthDay: randomBirthDay(), + birthYear: randomBirthYear(), + sameAddress: YesNoEnum.yes, + relationship: relationshipKeys[randomInt(relationshipKeys.length)], + workInRegion: YesNoEnum.yes, + householdMemberAddress: { create: addressFactory() }, + householdMemberWorkAddress: { + create: addressFactory(), + }, + orderId: index, }; +}; export const householdMemberFactoryMany = async ( numberToMake: number, ): Promise => { const createArray: Promise[] = - [...new Array(numberToMake)].map(async () => - householdMemberFactorySingle(), + [...new Array(numberToMake)].map(async (index) => + householdMemberFactorySingle(index), ); return await Promise.all(createArray); }; diff --git a/api/prisma/seed-helpers/jurisdiction-factory.ts b/api/prisma/seed-helpers/jurisdiction-factory.ts index 48cac53f2d..d155284d00 100644 --- a/api/prisma/seed-helpers/jurisdiction-factory.ts +++ b/api/prisma/seed-helpers/jurisdiction-factory.ts @@ -6,7 +6,7 @@ export const jurisdictionFactory = ( listingApprovalPermissions?: UserRoleEnum[], ): Prisma.JurisdictionsCreateInput => ({ name: jurisdictionName, - notificationsSignUpUrl: null, + notificationsSignUpUrl: 'https://www.exygy.com', languages: [LanguagesEnum.en], partnerTerms: 'Example Terms', publicUrl: 'http://localhost:3000', diff --git a/api/src/dtos/applications/alternate-contact.dto.ts b/api/src/dtos/applications/alternate-contact.dto.ts index fea3a86314..4ed8c70820 100644 --- a/api/src/dtos/applications/alternate-contact.dto.ts +++ b/api/src/dtos/applications/alternate-contact.dto.ts @@ -2,6 +2,7 @@ import { Expose, Type } from 'class-transformer'; import { IsDefined, IsEmail, + IsEnum, IsString, MaxLength, ValidateNested, @@ -11,14 +12,19 @@ import { ValidationsGroupsEnum } from '../../enums/shared/validation-groups-enum import { AbstractDTO } from '../shared/abstract.dto'; import { Address } from '../addresses/address.dto'; import { EnforceLowerCase } from '../../decorators/enforce-lower-case.decorator'; +import { AlternateContactRelationship } from '../../enums/applications/alternate-contact-relationship-enum'; export class AlternateContact extends AbstractDTO { @Expose() - @IsString({ groups: [ValidationsGroupsEnum.default] }) - @MaxLength(16, { groups: [ValidationsGroupsEnum.default] }) + @IsEnum(AlternateContactRelationship, { + groups: [ValidationsGroupsEnum.default], + }) + @ApiPropertyOptional({ + enum: AlternateContactRelationship, + enumName: 'AlternateContactRelationship', + }) @IsDefined({ groups: [ValidationsGroupsEnum.applicants] }) - @ApiPropertyOptional() - type?: string; + type?: AlternateContactRelationship; @Expose() @IsString({ groups: [ValidationsGroupsEnum.default] }) diff --git a/api/src/dtos/applications/household-member.dto.ts b/api/src/dtos/applications/household-member.dto.ts index b723de0411..ee8b4623b8 100644 --- a/api/src/dtos/applications/household-member.dto.ts +++ b/api/src/dtos/applications/household-member.dto.ts @@ -10,6 +10,7 @@ import { import { YesNoEnum } from '@prisma/client'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ValidationsGroupsEnum } from '../../enums/shared/validation-groups-enum'; +import { HouseholdMemberRelationship } from '../../enums/applications/household-member-relationship-enum'; import { AbstractDTO } from '../shared/abstract.dto'; import { Address } from '../addresses/address.dto'; @@ -67,10 +68,14 @@ export class HouseholdMember extends AbstractDTO { sameAddress?: YesNoEnum; @Expose() - @IsString({ groups: [ValidationsGroupsEnum.default] }) - @MaxLength(64, { groups: [ValidationsGroupsEnum.default] }) - @ApiPropertyOptional() - relationship?: string; + @IsEnum(HouseholdMemberRelationship, { + groups: [ValidationsGroupsEnum.default], + }) + @ApiPropertyOptional({ + enum: HouseholdMemberRelationship, + enumName: 'HouseholdMemberRelationship', + }) + relationship?: HouseholdMemberRelationship; @Expose() @IsEnum(YesNoEnum, { groups: [ValidationsGroupsEnum.default] }) diff --git a/api/src/enums/applications/alternate-contact-relationship-enum.ts b/api/src/enums/applications/alternate-contact-relationship-enum.ts new file mode 100644 index 0000000000..917789eab4 --- /dev/null +++ b/api/src/enums/applications/alternate-contact-relationship-enum.ts @@ -0,0 +1,7 @@ +export enum AlternateContactRelationship { + familyMember = 'familyMember', + friend = 'friend', + caseManager = 'caseManager', + other = 'other', + noContact = 'noContact', +} diff --git a/api/src/enums/applications/household-member-relationship-enum.ts b/api/src/enums/applications/household-member-relationship-enum.ts new file mode 100644 index 0000000000..d6be659913 --- /dev/null +++ b/api/src/enums/applications/household-member-relationship-enum.ts @@ -0,0 +1,17 @@ +export enum HouseholdMemberRelationship { + spouse = 'spouse', + registeredDomesticPartner = 'registeredDomesticPartner', + parent = 'parent', + child = 'child', + sibling = 'sibling', + cousin = 'cousin', + aunt = 'aunt', + uncle = 'uncle', + nephew = 'nephew', + niece = 'niece', + grandparent = 'grandparent', + greatGrandparent = 'greatGrandparent', + inLaw = 'inLaw', + friend = 'friend', + other = 'other', +} diff --git a/api/test/integration/application.e2e-spec.ts b/api/test/integration/application.e2e-spec.ts index 09f9468da0..28eae40173 100644 --- a/api/test/integration/application.e2e-spec.ts +++ b/api/test/integration/application.e2e-spec.ts @@ -39,6 +39,8 @@ import { Login } from '../../src/dtos/auth/login.dto'; import { multiselectQuestionFactory } from '../../prisma/seed-helpers/multiselect-question-factory'; import { reservedCommunityTypeFactoryAll } from '../../prisma/seed-helpers/reserved-community-type-factory'; import { ValidationMethod } from '../../src/enums/multiselect-questions/validation-method-enum'; +import { AlternateContactRelationship } from '../../src/enums/applications/alternate-contact-relationship-enum'; +import { HouseholdMemberRelationship } from '../../src/enums/applications/household-member-relationship-enum'; describe('Application Controller Tests', () => { let app: INestApplication; @@ -411,7 +413,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -447,7 +449,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -590,7 +592,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -626,7 +628,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -760,7 +762,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -796,7 +798,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -937,7 +939,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -973,7 +975,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -1103,7 +1105,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -1139,7 +1141,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -1269,7 +1271,7 @@ describe('Application Controller Tests', () => { hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -1305,7 +1307,7 @@ describe('Application Controller Tests', () => { birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, diff --git a/api/test/integration/permission-tests/helpers.ts b/api/test/integration/permission-tests/helpers.ts index f567da2a35..742d380b55 100644 --- a/api/test/integration/permission-tests/helpers.ts +++ b/api/test/integration/permission-tests/helpers.ts @@ -48,6 +48,8 @@ import { UserCreate } from '../../../src/dtos/users/user-create.dto'; import { UserInvite } from '../../../src/dtos/users/user-invite.dto'; import { ListingPublishedCreate } from '../../../src/dtos/listings/listing-published-create.dto'; import { ListingPublishedUpdate } from '../../../src/dtos/listings/listing-published-update.dto'; +import { AlternateContactRelationship } from '../../../src/enums/applications/alternate-contact-relationship-enum'; +import { HouseholdMemberRelationship } from '../../../src/enums/applications/household-member-relationship-enum'; export const generateJurisdiction = async ( prisma: PrismaService, @@ -324,7 +326,7 @@ export const buildApplicationCreateMock = ( hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -360,7 +362,7 @@ export const buildApplicationCreateMock = ( birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, @@ -421,7 +423,7 @@ export const buildApplicationUpdateMock = ( hearing: false, }, alternateContact: { - type: 'example type', + type: AlternateContactRelationship.friend, otherType: 'example other type', firstName: 'example first name', lastName: 'example last name', @@ -457,7 +459,7 @@ export const buildApplicationUpdateMock = ( birthDay: '17', birthYear: '1993', sameAddress: YesNoEnum.yes, - relationship: 'example relationship', + relationship: HouseholdMemberRelationship.friend, workInRegion: YesNoEnum.yes, householdMemberWorkAddress: exampleAddress, householdMemberAddress: exampleAddress, diff --git a/shared-helpers/src/types/backend-swagger.ts b/shared-helpers/src/types/backend-swagger.ts index 6c0902fbc7..db69975761 100644 --- a/shared-helpers/src/types/backend-swagger.ts +++ b/shared-helpers/src/types/backend-swagger.ts @@ -3874,7 +3874,7 @@ export interface AlternateContact { updatedAt: Date /** */ - type?: string + type?: AlternateContactRelationship /** */ otherType?: string @@ -3933,7 +3933,7 @@ export interface HouseholdMember { sameAddress?: YesNoEnum /** */ - relationship?: string + relationship?: HouseholdMemberRelationship /** */ workInRegion?: YesNoEnum @@ -4625,7 +4625,7 @@ export interface ApplicantUpdate { export interface AlternateContactUpdate { /** */ - type?: string + type?: AlternateContactRelationship /** */ otherType?: string @@ -4703,7 +4703,7 @@ export interface HouseholdMemberUpdate { sameAddress?: YesNoEnum /** */ - relationship?: string + relationship?: HouseholdMemberRelationship /** */ workInRegion?: YesNoEnum @@ -5398,6 +5398,32 @@ export enum YesNoEnum { "yes" = "yes", "no" = "no", } + +export enum AlternateContactRelationship { + "familyMember" = "familyMember", + "friend" = "friend", + "caseManager" = "caseManager", + "other" = "other", + "noContact" = "noContact", +} + +export enum HouseholdMemberRelationship { + "spouse" = "spouse", + "registeredDomesticPartner" = "registeredDomesticPartner", + "parent" = "parent", + "child" = "child", + "sibling" = "sibling", + "cousin" = "cousin", + "aunt" = "aunt", + "uncle" = "uncle", + "nephew" = "nephew", + "niece" = "niece", + "grandparent" = "grandparent", + "greatGrandparent" = "greatGrandparent", + "inLaw" = "inLaw", + "friend" = "friend", + "other" = "other", +} export type AllExtraDataTypes = BooleanInput | TextInput | AddressInput export enum EnumJurisdictionCreateListingApprovalPermissions { "user" = "user", diff --git a/shared-helpers/src/utilities/formKeys.ts b/shared-helpers/src/utilities/formKeys.ts index b4f76b8dd1..cd1762ac0f 100644 --- a/shared-helpers/src/utilities/formKeys.ts +++ b/shared-helpers/src/utilities/formKeys.ts @@ -1,4 +1,4 @@ -import { LanguagesEnum } from "../types/backend-swagger" +import { HouseholdMemberRelationship, AlternateContactRelationship } from "../types/backend-swagger" export const stateKeys = [ "", @@ -72,32 +72,9 @@ export const contactPreferencesKeys = [ export const adaFeatureKeys = ["mobility", "vision", "hearing"] -export const relationshipKeys = [ - "", - "spouse", - "registeredDomesticPartner", - "parent", - "child", - "sibling", - "cousin", - "aunt", - "uncle", - "nephew", - "niece", - "grandparent", - "greatGrandparent", - "inLaw", - "friend", - "other", -] +export const relationshipKeys = ["", ...Object.values(HouseholdMemberRelationship)] -export const altContactRelationshipKeys = [ - "familyMember", - "friend", - "caseManager", - "other", - "noContact", -] +export const altContactRelationshipKeys = Object.values(AlternateContactRelationship) export const ethnicityKeys = ["hispanicLatino", "notHispanicLatino"] diff --git a/sites/partners/src/components/applications/ApplicationsColDefs.ts b/sites/partners/src/components/applications/ApplicationsColDefs.ts index 2454599df5..312787a308 100644 --- a/sites/partners/src/components/applications/ApplicationsColDefs.ts +++ b/sites/partners/src/components/applications/ApplicationsColDefs.ts @@ -489,7 +489,7 @@ export function getColDefs(maxHouseholdSize: number, countyCode: string) { const householdCols = [] - for (let i = 0; i < maxHouseholdSize; i++) { + for (let i = 0; i < maxHouseholdSize - 1; i++) { const householdIndex = i + 1 householdCols.push( @@ -558,7 +558,7 @@ export function getColDefs(maxHouseholdSize: number, countyCode: string) { width: 115, minWidth: 50, valueFormatter: ({ value }) => { - if (!value) return "" + if (value.length < householdIndex) return "" return formatYesNoLabel(value[i]?.sameAddress) }, }, @@ -570,7 +570,7 @@ export function getColDefs(maxHouseholdSize: number, countyCode: string) { width: 90, minWidth: 50, valueFormatter: ({ value }) => { - if (!value) return "" + if (value?.length < householdIndex) return "" return formatYesNoLabel(value[i]?.workInRegion) }, } diff --git a/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsAlternateContact.tsx b/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsAlternateContact.tsx index 4a243710db..fdad6b7a97 100644 --- a/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsAlternateContact.tsx +++ b/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsAlternateContact.tsx @@ -4,6 +4,7 @@ import { FieldValue, Grid } from "@bloom-housing/ui-seeds" import { ApplicationContext } from "../../ApplicationContext" import { DetailsAddressColumns, AddressColsType } from "../DetailsAddressColumns" import SectionWithGrid from "../../../shared/SectionWithGrid" +import { AlternateContactRelationship } from "@bloom-housing/shared-helpers/src/types/backend-swagger" const DetailsAlternateContact = () => { const application = useContext(ApplicationContext) @@ -44,14 +45,20 @@ const DetailsAlternateContact = () => { {application.alternateContact?.phoneNumber || t("t.n/a")} - {t("application.contact.address")} - - - + {application.alternateContact?.type !== AlternateContactRelationship.noContact && ( + <> + + {t("application.contact.address")} + + + + + + )} ) } diff --git a/sites/partners/src/components/applications/PaperApplicationForm/FormMember.tsx b/sites/partners/src/components/applications/PaperApplicationForm/FormMember.tsx index 5048d5acd5..78467ac5a7 100644 --- a/sites/partners/src/components/applications/PaperApplicationForm/FormMember.tsx +++ b/sites/partners/src/components/applications/PaperApplicationForm/FormMember.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from "react" import { HouseholdMember, + HouseholdMemberRelationship, HouseholdMemberUpdate, YesNoEnum, } from "@bloom-housing/shared-helpers/src/types/backend-swagger" @@ -59,7 +60,7 @@ export class Member implements HouseholdMemberUpdate { longitude: undefined, } sameAddress?: YesNoEnum - relationship?: string + relationship?: HouseholdMemberRelationship workInRegion?: YesNoEnum } diff --git a/sites/partners/src/lib/applications/formatApplicationData.ts b/sites/partners/src/lib/applications/formatApplicationData.ts index 71f6a9555d..4e1eadef31 100644 --- a/sites/partners/src/lib/applications/formatApplicationData.ts +++ b/sites/partners/src/lib/applications/formatApplicationData.ts @@ -174,7 +174,6 @@ export const mapFormToApi = ({ applicationsMailingAddress: mailingAddressData, additionalPhoneNumber, contactPreferences, - sendMailToMailingAddress, } = data.application const additionalPhone = !additionalPhoneNumberData @@ -187,18 +186,25 @@ export const mapFormToApi = ({ race: fieldGroupObjectToArray(data, "race"), } + const sendMailToMailingAddress = data.application.sendMailToMailingAddress + const applicationsMailingAddress = getAddress(sendMailToMailingAddress, mailingAddressData) const alternateContact = data.application.alternateContact // send null instead of empty string alternateContact.emailAddress = alternateContact.emailAddress || null + alternateContact.type = alternateContact.type || null // pass blank address, not used for now everywhere const alternateAddress = getAddress(false, null) const { incomeMonth, incomeYear, householdMembers } = data + householdMembers.forEach((member) => { + member.relationship = member.relationship || null + }) + const incomePeriod: IncomePeriodEnum | null = data.application?.incomePeriod || null const income = incomePeriod === IncomePeriodEnum.perMonth ? incomeMonth : incomeYear || null diff --git a/sites/public/src/pages/applications/household/member.tsx b/sites/public/src/pages/applications/household/member.tsx index 32b1a3662e..7b0bc501a5 100644 --- a/sites/public/src/pages/applications/household/member.tsx +++ b/sites/public/src/pages/applications/household/member.tsx @@ -13,6 +13,7 @@ import { import { CardSection } from "@bloom-housing/ui-seeds/src/blocks/Card" import { HouseholdMember, + HouseholdMemberRelationship, HouseholdMemberUpdate, YesNoEnum, } from "@bloom-housing/shared-helpers/src/types/backend-swagger" @@ -72,7 +73,7 @@ export class Member implements HouseholdMemberUpdate { longitude: undefined, } sameAddress?: YesNoEnum - relationship?: string + relationship?: HouseholdMemberRelationship workInRegion?: YesNoEnum }