-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a66103d
commit ba4b330
Showing
3 changed files
with
31 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ProfileFormValidationErrors, ProfileFormValues } from './ProfilePage.types' | ||
import { useCallback } from 'react' | ||
import { t } from '../../utils/i18n' | ||
import { stringLengthInRange } from '../../utils/stringLengthInRange' | ||
|
||
const USERNAME_MIN_LENGTH = 2 | ||
const USERNAME_MAX_LENGTH = 20 | ||
|
||
export const useProfileValidation = () => | ||
useCallback((values: ProfileFormValues): ProfileFormValidationErrors => { | ||
const errors: ProfileFormValidationErrors = {} | ||
const isValidUsername = stringLengthInRange(values.username, { minLength: USERNAME_MIN_LENGTH, maxLength: USERNAME_MAX_LENGTH }) | ||
|
||
if (values.username && !isValidUsername) { | ||
errors.username = t.validation.username(USERNAME_MIN_LENGTH, USERNAME_MAX_LENGTH) | ||
} | ||
|
||
return errors | ||
}, []) |
ba4b330
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report for
apps/ligretto-gameplay-backend
Test suite run success
12 tests passing in 1 suite.
Report generated by 🧪jest coverage report action from ba4b330