import clsx from 'clsx' import {APIError} from 'common/api/utils' import {debug} from 'common/logger' import {useState} from 'react' import {Button} from 'web/components/buttons/button' import {Col} from 'web/components/layout/col' import {Row} from 'web/components/layout/row' import {Input} from 'web/components/widgets/input' import {LoadingIndicator} from 'web/components/widgets/loading-indicator' import {Title} from 'web/components/widgets/title' import {api} from 'web/lib/api' import {useT} from 'web/lib/locale' import {labelClassName} from 'web/pages/signup' const LAST_STEP = 0 export const initialRequiredState = { age: undefined, gender: '', pref_gender: [], pref_age_min: undefined, pref_age_max: undefined, pref_relation_styles: [], wants_kids_strength: -1, looking_for_matches: true, visibility: 'public', city: '', pinned_url: '', photo_urls: [], languages: [], bio: null, } export type RequiredFormData = { name: string username: string } export const RequiredProfileUserForm = (props: { data: RequiredFormData setData: ( key: K, value: RequiredFormData[K] | undefined, ) => void onSubmit?: () => void profileCreatedAlready?: boolean }) => { const {onSubmit, profileCreatedAlready, data, setData} = props const [step, setStep] = useState(0) const [loadingUsername, setLoadingUsername] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const [errorMessageUsername, setErrorUsername] = useState(null) const [errorMessageDisplayName, setErrorDisplayName] = useState(null) const t = useT() const isDisabled = !!errorMessageDisplayName || !!errorMessageUsername || isSubmitting const updateUsername = async () => { let success = true setLoadingUsername(true) try { if (data.username.length < 3) { setErrorUsername('Minimum 3 characters required for usernames') success = false setLoadingUsername(false) return success } const { valid, message = undefined, suggestedUsername, } = await api('validate-username', {username: data.username}) if (valid) { setData('username', suggestedUsername) } else { setErrorUsername(message || 'Unknown error') success = false } } catch (reason) { setErrorUsername((reason as APIError).message) success = false } setLoadingUsername(false) debug('Username:', data.username) return success } return ( <> {!profileCreatedAlready && {t('profile.basics.title', 'The Basics')}} {/*{step === 1 && !profileCreatedAlready && (*/} {/*
*/} {/* {t('profile.basics.subtitle', 'Write your own bio, your own way.')}*/} {/*
*/} {/*)}*/} {(step === 0 || profileCreatedAlready) && ( ) => { const value = e.target.value || '' if (value.length < 3) { setErrorDisplayName('Minimum 3 characters for display names') } else { setErrorDisplayName(null) } setData('name', value) }} /> {errorMessageDisplayName && (

{errorMessageDisplayName}

)} )} {!profileCreatedAlready && ( <> {step === 0 && ( ) => { const value = e.target.value || '' if (value.length < 3) { setErrorUsername('Minimum 3 characters required for usernames') } else { setErrorUsername(null) } setData('username', value) }} /> {loadingUsername && } { {t( 'profile.required.username_letters_only', 'Only letters and numbers are allowed for the username.', )} } {errorMessageUsername && ( {errorMessageUsername} )} )} {/*{step === 1 && (*/} {/* */} {/* */} {/* {*/} {/* console.debug('bio changed', e, profile.bio)*/} {/* setProfile('bio', e.getJSON())*/} {/* setProfile('bio_length', e.getText().length)*/} {/* }}*/} {/* />*/} {/* */} {/*)}*/} )} {onSubmit && ( )} ) }