highlight error field
This commit is contained in:
@@ -57,9 +57,11 @@ export const LoginForm = ({
|
||||
onAttemptFailed: () => void
|
||||
}) => {
|
||||
const t = useTheme()
|
||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||
const [isAuthFactorTokenNeeded, setIsAuthFactorTokenNeeded] =
|
||||
useState<boolean>(false)
|
||||
const [isProcessing, setIsProcessing] = useState(false)
|
||||
const [errorField, setErrorField] = useState<
|
||||
'none' | 'identifier' | 'password' | '2fa'
|
||||
>('none')
|
||||
const [isAuthFactorTokenNeeded, setIsAuthFactorTokenNeeded] = useState(false)
|
||||
const identifierValueRef = useRef<string>(initialHandle || '')
|
||||
const passwordValueRef = useRef<string>('')
|
||||
const [authFactorToken, setAuthFactorToken] = useState('')
|
||||
@@ -80,17 +82,20 @@ export const LoginForm = ({
|
||||
if (isProcessing) return
|
||||
Keyboard.dismiss()
|
||||
setError('')
|
||||
setErrorField('none')
|
||||
|
||||
const identifier = identifierValueRef.current.toLowerCase().trim()
|
||||
const password = passwordValueRef.current
|
||||
|
||||
if (!identifier) {
|
||||
setError(_(msg`Please enter your username`))
|
||||
setErrorField('identifier')
|
||||
return
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
setError(_(msg`Please enter your password`))
|
||||
setErrorField('password')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,6 +152,7 @@ export const LoginForm = ({
|
||||
error: errMsg,
|
||||
})
|
||||
setError(_(msg`Invalid 2FA confirmation code.`))
|
||||
setErrorField('2fa')
|
||||
} else if (
|
||||
errMsg.includes('Authentication Required') ||
|
||||
errMsg.includes('Invalid identifier or password')
|
||||
@@ -187,7 +193,7 @@ export const LoginForm = ({
|
||||
<Trans>Account</Trans>
|
||||
</TextField.LabelText>
|
||||
<View style={[a.gap_sm]}>
|
||||
<TextField.Root>
|
||||
<TextField.Root isInvalid={errorField === 'identifier'}>
|
||||
<TextField.Icon icon={At} />
|
||||
<TextField.Input
|
||||
testID="loginUsernameInput"
|
||||
@@ -202,6 +208,7 @@ export const LoginForm = ({
|
||||
defaultValue={initialHandle || ''}
|
||||
onChangeText={v => {
|
||||
identifierValueRef.current = v
|
||||
if (errorField) setErrorField('none')
|
||||
}}
|
||||
onSubmitEditing={() => {
|
||||
passwordRef.current?.focus()
|
||||
@@ -214,7 +221,7 @@ export const LoginForm = ({
|
||||
/>
|
||||
</TextField.Root>
|
||||
|
||||
<TextField.Root>
|
||||
<TextField.Root isInvalid={errorField === 'password'}>
|
||||
<TextField.Icon icon={Lock} />
|
||||
<TextField.Input
|
||||
testID="loginPasswordInput"
|
||||
@@ -229,6 +236,7 @@ export const LoginForm = ({
|
||||
clearButtonMode="while-editing"
|
||||
onChangeText={v => {
|
||||
passwordValueRef.current = v
|
||||
if (errorField) setErrorField('none')
|
||||
}}
|
||||
onSubmitEditing={onPressNext}
|
||||
blurOnSubmit={false} // HACK: https://github.com/facebook/react-native/issues/21911#issuecomment-558343069 Keyboard blur behavior is now handled in onSubmitEditing
|
||||
@@ -270,7 +278,7 @@ export const LoginForm = ({
|
||||
<TextField.LabelText>
|
||||
<Trans>2FA Confirmation</Trans>
|
||||
</TextField.LabelText>
|
||||
<TextField.Root>
|
||||
<TextField.Root isInvalid={errorField === '2fa'}>
|
||||
<TextField.Icon icon={Ticket} />
|
||||
<TextField.Input
|
||||
testID="loginAuthFactorTokenInput"
|
||||
@@ -281,8 +289,11 @@ export const LoginForm = ({
|
||||
autoComplete="one-time-code"
|
||||
returnKeyType="done"
|
||||
blurOnSubmit={false} // prevents flickering due to onSubmitEditing going to next field
|
||||
onChangeText={setAuthFactorToken}
|
||||
value={authFactorToken} // controlled input due to uncontrolled input not receiving pasted values properly
|
||||
onChangeText={text => {
|
||||
setAuthFactorToken(text)
|
||||
if (errorField) setErrorField('none')
|
||||
}}
|
||||
onSubmitEditing={onPressNext}
|
||||
editable={!isProcessing}
|
||||
accessibilityHint={_(
|
||||
|
||||
Reference in New Issue
Block a user