fix(contacts-ui): show specific add-by-email errors
Some checks are pending
CI / test (push) Has started running
Some checks are pending
CI / test (push) Has started running
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user