From 63bb8fda2d28e11d7e60808e1e86384d48ec1b47 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 2 Jul 2024 14:43:34 -0700 Subject: Improve textinput performance in login and account creation (#4673) * Change login form to use uncontrolled inputs * Debounce state updates in account creation to reduce flicker * Refactor state-control of account creation forms to fix perf without relying on debounces * Remove canNext and enforce is13 * Re-add live validation to signup form (#4720) * Update validation in real time * Disable on invalid * Clear server error on typing * Remove unnecessary clearing of error --------- Co-authored-by: Dan Abramov --- src/screens/Signup/index.tsx | 146 +++++-------------------------------------- 1 file changed, 15 insertions(+), 131 deletions(-) (limited to 'src/screens/Signup/index.tsx') diff --git a/src/screens/Signup/index.tsx b/src/screens/Signup/index.tsx index f7ca180bf..da0383884 100644 --- a/src/screens/Signup/index.tsx +++ b/src/screens/Signup/index.tsx @@ -7,11 +7,7 @@ import {useLingui} from '@lingui/react' import {useAnalytics} from '#/lib/analytics/analytics' import {FEEDBACK_FORM_URL} from '#/lib/constants' -import {logEvent} from '#/lib/statsig/statsig' -import {createFullHandle} from '#/lib/strings/handles' -import {logger} from '#/logger' import {useServiceQuery} from '#/state/queries/service' -import {useAgent} from '#/state/session' import {useStarterPackQuery} from 'state/queries/starter-packs' import {useActiveStarterPack} from 'state/shell/starter-pack' import {LoggedOutLayout} from '#/view/com/util/layouts/LoggedOutLayout' @@ -20,14 +16,12 @@ import { reducer, SignupContext, SignupStep, - useSubmitSignup, } from '#/screens/Signup/state' import {StepCaptcha} from '#/screens/Signup/StepCaptcha' import {StepHandle} from '#/screens/Signup/StepHandle' import {StepInfo} from '#/screens/Signup/StepInfo' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {AppLanguageDropdown} from '#/components/AppLanguageDropdown' -import {Button, ButtonText} from '#/components/Button' import {Divider} from '#/components/Divider' import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {InlineLinkText} from '#/components/Link' @@ -38,9 +32,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { const t = useTheme() const {screen} = useAnalytics() const [state, dispatch] = React.useReducer(reducer, initialState) - const submit = useSubmitSignup({state, dispatch}) const {gtMobile} = useBreakpoints() - const agent = useAgent() const activeStarterPack = useActiveStarterPack() const { @@ -89,72 +81,6 @@ export function Signup({onPressBack}: {onPressBack: () => void}) { } }, [_, serviceInfo, isError]) - const onNextPress = React.useCallback(async () => { - if (state.activeStep === SignupStep.HANDLE) { - try { - dispatch({type: 'setIsLoading', value: true}) - - const res = await agent.resolveHandle({ - handle: createFullHandle(state.handle, state.userDomain), - }) - - if (res.data.did) { - dispatch({ - type: 'setError', - value: _(msg`That handle is already taken.`), - }) - return - } - } catch (e) { - // Don't have to handle - } finally { - dispatch({type: 'setIsLoading', value: false}) - } - } - - logEvent('signup:nextPressed', { - activeStep: state.activeStep, - phoneVerificationRequired: - state.serviceDescription?.phoneVerificationRequired, - }) - - // phoneVerificationRequired is actually whether a captcha is required - if ( - state.activeStep === SignupStep.HANDLE && - !state.serviceDescription?.phoneVerificationRequired - ) { - submit() - return - } - dispatch({type: 'next'}) - }, [ - _, - state.activeStep, - state.handle, - state.serviceDescription?.phoneVerificationRequired, - state.userDomain, - submit, - agent, - ]) - - const onBackPress = React.useCallback(() => { - if (state.activeStep !== SignupStep.INFO) { - if (state.activeStep === SignupStep.CAPTCHA) { - logger.error('Signup Flow Error', { - errorMessage: - 'User went back from captcha step. Possibly encountered an error.', - registrationHandle: state.handle, - }) - } - dispatch({type: 'prev'}) - } else { - onPressBack() - } - logEvent('signup:backPressed', { - activeStep: state.activeStep, - }) - }, [onPressBack, state.activeStep, state.handle]) - return ( void}) { - - - {state.activeStep === SignupStep.INFO ? ( - - ) : state.activeStep === SignupStep.HANDLE ? ( - - ) : ( - - )} - - - - - - {state.activeStep !== SignupStep.CAPTCHA && ( - <> - {isError ? ( - - ) : ( - - )} - + + {state.activeStep === SignupStep.INFO ? ( + + ) : state.activeStep === SignupStep.HANDLE ? ( + + ) : ( + )} - + -- cgit 1.4.1