From 5305e5ca18072619256640fb2c8206b1c732a9e2 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 30 May 2025 08:40:55 -0300 Subject: [PATCH] feat: better handle friend code input --- src/locales/en/translation.json | 3 ++- src/locales/pt-BR/translation.json | 3 ++- src/main/constants.ts | 3 ++- .../user-friend-modal-add-friend.tsx | 14 ++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index ee4254e2..91946baf 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -500,7 +500,8 @@ "achievements_unlocked": "Achievements Unlocked", "earned_points": "Earned points", "show_achievements_on_profile": "Show your achievements on your profile", - "show_points_on_profile": "Show your earned points on your profile" + "show_points_on_profile": "Show your earned points on your profile", + "error_adding_friend": "Could not send friend request. Please check friend code" }, "achievement": { "achievement_unlocked": "Achievement unlocked", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 6b9546ec..af650966 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -493,7 +493,8 @@ "achievements_unlocked": "Conquistas desbloqueadas", "earned_points": "Pontos ganhos", "show_achievements_on_profile": "Exiba suas conquistas no perfil", - "show_points_on_profile": "Exiba seus pontos ganhos no perfil" + "show_points_on_profile": "Exiba seus pontos ganhos no perfil", + "error_adding_friend": "Não foi possível enviar o pedido de amizade. Verifique o código de amizade inserido" }, "achievement": { "achievement_unlocked": "Conquista desbloqueada", diff --git a/src/main/constants.ts b/src/main/constants.ts index 16642d50..5625a53e 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -4,7 +4,8 @@ import { SystemPath } from "./services/system-path"; export const defaultDownloadsPath = SystemPath.getPath("downloads"); -export const isStaging = import.meta.env.MAIN_VITE_API_URL.includes("staging"); +export const isStaging = + true || import.meta.env.MAIN_VITE_API_URL.includes("staging"); export const windowsStartMenuPath = path.join( SystemPath.getPath("appData"), diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx index 2bcf5ba7..a597c809 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx @@ -29,11 +29,10 @@ export const UserFriendModalAddFriend = ({ setIsAddingFriend(true); sendFriendRequest(friendCode) .then(() => { - // TODO: add validation for this input? setFriendCode(""); }) .catch(() => { - showErrorToast("Não foi possível enviar o pedido de amizade"); + showErrorToast(t("error_adding_friend")); }) .finally(() => { setIsAddingFriend(false); @@ -46,8 +45,8 @@ export const UserFriendModalAddFriend = ({ }; const handleClickSeeProfile = () => { - closeModal(); if (friendCode.length === 8) { + closeModal(); navigate(`/profile/${friendCode}`); } }; @@ -74,16 +73,19 @@ export const UserFriendModalAddFriend = ({ }); }; + const handleChangeFriendCode = (e: React.ChangeEvent) => { + const friendCode = e.target.value.trim().slice(0, 8); + setFriendCode(friendCode); + }; + return ( <>
setFriendCode(e.target.value)} + onChange={handleChangeFriendCode} />