Skip to content

Commit

Permalink
refactor(profile): notify that fields are too long before making a re…
Browse files Browse the repository at this point in the history
…quest to the server (sanidhyas3s) (#4694)

* impr: check profile length before sending to server

Length checks for GitHub and Twitter are now made before
sending server requests. Notification for the same is
displayed to the user.

Closes #4653

* the tiniest of nitpicks

---------

Co-authored-by: Miodec <[email protected]>
  • Loading branch information
sanidhyas3s and Miodec authored Oct 3, 2023
1 parent 84327f9 commit 82a24e4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend/src/ts/popups/edit-profile-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,31 @@ async function updateProfile(): Promise<void> {
if (!snapshot) return;
const updates = buildUpdatesFromInputs();

// check for length resctrictions before sending server requests
const githubLengthLimit = 39;
if (
updates.socialProfiles.github &&
updates.socialProfiles.github.length > githubLengthLimit
) {
Notifications.add(
`GitHub username exceeds maximum allowed length (${githubLengthLimit} characters).`,
-1
);
return;
}

const twitterLengthLimit = 20;
if (
updates.socialProfiles.twitter &&
updates.socialProfiles.twitter.length > twitterLengthLimit
) {
Notifications.add(
`Twitter username exceeds maximum allowed length (${twitterLengthLimit} characters).`,
-1
);
return;
}

Loader.show();
const response = await Ape.users.updateProfile(
updates,
Expand Down

0 comments on commit 82a24e4

Please sign in to comment.