fix(contacts-ui): show specific add-by-email errors
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-03-08 20:36:38 +03:00
parent 42596fba16
commit 6c039ae94f
2 changed files with 16 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ Legend:
1. Account - `PARTIAL` (email auth, JWT, refresh, logout, reset; sessions exist, full UX still improving)
2. User Profile - `DONE` (username, name, avatar, bio, update)
3. User Status - `PARTIAL` (online/last seen/offline; web now formats `just now/today/yesterday/recently`, backend-side presence heuristics still limited)
4. Contacts - `PARTIAL` (list/search/add/remove/block/unblock; `add by email` flow covered by integration tests including `success/not found/blocked conflict`; UX moved to menu)
4. Contacts - `PARTIAL` (list/search/add/remove/block/unblock; `add by email` flow covered by integration tests including `success/not found/blocked conflict`; web now surfaces specific add-by-email errors (`not found` vs `blocked`); UX moved to menu)
5. Chat List - `DONE` (all/pinned/archive/sort/unread; saved-messages delete behavior covered: clear history without deleting chat)
6. Chat Types - `DONE` (private/group/channel)
7. Chat Creation - `DONE` (private/group/channel)

View File

@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import axios from "axios";
import { archiveChat, clearChat, createPrivateChat, deleteChat, getChats, getSavedMessagesChat, joinChat, leaveChat, pinChat, unarchiveChat, unpinChat } from "../api/chats";
import { globalSearch } from "../api/search";
import type { DiscoverChat, Message, UserSearchItem } from "../chat/types";
@@ -526,8 +527,20 @@ export function ChatList() {
await addContactByEmail(email);
setContactEmail("");
setContacts(await listContacts());
} catch {
setContactEmailError("User with this email not found");
setContactEmailError(null);
} catch (error) {
if (axios.isAxiosError(error)) {
const status = error.response?.status;
if (status === 404) {
setContactEmailError("User with this email not found");
return;
}
if (status === 409) {
setContactEmailError("Cannot add contact while blocked");
return;
}
}
setContactEmailError("Failed to add contact");
}
}}
type="button"