fix: make support replies finish promptly

This commit is contained in:
3252a8
2026-05-27 22:21:24 +03:00
parent bce78c4f28
commit ded044b4c0
4 changed files with 55 additions and 26 deletions
@@ -93,7 +93,8 @@
});
async function send(body) {
await supportStore.sendReply(body);
const sent = await supportStore.sendReply(body);
if (!sent) return;
reply = "";
}
+18 -9
View File
@@ -193,17 +193,26 @@ export function createAdminSupportStore({ api, onToast, at }) {
body: JSON.stringify({ body, is_internal_note: internal }),
});
if (!res?.ok) throw res;
state.update((s) => ({
...s,
openedTicket: res.ticket
? { ...s.openedTicket, ...res.ticket, user: res.ticket.user || s.openedTicket?.user }
: s.openedTicket,
messages: [...s.messages, res.message],
}));
await loadList();
await loadStats();
state.update((s) =>
s.openedTicketId === current
? {
...s,
openedTicket: res.ticket
? {
...s.openedTicket,
...res.ticket,
user: res.ticket.user || s.openedTicket?.user,
}
: s.openedTicket,
messages: res.message ? [...s.messages, res.message] : s.messages,
}
: s
);
void Promise.allSettled([loadList({ silent: true }), loadStats()]);
return true;
} catch (error) {
onToast(error?.message || at("support_send_failed", {}, "Send failed"));
return false;
} finally {
state.update((s) => ({ ...s, sending: false }));
}
+13 -7
View File
@@ -258,13 +258,19 @@ export function createSupportStore({ api, t, showToast }) {
body: JSON.stringify({ body }),
});
if (!res?.ok) throw res;
state.update((s) => ({
...s,
openedTicket: res.ticket || s.openedTicket,
messages: [...s.messages, res.message],
}));
await refreshUnread();
await loadList({ silent: true, force: true });
state.update((s) =>
s.openedTicketId === ticketId
? {
...s,
openedTicket: res.ticket || s.openedTicket,
messages: res.message ? [...s.messages, res.message] : s.messages,
}
: s
);
void Promise.allSettled([
refreshUnread({ silent: true }),
loadList({ silent: true, force: true }),
]);
return true;
} catch (error) {
showToast(error?.message || t("wa_support_send_failed"));