Skip to content

Commit 5b721dc

Browse files
committed
password with validations done
1 parent d1434f0 commit 5b721dc

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/components/screens/profile/ProfileControlledInput.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { isWeb } from '@baca/constants'
33
import { Box, Text } from '@baca/design-system'
44
import { useWeb } from '@baca/hooks'
55
import { ProfileControlledInputProps } from '@baca/types'
6-
import { StyleSheet } from 'react-native'
76

87
export const ProfileControlledInput = ({
98
label,
@@ -20,7 +19,7 @@ export const ProfileControlledInput = ({
2019
mb={isWeb ? 10 : 0}
2120
maxW={800}
2221
>
23-
<Text.SmBold flex={1} color="text.primary" style={styles.labelMargin}>
22+
<Text.SmBold flex={1} color="text.primary" mb={2.5}>
2423
{label}
2524
</Text.SmBold>
2625
<Box flex={isWeb ? 2 : 0}>
@@ -36,7 +35,3 @@ export const ProfileControlledInput = ({
3635
</Box>
3736
)
3837
}
39-
40-
const styles = StyleSheet.create({
41-
labelMargin: { marginBottom: 10 },
42-
})

src/components/screens/profile/ProfilePasswordForm.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Box, Button, Row } from '@baca/design-system'
2-
import { useUpdatePasswordForm } from '@baca/hooks/forms/useUpdatePasswordForm'
2+
import { useCallback } from '@baca/hooks'
3+
import { useUpdatePasswordForm } from '@baca/hooks/forms'
4+
import { usePasswordValidation } from '@baca/hooks/usePasswordValidation'
35
import { useTranslation } from 'react-i18next'
6+
import { Keyboard } from 'react-native'
47

58
import { ProfileControlledInput } from './ProfileControlledInput'
69

710
export const ProfilePasswordForm = () => {
811
const { t } = useTranslation()
9-
const { control, errors, submit, isSubmitting } = useUpdatePasswordForm()
12+
const { control, errors, submit, isSubmitting, setFocus } = useUpdatePasswordForm()
13+
14+
const { isPasswordError, passwordSuggestions, validationFn } = usePasswordValidation()
15+
16+
const focusNewPasswordInput = useCallback(() => setFocus('password'), [setFocus])
1017

1118
return (
1219
<Box borderColor="border.secondary" borderTopWidth={1} py={6}>
@@ -16,14 +23,21 @@ export const ProfilePasswordForm = () => {
1623
placeholder={t('form.placeholders.old_password')}
1724
control={control}
1825
errors={errors}
26+
onSubmitEditing={focusNewPasswordInput}
1927
/>
2028
<ProfileControlledInput
2129
label={t('form.labels.new_password')}
2230
name="password"
2331
placeholder={t('form.placeholders.new_password')}
2432
control={control}
25-
errors={errors}
33+
errors={{}}
34+
isInvalid={isPasswordError}
35+
isRequired
36+
rules={{ validate: { validationFn } }}
37+
type="password"
38+
onSubmitEditing={Keyboard.dismiss}
2639
/>
40+
{passwordSuggestions}
2741
<Row maxW={800} justifyContent="flex-end">
2842
<Button
2943
disabled={isSubmitting}

src/hooks/forms/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './useSignInForm'
44
export * from './useSignUpForm'
55
export * from './useTestForm'
66
export * from './useUpdateProfileForm'
7+
export * from './useUpdatePasswordForm'

src/hooks/forms/useUpdatePasswordForm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export const useUpdatePasswordForm = () => {
1818
formState: { errors },
1919
handleSubmit,
2020
reset,
21+
setFocus,
2122
setError: setFormError,
2223
} = useForm<AuthUpdateDto>({
23-
mode: 'onTouched',
24+
mode: 'onChange',
2425
defaultValues,
2526
})
2627

@@ -49,6 +50,7 @@ export const useUpdatePasswordForm = () => {
4950
control,
5051
errors,
5152
isSubmitting: isLoading,
53+
setFocus,
5254
submit: handleSubmit(onSubmit),
5355
}
5456
}

src/types/ProfileInputProps.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { Control, FieldErrors } from 'react-hook-form'
1+
import { Control, FieldErrors, RegisterOptions } from 'react-hook-form'
22

33
export type ProfileControlledInputProps = {
4-
label: string
5-
name: string
6-
placeholder: string
74
control: Control
85
errors: FieldErrors
96
isDisabled?: boolean
7+
isInvalid?: boolean
8+
isRequired?: boolean
9+
label: string
10+
name: string
1011
onFocus?: () => void
1112
onSubmitEditing?: () => void
13+
placeholder: string
14+
rules?: RegisterOptions
15+
type?: 'text' | 'password' | undefined
1216
}

0 commit comments

Comments
 (0)