Skip to content

Commit 9e7636e

Browse files
Merge branch 'chore/sections-division-ProfileScreen' of github.com:binarapps/baca-react-native-template into chore/sections-division-ProfileScreen
2 parents 85de1e0 + 5487ad2 commit 9e7636e

6 files changed

Lines changed: 58 additions & 34 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/ProfileEditImage.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isWeb } from '@baca/constants'
21
import { Box, Text, Button, Row, themeColors } from '@baca/design-system'
32
import * as ImagePicker from 'expo-image-picker'
43
import { t } from 'i18next'
@@ -22,8 +21,8 @@ export const ProfileEditImage: React.FC = () => {
2221
}, [])
2322

2423
return (
25-
<Box borderColor="border.secondary" borderTopWidth={1} py={6}>
26-
<Box style={styles.marginBottom}>
24+
<Row style={styles.container}>
25+
<Box style={styles.textContainer}>
2726
<Text.SmBold color="text.primary">{t('profile_screen.your_photo')}</Text.SmBold>
2827
<Text.SmRegular color="text.secondary">
2928
{t('profile_screen.your_photo_description')}
@@ -34,39 +33,47 @@ export const ProfileEditImage: React.FC = () => {
3433
<Image source={{ uri: image }} style={styles.image} />
3534
) : (
3635
<Box style={styles.placeholder}>
37-
<Text color="Gray modern.600">{t('profile_screen.photo_innerText')}</Text>
36+
<Text fontSize={11} color="Gray modern.600">
37+
{t('profile_screen.photo_innerText')}
38+
</Text>
3839
</Box>
3940
)}
4041
</Box>
41-
<Row maxW={800} justifyContent="flex-end">
42-
<Button onPress={pickImage}>{t('common.upload')}</Button>
43-
</Row>
44-
</Box>
42+
<Button onPress={pickImage}>{t('common.upload')}</Button>
43+
</Row>
4544
)
4645
}
4746

4847
const styles = StyleSheet.create({
48+
container: {
49+
alignItems: 'flex-start',
50+
flexDirection: 'row',
51+
flexWrap: 'wrap',
52+
justifyContent: 'space-between',
53+
maxWidth: 800,
54+
},
4955
image: {
5056
height: '100%',
5157
width: '100%',
5258
},
5359
imageContainer: {
54-
alignSelf: 'center',
55-
borderRadius: 50,
56-
height: 100,
60+
borderRadius: 32,
61+
height: 64,
5762
marginBottom: 10,
63+
marginRight: 82,
5864
overflow: 'hidden',
59-
right: isWeb ? 150 : 0,
60-
width: 100,
61-
},
62-
marginBottom: {
63-
marginBottom: 10,
65+
width: 64,
6466
},
6567
placeholder: {
6668
alignItems: 'center',
6769
backgroundColor: themeColors.primitives['Gray neutral']['50'],
6870
height: '100%',
6971
justifyContent: 'center',
70-
width: '100%',
72+
},
73+
textContainer: {
74+
flex: 1,
75+
marginBottom: 30,
76+
maxWidth: 260,
77+
minWidth: 260,
7178
},
7279
})

src/components/screens/profile/ProfilePasswordForm.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
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}>
1320
<ProfileControlledInput
21+
control={control}
22+
errors={errors}
1423
label={t('form.labels.old_password')}
1524
name="oldPassword"
25+
onSubmitEditing={focusNewPasswordInput}
1626
placeholder={t('form.placeholders.old_password')}
17-
control={control}
18-
errors={errors}
27+
type="password"
1928
/>
2029
<ProfileControlledInput
30+
control={control}
31+
errors={{}}
32+
isInvalid={isPasswordError}
33+
isRequired
2134
label={t('form.labels.new_password')}
2235
name="password"
36+
onSubmitEditing={Keyboard.dismiss}
2337
placeholder={t('form.placeholders.new_password')}
24-
control={control}
25-
errors={errors}
38+
rules={{ validate: { validationFn } }}
39+
type="password"
2640
/>
41+
{passwordSuggestions}
2742
<Row maxW={800} justifyContent="flex-end">
2843
<Button
2944
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)