fix handle length error message (#7802)
This commit is contained in:
@@ -5,6 +5,8 @@ import {forceLTR} from '#/lib/strings/bidi'
|
|||||||
const VALIDATE_REGEX =
|
const VALIDATE_REGEX =
|
||||||
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/
|
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/
|
||||||
|
|
||||||
|
export const MAX_SERVICE_HANDLE_LENGTH = 18
|
||||||
|
|
||||||
export function makeValidHandle(str: string): string {
|
export function makeValidHandle(str: string): string {
|
||||||
if (str.length > 20) {
|
if (str.length > 20) {
|
||||||
str = str.slice(0, 20)
|
str = str.slice(0, 20)
|
||||||
@@ -19,10 +21,6 @@ export function createFullHandle(name: string, domain: string): string {
|
|||||||
return `${name}.${domain}`
|
return `${name}.${domain}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function maxServiceHandleLength(domain: string): number {
|
|
||||||
return 30 - `.${(domain || '').replace(/^[.]+/, '')}`.length
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isInvalidHandle(handle: string): boolean {
|
export function isInvalidHandle(handle: string): boolean {
|
||||||
return handle === 'handle.invalid'
|
return handle === 'handle.invalid'
|
||||||
}
|
}
|
||||||
@@ -52,7 +50,7 @@ export function validateServiceHandle(
|
|||||||
handleChars:
|
handleChars:
|
||||||
!str || (VALIDATE_REGEX.test(fullHandle) && !str.includes('.')),
|
!str || (VALIDATE_REGEX.test(fullHandle) && !str.includes('.')),
|
||||||
hyphenStartOrEnd: !str.startsWith('-') && !str.endsWith('-'),
|
hyphenStartOrEnd: !str.startsWith('-') && !str.endsWith('-'),
|
||||||
frontLength: str.length >= 3 && str.length <= 18,
|
frontLength: str.length >= 3 && str.length <= MAX_SERVICE_HANDLE_LENGTH,
|
||||||
totalLength: fullHandle.length <= 253,
|
totalLength: fullHandle.length <= 253,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {
|
import {
|
||||||
createFullHandle,
|
createFullHandle,
|
||||||
maxServiceHandleLength,
|
MAX_SERVICE_HANDLE_LENGTH,
|
||||||
validateServiceHandle,
|
validateServiceHandle,
|
||||||
} from '#/lib/strings/handles'
|
} from '#/lib/strings/handles'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
@@ -168,11 +168,11 @@ export function StepHandle() {
|
|||||||
<IsValidIcon
|
<IsValidIcon
|
||||||
valid={validCheck.frontLength && validCheck.totalLength}
|
valid={validCheck.frontLength && validCheck.totalLength}
|
||||||
/>
|
/>
|
||||||
{!validCheck.totalLength ? (
|
{!validCheck.totalLength ||
|
||||||
|
draftValue.length > MAX_SERVICE_HANDLE_LENGTH ? (
|
||||||
<Text style={[a.text_md, a.flex_1]}>
|
<Text style={[a.text_md, a.flex_1]}>
|
||||||
<Trans>
|
<Trans>
|
||||||
No longer than {maxServiceHandleLength(state.userDomain)}{' '}
|
No longer than {MAX_SERVICE_HANDLE_LENGTH} characters
|
||||||
characters
|
|
||||||
</Trans>
|
</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user