|
1 | 1 | import { InputGroup, InputGroupProps2 } from '@blueprintjs/core'
|
2 |
| -import { ControllerProps, FieldValues, UseControllerProps } from 'react-hook-form' |
| 2 | + |
| 3 | +import { |
| 4 | + ControllerProps, |
| 5 | + FieldValues, |
| 6 | + UseControllerProps, |
| 7 | +} from 'react-hook-form' |
3 | 8 | import { useTranslation } from 'react-i18next'
|
| 9 | + |
4 | 10 | import { FormField, FormFieldProps } from 'components/FormField'
|
5 | 11 | import { REGEX_EMAIL, REGEX_USERNAME } from 'utils/regexes'
|
6 | 12 |
|
7 | 13 | export type RuleKeys = 'email' | 'password' | 'username' | 'registertoken'
|
8 | 14 |
|
9 |
| -// Define rules with translation keys |
10 | 15 | export const rule: Record<RuleKeys, UseControllerProps['rules']> = {
|
11 | 16 | email: {
|
12 | 17 | required: 'components.account.AuthFormShared.email_required',
|
13 |
| - pattern: { value: REGEX_EMAIL, message: 'components.account.AuthFormShared.email_invalid' }, |
| 18 | + pattern: { |
| 19 | + value: REGEX_EMAIL, |
| 20 | + message: 'components.account.AuthFormShared.email_invalid', |
| 21 | + }, |
14 | 22 | },
|
15 | 23 | password: {
|
16 | 24 | required: 'components.account.AuthFormShared.password_required',
|
17 |
| - minLength: { value: 8, message: 'components.account.AuthFormShared.password_min_length' }, |
18 |
| - maxLength: { value: 32, message: 'components.account.AuthFormShared.password_max_length' }, |
| 25 | + minLength: { |
| 26 | + value: 8, |
| 27 | + message: 'components.account.AuthFormShared.password_min_length', |
| 28 | + }, |
| 29 | + maxLength: { |
| 30 | + value: 32, |
| 31 | + message: 'components.account.AuthFormShared.password_max_length', |
| 32 | + }, |
19 | 33 | },
|
20 | 34 | username: {
|
21 | 35 | required: 'components.account.AuthFormShared.username_required',
|
22 |
| - minLength: { value: 4, message: 'components.account.AuthFormShared.username_min_length' }, |
23 |
| - maxLength: { value: 24, message: 'components.account.AuthFormShared.username_max_length' }, |
24 |
| - pattern: { value: REGEX_USERNAME, message: 'components.account.AuthFormShared.username_pattern' }, |
| 36 | + minLength: { |
| 37 | + value: 4, |
| 38 | + message: 'components.account.AuthFormShared.username_min_length', |
| 39 | + }, |
| 40 | + maxLength: { |
| 41 | + value: 24, |
| 42 | + message: 'components.account.AuthFormShared.username_max_length', |
| 43 | + }, |
| 44 | + pattern: { |
| 45 | + value: REGEX_USERNAME, |
| 46 | + message: 'components.account.AuthFormShared.username_pattern', |
| 47 | + }, |
25 | 48 | },
|
26 | 49 | registertoken: {
|
27 | 50 | required: 'components.account.AuthFormShared.token_required',
|
28 |
| - minLength: { value: 6, message: 'components.account.AuthFormShared.token_length' }, |
29 |
| - maxLength: { value: 6, message: 'components.account.AuthFormShared.token_length' }, |
| 51 | + minLength: { |
| 52 | + value: 6, |
| 53 | + message: 'components.account.AuthFormShared.token_length', |
| 54 | + }, |
| 55 | + maxLength: { |
| 56 | + value: 6, |
| 57 | + message: 'components.account.AuthFormShared.token_length', |
| 58 | + }, |
30 | 59 | },
|
31 | 60 | }
|
32 | 61 |
|
33 |
| -// Helper function that translates rule messages |
34 | 62 | function useTranslatedRules() {
|
35 | 63 | const { t } = useTranslation()
|
36 | 64 |
|
@@ -102,7 +130,9 @@ export const AuthFormEmailField = <T extends FieldValues>({
|
102 | 130 | ),
|
103 | 131 | }}
|
104 | 132 | FormGroupProps={{
|
105 |
| - helperText: register && t('components.account.AuthFormShared.email_verification_note'), |
| 133 | + helperText: |
| 134 | + register && |
| 135 | + t('components.account.AuthFormShared.email_verification_note'), |
106 | 136 | }}
|
107 | 137 | />
|
108 | 138 | )
|
@@ -140,7 +170,9 @@ export const AuthRegistrationTokenField = <T extends FieldValues>({
|
140 | 170 | ),
|
141 | 171 | }}
|
142 | 172 | FormGroupProps={{
|
143 |
| - helperText: register && t('components.account.AuthFormShared.token_verification_note'), |
| 173 | + helperText: |
| 174 | + register && |
| 175 | + t('components.account.AuthFormShared.token_verification_note'), |
144 | 176 | }}
|
145 | 177 | />
|
146 | 178 | )
|
|
0 commit comments