Skip to content

Commit 79505b3

Browse files
Merge pull request #61 from binarapps/chore/clean-up-form-inputs
Chore/clean up form inputs
2 parents dc8604e + 8a1db38 commit 79505b3

3 files changed

Lines changed: 86 additions & 71 deletions

File tree

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

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+
label={t('form.labels.first_name')}
21+
name="firstName"
22+
placeholder={t('form.placeholders.first_name')}
23+
control={control}
24+
errors={errors}
25+
onFocus={focusLastNameInput}
26+
/>
27+
<ProfileControlledInput
28+
label={t('form.labels.last_name')}
29+
name="lastName"
30+
placeholder={t('form.placeholders.last_name')}
31+
control={control}
32+
errors={errors}
33+
/>
34+
<ProfileControlledInput
35+
label={t('form.labels.email')}
36+
name="email"
37+
placeholder={t('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}

src/types/ProfileInputProps.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Control, FieldErrors } from 'react-hook-form'
2+
3+
export type ProfileControlledInputProps = {
4+
label: string
5+
name: string
6+
placeholder: string
7+
control: Control
8+
errors: FieldErrors
9+
isDisabled?: boolean
10+
onFocus?: () => void
11+
onSubmitEditing?: () => void
12+
}

0 commit comments

Comments
 (0)