-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-js,localizations,types): Add min and max lengths to usernam…
…e field error (#4771)
- Loading branch information
1 parent
5c5f1db
commit aeafa7c
Showing
8 changed files
with
64 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/localizations': patch | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Added min and max length username settings to username field error. |
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,26 @@ | ||
import type { ClerkAPIError, UsernameSettingsData } from '@clerk/types'; | ||
|
||
import { type LocalizationKey, localizationKeys } from '../localization'; | ||
|
||
type LocalizationConfigProps = { | ||
t: (localizationKey: LocalizationKey | string | undefined) => string; | ||
locale: string; | ||
usernameSettings: Pick<UsernameSettingsData, 'max_length' | 'min_length'>; | ||
}; | ||
|
||
export const createUsernameError = (errors: ClerkAPIError[], localizationConfig: LocalizationConfigProps) => { | ||
const { t, usernameSettings } = localizationConfig; | ||
|
||
if (!localizationConfig) { | ||
return errors[0].longMessage; | ||
} | ||
|
||
const msg = t( | ||
localizationKeys('unstable__errors.form_username_invalid_length', { | ||
min_length: usernameSettings.min_length, | ||
max_length: usernameSettings.max_length, | ||
}), | ||
); | ||
|
||
return msg; | ||
}; |
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