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

@@ -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"