Skip to content

Commit

Permalink
make change handle screen generic
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius committed Jan 10, 2025
1 parent 672c7e6 commit 02cc95a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/lib/strings/handles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface IsValidHandle {
export function validateHandle(
str: string,
userDomain: string,
serviceHandle?: boolean,
isServiceHandle?: boolean,
): IsValidHandle {
const fullHandle = createFullHandle(str, userDomain)

Expand All @@ -54,7 +54,7 @@ export function validateHandle(
!str || (VALIDATE_REGEX.test(fullHandle) && !str.includes('.')),
hyphenStartOrEnd: !str.startsWith('-') && !str.endsWith('-'),
frontLength: str.length >= 3,
totalLength: fullHandle.length <= (serviceHandle ? 30 : 253),
totalLength: fullHandle.length <= (isServiceHandle ? 30 : 253),
}

return {
Expand Down
10 changes: 4 additions & 6 deletions src/screens/Settings/components/ChangeHandleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,11 @@ function ProvidedHandlePage({
const host = serviceInfo.availableUserDomains[0]

const validation = useMemo(
() => validateHandle(subdomain, host),
() => validateHandle(subdomain, host, true),
[subdomain, host],
)

const isTooLong = subdomain.length > 18
const isInvalid =
isTooLong ||
!validation.handleChars ||
!validation.hyphenStartOrEnd ||
!validation.totalLength
Expand Down Expand Up @@ -231,10 +229,10 @@ function ProvidedHandlePage({
label={_(msg`Save new handle`)}
variant="solid"
size="large"
color={validation.overall && !isTooLong ? 'primary' : 'secondary'}
disabled={!validation.overall && !isTooLong}
color={validation.overall ? 'primary' : 'secondary'}
disabled={!validation.overall}
onPress={() => {
if (validation.overall && !isTooLong) {
if (validation.overall) {
changeHandle({handle: createFullHandle(subdomain, host)})
}
}}>
Expand Down

0 comments on commit 02cc95a

Please sign in to comment.