From 6787cdffa34f6965c02e4e88e3c76821b7cbdf10 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Wed, 18 Feb 2026 22:53:50 +0100 Subject: [PATCH] Remove impossible options for min max age --- web/components/optional-profile-form.tsx | 354 ++++++++++++++--------- 1 file changed, 220 insertions(+), 134 deletions(-) diff --git a/web/components/optional-profile-form.tsx b/web/components/optional-profile-form.tsx index ef8e0629..990df8de 100644 --- a/web/components/optional-profile-form.tsx +++ b/web/components/optional-profile-form.tsx @@ -23,10 +23,10 @@ import {PLATFORM_LABELS, type Site, SITE_ORDER} from 'common/socials' import {PlusIcon, XIcon} from '@heroicons/react/solid' import {SocialIcon} from './user/social' import {Select} from 'web/components/widgets/select' -import {City, CityRow, profileToCity, useCitySearch} from "web/components/search-location"; +import {City, CityRow, profileToCity, useCitySearch,} from 'web/components/search-location' import {AddPhotosWidget} from './widgets/add-photos' -import {RadioToggleGroup} from "web/components/widgets/radio-toggle-group"; -import {MultipleChoiceOptions} from "common/profiles/multiple-choice"; +import {RadioToggleGroup} from 'web/components/widgets/radio-toggle-group' +import {MultipleChoiceOptions} from 'common/profiles/multiple-choice' import {useProfileDraft} from 'web/hooks/use-profile-draft' import { DIET_CHOICES, @@ -39,31 +39,43 @@ import { RELATIONSHIP_CHOICES, RELATIONSHIP_STATUS_CHOICES, RELIGION_CHOICES, - ROMANTIC_CHOICES -} from "web/components/filters/choices"; -import toast from "react-hot-toast"; -import {db} from "web/lib/supabase/db"; -import {fetchChoices} from "web/hooks/use-choices"; -import {AddOptionEntry} from "web/components/add-option-entry"; -import {sleep} from "common/util/time" -import {SignupBio} from "web/components/bio/editable-bio"; -import {Editor} from "@tiptap/core"; -import {Slider} from "web/components/widgets/slider"; - + ROMANTIC_CHOICES, +} from 'web/components/filters/choices' +import toast from 'react-hot-toast' +import {db} from 'web/lib/supabase/db' +import {fetchChoices} from 'web/hooks/use-choices' +import {AddOptionEntry} from 'web/components/add-option-entry' +import {sleep} from 'common/util/time' +import {SignupBio} from 'web/components/bio/editable-bio' +import {Editor} from '@tiptap/core' +import {Slider} from 'web/components/widgets/slider' export const OptionalProfileUserForm = (props: { profile: ProfileWithoutUser - setProfile: (key: K, value: ProfileWithoutUser[K]) => void + setProfile: ( + key: K, + value: ProfileWithoutUser[K] + ) => void user: User buttonLabel?: string bottomNavBarVisible?: boolean fromSignup?: boolean onSubmit?: () => Promise }) => { - const {profile, user, buttonLabel, setProfile, fromSignup, onSubmit, bottomNavBarVisible = true} = props + const { + profile, + user, + buttonLabel, + setProfile, + fromSignup, + onSubmit, + bottomNavBarVisible = true, + } = props const [isSubmitting, setIsSubmitting] = useState(false) - const [lookingRelationship, setLookingRelationship] = useState((profile.pref_relation_styles || []).includes('relationship')) + const [lookingRelationship, setLookingRelationship] = useState( + (profile.pref_relation_styles || []).includes('relationship') + ) const [ageError, setAgeError] = useState(null) const router = useRouter() const t = useT() @@ -90,7 +102,9 @@ export const OptionalProfileUserForm = (props: { setHeightInches(Math.round(h % 12)) } - const [newLinks, setNewLinks] = useState>(user.link) + const [newLinks, setNewLinks] = useState>( + user.link + ) const [newLinkPlatform, setNewLinkPlatform] = useState('') const [newLinkValue, setNewLinkValue] = useState('') @@ -99,7 +113,12 @@ export const OptionalProfileUserForm = (props: { const [workChoices, setWorkChoices] = useState({}) const {locale} = useLocale() - const {clearProfileDraft} = useProfileDraft(user.id, profile, setProfile, updateHeight) + const {clearProfileDraft} = useProfileDraft( + user.id, + profile, + setProfile, + updateHeight + ) useEffect(() => { fetchChoices('interests', locale).then(setInterestChoices) @@ -109,10 +128,7 @@ export const OptionalProfileUserForm = (props: { const errorToast = () => { toast.error( - t( - 'profile.optional.error.invalid_fields', - 'Some fields are incorrect...' - ) + t('profile.optional.error.invalid_fields', 'Some fields are incorrect...') ) } @@ -153,10 +169,12 @@ export const OptionalProfileUserForm = (props: { } = profile console.debug('otherProfileProps', removeUndefinedProps(otherProfileProps)) const promises: Promise[] = [ - tryCatch(updateProfile(removeUndefinedProps(otherProfileProps) as any)) + tryCatch(updateProfile(removeUndefinedProps(otherProfileProps) as any)), ] if (interests) { - promises.push(api('update-options', {table: 'interests', values: interests})) + promises.push( + api('update-options', {table: 'interests', values: interests}) + ) } if (causes) { promises.push(api('update-options', {table: 'causes', values: causes})) @@ -192,7 +210,9 @@ export const OptionalProfileUserForm = (props: { while (Date.now() - start < 10000) { profile = await getProfileRow(user.id, db) if (profile) { - console.log(`Found profile after ${Date.now() - start} ms, ${i} attempts`) + console.log( + `Found profile after ${Date.now() - start} ms, ${i} attempts` + ) break } await sleep(500) @@ -202,7 +222,7 @@ export const OptionalProfileUserForm = (props: { await sleep(5000) // attempt to mitigate profile not found at /${username} upon creation router.push(`/${user.username}${fromSignup ? '?fromSignup=true' : ''}`) } else { - console.log("Profile not found after fetching, going back home...") + console.log('Profile not found after fetching, going back home...') router.push('/') } } else router.push('/') @@ -262,22 +282,30 @@ export const OptionalProfileUserForm = (props: { {t('profile.optional.subtitle', 'Optional information')} + {!fromSignup && ( + <> + + { + console.debug('bio changed', e, profile.bio) + setProfile('bio', e.getJSON()) + setProfile('bio_length', e.getText().length) + }} + /> + + )} - {!fromSignup && - <> - - { - console.debug('bio changed', e, profile.bio) - setProfile('bio', e.getJSON()) - setProfile('bio_length', e.getText().length) - }} - /> - - } - - + [t(`profile.gender.${v}`, k), v]))} + choicesMap={Object.fromEntries( + Object.entries(GENDERS).map(([k, v]) => [ + t(`profile.gender.${v}`, k), + v, + ]) + )} setChoice={(c) => setProfile('gender', c)} /> @@ -344,7 +377,10 @@ export const OptionalProfileUserForm = (props: { ) } else if (value !== null && value > 100) { setAgeError( - t('profile.optional.age.error_max', 'Please enter a valid age') + t( + 'profile.optional.age.error_max', + 'Please enter a valid age' + ) ) } else { setAgeError(null) @@ -369,12 +405,15 @@ export const OptionalProfileUserForm = (props: { setHeightFeet(undefined) } else { setHeightFeet(Number(e.target.value)) - const heightInInches = Number(e.target.value) * 12 + (heightInches ?? 0) + const heightInInches = + Number(e.target.value) * 12 + (heightInches ?? 0) setProfile('height_in_inches', heightInInches) } }} className={'w-16'} - value={typeof heightFeet === 'number' ? Math.floor(heightFeet) : ''} + value={ + typeof heightFeet === 'number' ? Math.floor(heightFeet) : '' + } min={0} /> @@ -387,12 +426,17 @@ export const OptionalProfileUserForm = (props: { setHeightInches(undefined) } else { setHeightInches(Number(e.target.value)) - const heightInInches = Number(e.target.value) + 12 * (heightFeet ?? 0) + const heightInInches = + Number(e.target.value) + 12 * (heightFeet ?? 0) setProfile('height_in_inches', heightInInches) } }} className={'w-16'} - value={typeof heightInches === 'number' ? Math.floor(heightInches) : ''} + value={ + typeof heightInches === 'number' + ? Math.floor(heightInches) + : '' + } min={0} /> @@ -417,9 +461,11 @@ export const OptionalProfileUserForm = (props: { } }} className={'w-20'} - value={heightFeet !== undefined && profile['height_in_inches'] - ? Math.round(profile['height_in_inches'] * 2.54) - : ''} + value={ + heightFeet !== undefined && profile['height_in_inches'] + ? Math.round(profile['height_in_inches'] * 2.54) + : '' + } min={0} /> @@ -438,11 +484,19 @@ export const OptionalProfileUserForm = (props: { /> - + - - {range(18, 100).map((m) => ( + + {range(18, (profile['pref_age_max'] ?? 100) + 1).map((m) => ( @@ -491,8 +545,8 @@ export const OptionalProfileUserForm = (props: { }} className={'w-18 border-ink-300 rounded-md'} > - - {range(18, 100).map((m) => ( + + {range(profile['pref_age_min'] ?? 18, 100).map((m) => ( @@ -517,7 +571,9 @@ export const OptionalProfileUserForm = (props: { /> - +