-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup a dummy form example with validation and keyboard avoidance
- Loading branch information
Showing
18 changed files
with
307 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useRef } from 'react'; | ||
import type { SubmitHandler } from 'react-hook-form'; | ||
import { Controller, useForm } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import type { TextInput } from 'react-native'; | ||
|
||
import { | ||
DummyFormSchema, | ||
type DummyFormSchemaType, | ||
} from '$features/dummyForm/utils/dummyForm.schema'; | ||
import { Button } from '$shared/uiKit/button'; | ||
import { Input } from '$shared/uiKit/input'; | ||
import { Box } from '$shared/uiKit/primitives'; | ||
|
||
export const DummyFormExample = () => { | ||
const firstNameInputRef = useRef<TextInput>(null); | ||
const lastNameInputRef = useRef<TextInput>(null); | ||
|
||
const { t } = useTranslation('miscScreens'); | ||
|
||
const { control, handleSubmit } = useForm<DummyFormSchemaType>({ | ||
resolver: zodResolver(DummyFormSchema), | ||
}); | ||
|
||
const onSubmit: SubmitHandler<DummyFormSchemaType> = (data) => { | ||
// Do your form submission stuff here | ||
console.log('data', data); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Box pb="spacing_16" pt="spacing_32"> | ||
<Controller | ||
control={control} | ||
name="email" | ||
render={({ field: { onChange, onBlur, value }, fieldState }) => ( | ||
<Input | ||
autoCapitalize="none" | ||
autoComplete="email" | ||
autoCorrect={false} | ||
error={fieldState.error?.message} | ||
keyboardType="email-address" | ||
label={t('dummyForm.form.email.label')} | ||
placeholder={t('dummyForm.form.email.placeholder')} | ||
returnKeyType="next" | ||
value={value} | ||
onBlur={onBlur} | ||
onChangeText={onChange} | ||
onSubmitEditing={() => { | ||
firstNameInputRef.current?.focus(); | ||
}} | ||
/> | ||
)} | ||
/> | ||
</Box> | ||
|
||
<Box pb="spacing_16"> | ||
<Controller | ||
control={control} | ||
name="firstName" | ||
render={({ field: { onChange, onBlur, value }, fieldState }) => ( | ||
<Input | ||
ref={firstNameInputRef} | ||
autoComplete="name-given" | ||
error={fieldState.error?.message} | ||
label={t('dummyForm.form.firstName.label')} | ||
placeholder={t('dummyForm.form.firstName.placeholder')} | ||
returnKeyType="next" | ||
value={value} | ||
onBlur={onBlur} | ||
onChangeText={onChange} | ||
onSubmitEditing={() => { | ||
lastNameInputRef.current?.focus(); | ||
}} | ||
/> | ||
)} | ||
/> | ||
</Box> | ||
|
||
<Box pb="spacing_24"> | ||
<Controller | ||
control={control} | ||
name="lastName" | ||
render={({ field: { onChange, onBlur, value }, fieldState }) => ( | ||
<Input | ||
ref={lastNameInputRef} | ||
autoComplete="name-family" | ||
error={fieldState.error?.message} | ||
label={t('dummyForm.form.lastName.label')} | ||
placeholder={t('dummyForm.form.lastName.placeholder')} | ||
returnKeyType="done" | ||
value={value} | ||
onBlur={onBlur} | ||
onChangeText={onChange} | ||
onSubmitEditing={handleSubmit(onSubmit)} | ||
/> | ||
)} | ||
/> | ||
</Box> | ||
|
||
<Button.Text | ||
onPress={handleSubmit(onSubmit) as (arg: unknown) => Promise<unknown>} | ||
> | ||
Submit | ||
</Button.Text> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { DummyFormExample as DummyForm } from './DummyFormExample'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import i18next from 'i18next'; | ||
import { z } from 'zod'; | ||
|
||
const FIRST_NAME_MIN_LENGTH = 2; | ||
const FIRST_NAME_MAX_LENGTH = 20; | ||
const LAST_NAME_MIN_LENGTH = 2; | ||
const LAST_NAME_MAX_LENGTH = 30; | ||
|
||
export const DummyFormSchema = z.object({ | ||
email: z.string().email({ | ||
message: i18next.t('miscScreens:dummyForm.form.email.validation.email'), | ||
}), | ||
firstName: z | ||
.string() | ||
.min(FIRST_NAME_MIN_LENGTH, { | ||
message: i18next.t( | ||
'miscScreens:dummyForm.form.firstName.validation.minLength', | ||
), | ||
}) | ||
.max(FIRST_NAME_MAX_LENGTH, { | ||
message: i18next.t( | ||
'miscScreens:dummyForm.form.firstName.validation.maxLength', | ||
), | ||
}), | ||
lastName: z | ||
.string() | ||
.min(LAST_NAME_MIN_LENGTH, { | ||
message: i18next.t( | ||
'miscScreens:dummyForm.form.lastName.validation.minLength', | ||
), | ||
}) | ||
.max(LAST_NAME_MAX_LENGTH, { | ||
message: i18next.t( | ||
'miscScreens:dummyForm.form.lastName.validation.minLength', | ||
), | ||
}), | ||
}); | ||
|
||
export type DummyFormSchemaType = z.infer<typeof DummyFormSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { Box, Text } from '$shared/uiKit/primitives'; | ||
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; | ||
|
||
import { DummyForm as DummyFormComponent } from '$features/dummyForm'; | ||
import { Box } from '$shared/uiKit/primitives'; | ||
import { Screen } from '$shared/uiKit/Screen'; | ||
|
||
export const DummyForm = () => ( | ||
<Screen> | ||
<Box p="spacing_16"> | ||
<Text variant="large">DummyForm screen</Text> | ||
</Box> | ||
</Screen> | ||
); | ||
export const DummyForm = () => { | ||
return ( | ||
<Screen isScrollable={false}> | ||
<KeyboardAwareScrollView bottomOffset={50}> | ||
<Box px="spacing_16"> | ||
<DummyFormComponent /> | ||
</Box> | ||
</KeyboardAwareScrollView> | ||
</Screen> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.