MCPcopy Create free account
hub / github.com/dailydotdev/apps / onValidateHandles

Function onValidateHandles

packages/shared/src/hooks/useProfileForm.ts:44–67  ·  view source on GitHub ↗
(
  before: Partial<Handles>,
  after: Partial<Handles>,
)

Source from the content-addressed store, hash-verified

42 username.replace('@', '').trim();
43
44export 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

Callers 2

onSubmitFunction · 0.90

Calls 1

normalizeUsernameFunction · 0.85

Tested by

no test coverage detected