add validation

This commit is contained in:
Eric Bailey
2024-09-17 11:55:19 -07:00
committed by Hailey
parent 665150ca9d
commit b84e852fb8
2 changed files with 35 additions and 9 deletions
+3 -1
View File
@@ -15,6 +15,7 @@ export interface BackNextButtonsProps {
onBackPress: () => void onBackPress: () => void
onNextPress?: () => void onNextPress?: () => void
onRetryPress?: () => void onRetryPress?: () => void
overrideNextText?: string
} }
export function BackNextButtons({ export function BackNextButtons({
@@ -25,6 +26,7 @@ export function BackNextButtons({
onBackPress, onBackPress,
onNextPress, onNextPress,
onRetryPress, onRetryPress,
overrideNextText,
}: BackNextButtonsProps) { }: BackNextButtonsProps) {
const {_} = useLingui() const {_} = useLingui()
@@ -63,7 +65,7 @@ export function BackNextButtons({
disabled={isLoading || isNextDisabled} disabled={isLoading || isNextDisabled}
onPress={onNextPress}> onPress={onNextPress}>
<ButtonText> <ButtonText>
<Trans>Next</Trans> {overrideNextText ? overrideNextText : <Trans>Next</Trans>}
</ButtonText> </ButtonText>
{isLoading && <ButtonIcon icon={Loader} />} {isLoading && <ButtonIcon icon={Loader} />}
</Button> </Button>
+32 -8
View File
@@ -3,6 +3,7 @@ import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import * as EmailValidator from 'email-validator' import * as EmailValidator from 'email-validator'
import type tldts from 'tldts'
import {logEvent} from '#/lib/statsig/statsig' import {logEvent} from '#/lib/statsig/statsig'
import {logger} from '#/logger' import {logger} from '#/logger'
@@ -48,11 +49,39 @@ export function StepInfo({
const emailValueRef = useRef<string>(state.email) const emailValueRef = useRef<string>(state.email)
const passwordValueRef = useRef<string>(state.password) const passwordValueRef = useRef<string>(state.password)
const onNextPress = React.useCallback(async () => { const [hasWarnedEmail, setHasWarnedEmail] = React.useState<boolean>(false)
const tldtsRef = React.useRef<typeof tldts>()
React.useEffect(() => {
// @ts-expect-error - valid path
import('../../../../node_modules/tldts/dist/index.cjs.min.js').then(
tldts => {
tldtsRef.current = tldts
},
)
}, [])
const onNextPress = () => {
const inviteCode = inviteCodeValueRef.current const inviteCode = inviteCodeValueRef.current
const email = emailValueRef.current const email = emailValueRef.current
const password = passwordValueRef.current const password = passwordValueRef.current
if (!hasWarnedEmail && tldtsRef.current) {
console.log(tldtsRef.current)
const isIcann = tldtsRef.current.parse(email).isIcann
if (!isIcann) {
setHasWarnedEmail(true)
return dispatch({
type: 'setError',
value: _(
msg`It looks like you may have entered your email address incorrectly. Are you sure it's right?`,
),
})
}
} else if (hasWarnedEmail) {
setHasWarnedEmail(false)
}
if (!is13(state.dateOfBirth)) { if (!is13(state.dateOfBirth)) {
return return
} }
@@ -89,13 +118,7 @@ export function StepInfo({
logEvent('signup:nextPressed', { logEvent('signup:nextPressed', {
activeStep: state.activeStep, activeStep: state.activeStep,
}) })
}, [ }
_,
dispatch,
state.activeStep,
state.dateOfBirth,
state.serviceDescription?.inviteCodeRequired,
])
return ( return (
<ScreenTransition> <ScreenTransition>
@@ -208,6 +231,7 @@ export function StepInfo({
onBackPress={onPressBack} onBackPress={onPressBack}
onNextPress={onNextPress} onNextPress={onNextPress}
onRetryPress={refetchServer} onRetryPress={refetchServer}
overrideNextText={hasWarnedEmail ? _(msg`It's correct`) : undefined}
/> />
</ScreenTransition> </ScreenTransition>
) )