( before: Partial<Handles>, after: Partial<Handles>, )
| 42 | username.replace('@', '').trim(); |
| 43 | |
| 44 | export const onValidateHandles = ( |
| 45 | before: Partial<Handles>, |
| 46 | after: Partial<Handles>, |
| 47 | ): Partial<Record<keyof Handles, string>> => { |
| 48 | if (after.username && after.username !== before.username) { |
| 49 | const normalizedUsername = normalizeUsername(after.username); |
| 50 | |
| 51 | if ( |
| 52 | normalizedUsername.length < minUsernameLength || |
| 53 | normalizedUsername.length > maxUsernameLength |
| 54 | ) { |
| 55 | return { username: errorMessage.profile.usernameLength }; |
| 56 | } |
| 57 | const isValid = handleRegex.test(normalizedUsername); |
| 58 | |
| 59 | if (!isValid) { |
| 60 | return { username: errorMessage.profile.invalidUsername }; |
| 61 | } |
| 62 | } else if ('username' in after && !after.username) { |
| 63 | return { username: errorMessage.profile.usernameRequired }; |
| 64 | } |
| 65 | |
| 66 | return {}; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * @deprecated Use useUserInfoForm instead |
no test coverage detected