diff --git a/tests/e2e/backend/utils/userInformation.ts b/tests/e2e/backend/utils/userInformation.ts index 2cd60b1..49dac7b 100644 --- a/tests/e2e/backend/utils/userInformation.ts +++ b/tests/e2e/backend/utils/userInformation.ts @@ -1,12 +1,12 @@ import { faker } from "@faker-js/faker"; -import { - RELATIONSHIP_CHOICES, - POLITICAL_CHOICES, - RELIGION_CHOICES, - DIET_CHOICES, - EDUCATION_CHOICES, - } from "../../../../web/components/filters/choices"; -import { Races } from "../../../../web/components/race"; +import { + RELATIONSHIP_CHOICES, + POLITICAL_CHOICES, + RELIGION_CHOICES, + DIET_CHOICES, + EDUCATION_CHOICES, + RACE_CHOICES, +} from "web/components/filters/choices"; class UserAccountInformation { @@ -41,7 +41,7 @@ class UserAccountInformation { diet = Object.values(DIET_CHOICES); drinks_per_month = faker.number.int({min: 4, max:40}); height_in_inches = faker.number.float({min: 56, max: 78, fractionDigits:2}); - ethnicity = Object.values(Races); + ethnicity = Object.values(RACE_CHOICES); education_level = Object.values(EDUCATION_CHOICES); company = faker.company.name(); occupation_title = faker.person.jobTitle(); diff --git a/web/components/filters/choices.tsx b/web/components/filters/choices.tsx index 45eda79..79e61d0 100644 --- a/web/components/filters/choices.tsx +++ b/web/components/filters/choices.tsx @@ -177,11 +177,23 @@ export const LANGUAGE_CHOICES = { 'Zulu': 'zulu', } -export const REVERTED_RELATIONSHIP_CHOICES = invert(RELATIONSHIP_CHOICES) -export const REVERTED_RELATIONSHIP_STATUS_CHOICES = invert(RELATIONSHIP_STATUS_CHOICES) -export const REVERTED_ROMANTIC_CHOICES = invert(ROMANTIC_CHOICES) -export const REVERTED_POLITICAL_CHOICES = invert(POLITICAL_CHOICES) -export const REVERTED_DIET_CHOICES = invert(DIET_CHOICES) -export const REVERTED_EDUCATION_CHOICES = invert(EDUCATION_CHOICES) -export const REVERTED_RELIGION_CHOICES = invert(RELIGION_CHOICES) -export const REVERTED_LANGUAGE_CHOICES = invert(LANGUAGE_CHOICES) \ No newline at end of file +export const RACE_CHOICES = { + 'Black/African origin': 'african', + 'East Asian': 'asian', + 'South/Southeast Asian': 'south_asian', + 'White/Caucasian': 'caucasian', + 'Hispanic/Latino': 'hispanic', + 'Middle Eastern': 'middle_eastern', + 'Native American/Indigenous': 'native_american', + Other: 'other', +} as const + +export const INVERTED_RELATIONSHIP_CHOICES = invert(RELATIONSHIP_CHOICES) +export const INVERTED_RELATIONSHIP_STATUS_CHOICES = invert(RELATIONSHIP_STATUS_CHOICES) +export const INVERTED_ROMANTIC_CHOICES = invert(ROMANTIC_CHOICES) +export const INVERTED_POLITICAL_CHOICES = invert(POLITICAL_CHOICES) +export const INVERTED_DIET_CHOICES = invert(DIET_CHOICES) +export const INVERTED_EDUCATION_CHOICES = invert(EDUCATION_CHOICES) +export const INVERTED_RELIGION_CHOICES = invert(RELIGION_CHOICES) +export const INVERTED_LANGUAGE_CHOICES = invert(LANGUAGE_CHOICES) +export const INVERTED_RACE_CHOICES = invert(RACE_CHOICES) \ No newline at end of file diff --git a/web/components/optional-profile-form.tsx b/web/components/optional-profile-form.tsx index 05fbdbc..133c664 100644 --- a/web/components/optional-profile-form.tsx +++ b/web/components/optional-profile-form.tsx @@ -13,7 +13,6 @@ import {updateProfile, updateUser} from 'web/lib/api' import {Column} from 'common/supabase/utils' import {User} from 'common/user' import {track} from 'web/lib/service/analytics' -import {Races} from './race' import {Carousel} from 'web/components/widgets/carousel' import {tryCatch} from 'common/util/try-catch' import {ProfileRow} from 'common/profiles/profile' @@ -32,7 +31,7 @@ import { DIET_CHOICES, EDUCATION_CHOICES, LANGUAGE_CHOICES, - POLITICAL_CHOICES, + POLITICAL_CHOICES, RACE_CHOICES, RELATIONSHIP_CHOICES, RELATIONSHIP_STATUS_CHOICES, RELIGION_CHOICES, @@ -555,7 +554,7 @@ export const OptionalProfileUserForm = (props: { setProfile('ethnicity', selected)} /> diff --git a/web/components/profile-about.tsx b/web/components/profile-about.tsx index 080d1ba..27bf667 100644 --- a/web/components/profile-about.tsx +++ b/web/components/profile-about.tsx @@ -1,15 +1,15 @@ import clsx from 'clsx' -import {convertRelationshipType, type RelationshipType,} from 'web/lib/util/convert-types' +import {convertRace, convertRelationshipType, type RelationshipType,} from 'web/lib/util/convert-types' import stringOrStringArrayToText from 'web/lib/util/string-or-string-array-to-text' import {ReactNode} from 'react' import { - REVERTED_DIET_CHOICES, - REVERTED_EDUCATION_CHOICES, - REVERTED_LANGUAGE_CHOICES, - REVERTED_POLITICAL_CHOICES, - REVERTED_RELATIONSHIP_STATUS_CHOICES, - REVERTED_RELIGION_CHOICES, - REVERTED_ROMANTIC_CHOICES + INVERTED_DIET_CHOICES, + INVERTED_EDUCATION_CHOICES, + INVERTED_LANGUAGE_CHOICES, + INVERTED_POLITICAL_CHOICES, + INVERTED_RELATIONSHIP_STATUS_CHOICES, + INVERTED_RELIGION_CHOICES, + INVERTED_ROMANTIC_CHOICES } from 'web/components/filters/choices' import {BiSolidDrink} from 'react-icons/bi' import {BsPersonHeart} from 'react-icons/bs' @@ -24,7 +24,6 @@ import {fromNow} from 'web/lib/util/time' import {convertGenderPlural, Gender} from 'common/gender' import {HiOutlineGlobe} from 'react-icons/hi' import {UserHandles} from 'web/components/user/user-handles' -import {convertRace} from './race' import {Profile} from 'common/profiles/profile' import {UserActivity} from "common/user"; import {ClockIcon} from "@heroicons/react/solid"; @@ -80,22 +79,22 @@ export default function ProfileAbout(props: { } - text={profile.relationship_status?.map(v => REVERTED_RELATIONSHIP_STATUS_CHOICES[v])} + text={profile.relationship_status?.map(v => INVERTED_RELATIONSHIP_STATUS_CHOICES[v])} /> } - text={profile.languages?.map(v => REVERTED_LANGUAGE_CHOICES[v])} + text={profile.languages?.map(v => INVERTED_LANGUAGE_CHOICES[v])} /> } - text={profile.political_beliefs?.map(belief => REVERTED_POLITICAL_CHOICES[belief])} + text={profile.political_beliefs?.map(belief => INVERTED_POLITICAL_CHOICES[belief])} suffix={profile.political_details} /> } - text={profile.religion?.map(belief => REVERTED_RELIGION_CHOICES[belief])} + text={profile.religion?.map(belief => INVERTED_RELIGION_CHOICES[belief])} suffix={profile.religious_beliefs} /> } - text={profile.diet?.map(e => REVERTED_DIET_CHOICES[e])} + text={profile.diet?.map(e => INVERTED_DIET_CHOICES[e])} /> @@ -175,7 +174,7 @@ function RelationshipType(props: { profile: Profile }) { }) if (relationshipTypes?.includes('relationship')) { const romanticStyles = profile.pref_romantic_styles - ?.map((style) => REVERTED_ROMANTIC_CHOICES[style].toLowerCase()) + ?.map((style) => INVERTED_ROMANTIC_CHOICES[style].toLowerCase()) .filter(Boolean) if (romanticStyles && romanticStyles.length > 0) { seekingGenderText += ` (${romanticStyles.join(', ')})` @@ -198,7 +197,7 @@ function Education(props: { profile: Profile }) { let text = '' if (educationLevel) { - text += capitalizeAndRemoveUnderscores(REVERTED_EDUCATION_CHOICES[educationLevel]) + text += capitalizeAndRemoveUnderscores(INVERTED_EDUCATION_CHOICES[educationLevel]) } if (university) { if (educationLevel) text += ' at ' diff --git a/web/components/race.ts b/web/components/race.ts deleted file mode 100644 index 0b6d31d..0000000 --- a/web/components/race.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { invert } from 'lodash' - -// label -> backend -export const Races = { - 'Black/African origin': 'african', - 'East Asian': 'asian', - 'South/Southeast Asian': 'south_asian', - 'White/Caucasian': 'caucasian', - 'Hispanic/Latino': 'hispanic', - 'Middle Eastern': 'middle_eastern', - 'Native American/Indigenous': 'native_american', - Other: 'other', -} as const - -export type Race = (typeof Races)[keyof typeof Races] - -const raceTolabel = invert(Races) - -export function convertRace(race: Race) { - return raceTolabel[race] -} diff --git a/web/lib/util/convert-types.ts b/web/lib/util/convert-types.ts index 798a123..ca766f4 100644 --- a/web/lib/util/convert-types.ts +++ b/web/lib/util/convert-types.ts @@ -1,50 +1,65 @@ import { - REVERTED_DIET_CHOICES, - REVERTED_EDUCATION_CHOICES, - REVERTED_LANGUAGE_CHOICES, - REVERTED_POLITICAL_CHOICES, - REVERTED_RELATIONSHIP_CHOICES, REVERTED_RELATIONSHIP_STATUS_CHOICES, - REVERTED_RELIGION_CHOICES, - REVERTED_ROMANTIC_CHOICES + INVERTED_DIET_CHOICES, + INVERTED_EDUCATION_CHOICES, + INVERTED_LANGUAGE_CHOICES, + INVERTED_POLITICAL_CHOICES, + INVERTED_RACE_CHOICES, + INVERTED_RELATIONSHIP_CHOICES, + INVERTED_RELATIONSHIP_STATUS_CHOICES, + INVERTED_RELIGION_CHOICES, + INVERTED_ROMANTIC_CHOICES } from "web/components/filters/choices"; -export type RelationshipType = keyof typeof REVERTED_RELATIONSHIP_CHOICES -export type RelationshipStatusType = keyof typeof REVERTED_RELATIONSHIP_STATUS_CHOICES -export type RomanticType = keyof typeof REVERTED_ROMANTIC_CHOICES -export type DietType = keyof typeof REVERTED_DIET_CHOICES -export type PoliticalType = keyof typeof REVERTED_POLITICAL_CHOICES -export type EducationType = keyof typeof REVERTED_EDUCATION_CHOICES -export type ReligionType = keyof typeof REVERTED_RELIGION_CHOICES -export type LanguageType = keyof typeof REVERTED_LANGUAGE_CHOICES +export type RelationshipType = keyof typeof INVERTED_RELATIONSHIP_CHOICES export function convertRelationshipType(relationshipType: RelationshipType) { - return REVERTED_RELATIONSHIP_CHOICES[relationshipType] + return INVERTED_RELATIONSHIP_CHOICES[relationshipType] } +export type RelationshipStatusType = keyof typeof INVERTED_RELATIONSHIP_STATUS_CHOICES + export function convertRelationshipStatusTypes(relationshipStatusType: RelationshipStatusType) { - return REVERTED_RELATIONSHIP_STATUS_CHOICES[relationshipStatusType] + return INVERTED_RELATIONSHIP_STATUS_CHOICES[relationshipStatusType] } +export type RomanticType = keyof typeof INVERTED_ROMANTIC_CHOICES + export function convertRomanticTypes(romanticType: RomanticType) { - return REVERTED_ROMANTIC_CHOICES[romanticType] + return INVERTED_ROMANTIC_CHOICES[romanticType] } +export type DietType = keyof typeof INVERTED_DIET_CHOICES + export function convertDietTypes(dietType: DietType) { - return REVERTED_DIET_CHOICES[dietType] + return INVERTED_DIET_CHOICES[dietType] } +export type PoliticalType = keyof typeof INVERTED_POLITICAL_CHOICES + export function convertPoliticalTypes(politicalType: PoliticalType) { - return REVERTED_POLITICAL_CHOICES[politicalType] + return INVERTED_POLITICAL_CHOICES[politicalType] } +export type EducationType = keyof typeof INVERTED_EDUCATION_CHOICES + export function convertEducationTypes(educationType: EducationType) { - return REVERTED_EDUCATION_CHOICES[educationType] + return INVERTED_EDUCATION_CHOICES[educationType] } +export type ReligionType = keyof typeof INVERTED_RELIGION_CHOICES + export function convertReligionTypes(religionType: ReligionType) { - return REVERTED_RELIGION_CHOICES[religionType] + return INVERTED_RELIGION_CHOICES[religionType] } +export type LanguageType = keyof typeof INVERTED_LANGUAGE_CHOICES + export function convertLanguageTypes(languageType: LanguageType) { - return REVERTED_LANGUAGE_CHOICES[languageType] + return INVERTED_LANGUAGE_CHOICES[languageType] } + +export type RaceType = keyof typeof INVERTED_RACE_CHOICES + +export function convertRace(race: RaceType) { + return INVERTED_RACE_CHOICES[race] +} \ No newline at end of file