-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Form component. Use FormProvider instead Rename rulesForm to regex
- Loading branch information
1 parent
7891668
commit a6df3fe
Showing
25 changed files
with
248 additions
and
390 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
File renamed without changes.
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,2 @@ | ||
export const rxEmail = /^[a-z][a-z0-9%_\.]{3,32}@[a-z0-9]{3,}(\.[a-z]{3,4}){1,2}$/; | ||
export const rxPassword = /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W])(?!.*['"]).{8,}$/; |
This file was deleted.
Oops, something went wrong.
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
91 changes: 43 additions & 48 deletions
91
template/src/app/features/unAuthentication/login/design/components/FormLogin.tsx
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
69 changes: 44 additions & 25 deletions
69
template/src/app/features/unAuthentication/login/design/components/Input.tsx
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,34 +1,53 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import React, {memo, forwardRef} from 'react'; | ||
import {TextField} from '@components'; | ||
import {HookFormRules} from '@config/type'; | ||
import {FormLoginType} from '@model/login'; | ||
import React, {memo} from 'react'; | ||
import isEqual from 'react-fast-compare'; | ||
import {FieldError} from 'react-hook-form'; | ||
import {useController, useFormContext} from 'react-hook-form'; | ||
import {TextInputProps} from 'react-native'; | ||
|
||
import {FormValue} from './FormLogin'; | ||
|
||
interface InputProps { | ||
name: keyof FormValue; | ||
interface InputProps extends TextInputProps { | ||
name: keyof FormLoginType; | ||
label: string; | ||
error?: FieldError | undefined; | ||
onSubmit?: () => void; | ||
nameTrigger?: keyof FormValue; | ||
nameTrigger?: keyof FormLoginType; | ||
rules?: HookFormRules; | ||
} | ||
|
||
const InputComponent = forwardRef<any, InputProps>( | ||
({onSubmit, label, name, nameTrigger, error, ...rest}, ref) => { | ||
return ( | ||
<TextField | ||
onSubmit={onSubmit} | ||
ref={ref} | ||
nameTrigger={nameTrigger} | ||
error={error?.message !== undefined} | ||
label={label} | ||
name={name} | ||
typeInput={'flat'} | ||
{...rest} | ||
/> | ||
); | ||
}, | ||
); | ||
const InputComponent = ({ | ||
onSubmit, | ||
label, | ||
name, | ||
rules, | ||
nameTrigger, | ||
defaultValue = '', | ||
...rest | ||
}: InputProps) => { | ||
// state | ||
const {errors, control, trigger, getValues} = useFormContext<FormLoginType>(); | ||
const {field} = useController({ | ||
name, | ||
control, | ||
rules, | ||
defaultValue, | ||
}); | ||
// render | ||
return ( | ||
<TextField | ||
onSubmit={onSubmit} | ||
ref={field.ref} | ||
nameTrigger={nameTrigger} | ||
trigger={trigger} | ||
error={errors[name]?.message !== undefined} | ||
label={label} | ||
name={name} | ||
onChangeText={field.onChange} | ||
onBlur={field.onBlur} | ||
defaultValue={getValues()[name]} | ||
typeInput={'flat'} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export const Input = memo(InputComponent, isEqual); |
1 change: 0 additions & 1 deletion
1
template/src/app/features/unAuthentication/login/design/components/index.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.