Skip to content

Commit c9f6149

Browse files
committed
ProfileDetailsForm working with i18Next on interface
1 parent 718fdac commit c9f6149

2 files changed

Lines changed: 87 additions & 71 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ControlledField } from '@baca/components'
2+
import { isWeb } from '@baca/constants'
3+
import { Text, Box } from '@baca/design-system'
4+
import { useTranslation, useWeb } from '@baca/hooks'
5+
import { I18nKeys } from '@baca/types/i18next'
6+
import { Control, FieldErrors } from 'react-hook-form'
7+
8+
interface ProfileControlledInputProps {
9+
labelTx: I18nKeys
10+
name: string
11+
placeholderTx: I18nKeys
12+
control: Control
13+
errors: FieldErrors
14+
isDisabled?: boolean
15+
onFocus?: () => void
16+
onSubmitEditing?: () => void
17+
}
18+
19+
export const ProfileControlledInput = ({
20+
labelTx,
21+
name,
22+
placeholderTx,
23+
control,
24+
errors,
25+
isDisabled = false,
26+
onFocus,
27+
onSubmitEditing,
28+
}: ProfileControlledInputProps) => {
29+
const { t } = useTranslation()
30+
const { shouldApplyMobileStyles } = useWeb()
31+
32+
return (
33+
<Box
34+
justifyContent="space-between"
35+
flexDirection={isWeb && !shouldApplyMobileStyles ? 'row' : 'column'}
36+
mb={isWeb ? 10 : 0}
37+
maxW={800}
38+
>
39+
<Text.SmBold flex={1}>{t(labelTx)}</Text.SmBold>
40+
<Box flex={isWeb ? 2 : 0}>
41+
<ControlledField.Input
42+
control={control}
43+
errors={errors}
44+
autoCapitalize="none"
45+
inputMode={name === 'email' ? 'email' : 'text'}
46+
name={name}
47+
placeholder={t(placeholderTx)}
48+
testID={`${name}Input`}
49+
isDisabled={isDisabled}
50+
onFocus={onFocus}
51+
onSubmitEditing={onSubmitEditing}
52+
{...(!isWeb && { label: t(labelTx) })}
53+
/>
54+
</Box>
55+
</Box>
56+
)
57+
}

src/components/screens/profile/ProfileDetailsForm.tsx

Lines changed: 30 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { ControlledField } from '@baca/components'
2-
import { isWeb } from '@baca/constants'
3-
import { Text, Box, Button, Spacer, Row } from '@baca/design-system'
4-
import { useCallback, useTranslation, useUpdateProfileForm, useWeb } from '@baca/hooks'
1+
import { Box, Button, Spacer, Row } from '@baca/design-system'
2+
import { useUpdateProfileForm } from '@baca/hooks'
53
import { useRouter } from 'expo-router'
4+
import { useCallback } from 'react'
5+
import { useTranslation } from 'react-i18next'
6+
7+
import { ProfileControlledInput } from './ProfileControlledInput'
68

79
export const ProfileDetailsForm = () => {
810
const { t } = useTranslation()
9-
const { shouldApplyMobileStyles } = useWeb()
1011
const { control, errors, setFocus, submit, isSubmitting } = useUpdateProfileForm()
1112
const { back } = useRouter()
1213

@@ -15,72 +16,30 @@ export const ProfileDetailsForm = () => {
1516
return (
1617
<Box>
1718
<Box borderColor="border.secondary" borderTopWidth={1} py={6}>
18-
<Box
19-
justifyContent="space-between"
20-
flexDirection={isWeb && !shouldApplyMobileStyles ? 'row' : 'column'}
21-
mb={isWeb ? 10 : 0}
22-
maxW={800}
23-
>
24-
<Text.SmBold flex={1}>{t('form.labels.first_name')}</Text.SmBold>
25-
<Box flex={isWeb ? 2 : 0}>
26-
<ControlledField.Input
27-
{...{ control, errors }}
28-
autoCapitalize="none"
29-
inputMode="text"
30-
name="firstName"
31-
onFocus={focusLastNameInput}
32-
placeholder={t('form.placeholders.first_name')}
33-
testID="firstNameInput"
34-
{...(!isWeb && {
35-
label: t('form.labels.first_name'),
36-
})}
37-
/>
38-
</Box>
39-
</Box>
40-
<Box
41-
justifyContent="space-between"
42-
flexDirection={isWeb && !shouldApplyMobileStyles ? 'row' : 'column'}
43-
mb={isWeb ? 10 : 0}
44-
maxW={800}
45-
>
46-
<Text.SmBold flex={1}>{t('form.labels.last_name')}</Text.SmBold>
47-
<Box flex={isWeb ? 2 : 0}>
48-
<ControlledField.Input
49-
{...{ control, errors }}
50-
autoCapitalize="none"
51-
inputMode="text"
52-
name="lastName"
53-
placeholder={t('form.placeholders.last_name')}
54-
testID="lastNameInput"
55-
{...(!isWeb && {
56-
label: t('form.labels.last_name'),
57-
})}
58-
/>
59-
</Box>
60-
</Box>
61-
<Box
62-
justifyContent="space-between"
63-
flexDirection={isWeb && !shouldApplyMobileStyles ? 'row' : 'column'}
64-
mb={isWeb ? 10 : 0}
65-
maxW={800}
66-
>
67-
<Text.SmBold flex={1}>{t('form.labels.email')}</Text.SmBold>
68-
<Box flex={isWeb ? 2 : 0}>
69-
<ControlledField.Input
70-
{...{ control, errors }}
71-
autoCapitalize="none"
72-
inputMode="email"
73-
isDisabled
74-
name="email"
75-
onSubmitEditing={submit}
76-
placeholder={t('form.placeholders.email')}
77-
testID="emailInput"
78-
{...(!isWeb && {
79-
label: t('form.labels.email'),
80-
})}
81-
/>
82-
</Box>
83-
</Box>
19+
<ProfileControlledInput
20+
labelTx="form.labels.first_name"
21+
name="firstName"
22+
placeholderTx="form.placeholders.first_name"
23+
control={control}
24+
errors={errors}
25+
onFocus={focusLastNameInput}
26+
/>
27+
<ProfileControlledInput
28+
labelTx="form.labels.last_name"
29+
name="lastName"
30+
placeholderTx="form.placeholders.last_name"
31+
control={control}
32+
errors={errors}
33+
/>
34+
<ProfileControlledInput
35+
labelTx="form.labels.email"
36+
name="email"
37+
placeholderTx="form.placeholders.email"
38+
control={control}
39+
errors={errors}
40+
isDisabled
41+
onSubmitEditing={submit}
42+
/>
8443
<Row maxW={800} justifyContent="flex-end">
8544
<Button.SecondaryColor
8645
disabled={isSubmitting}

0 commit comments

Comments
 (0)