@universe-platform/ui 0.1.0-beta.27 → 0.1.0-beta.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -13689,8 +13689,8 @@ function useInboxState(orgId, actions) {
13689
13689
  setError(res.error);
13690
13690
  }
13691
13691
  }, [orgId]);
13692
- const fetchMessages = (0, import_react21.useCallback)(async (conversationId) => {
13693
- setIsLoading(true);
13692
+ const fetchMessages = (0, import_react21.useCallback)(async (conversationId, silent = false) => {
13693
+ if (!silent) setIsLoading(true);
13694
13694
  const res = await actionsRef.current.getMessages(conversationId);
13695
13695
  if (res.success && res.data) {
13696
13696
  setMessages(res.data);
@@ -13700,14 +13700,14 @@ function useInboxState(orgId, actions) {
13700
13700
  } else if (res.error) {
13701
13701
  setError(res.error);
13702
13702
  }
13703
- setIsLoading(false);
13703
+ if (!silent) setIsLoading(false);
13704
13704
  }, []);
13705
13705
  (0, import_react21.useEffect)(() => {
13706
13706
  fetchConversations();
13707
13707
  const interval = setInterval(() => {
13708
13708
  fetchConversations();
13709
13709
  if (activeConversationId) {
13710
- fetchMessages(activeConversationId);
13710
+ fetchMessages(activeConversationId, true);
13711
13711
  }
13712
13712
  }, 5e3);
13713
13713
  return () => clearInterval(interval);
@@ -13726,7 +13726,7 @@ function useInboxState(orgId, actions) {
13726
13726
  status: "SENDING",
13727
13727
  createdAt: /* @__PURE__ */ new Date()
13728
13728
  };
13729
- setMessages((prev) => [...prev, tempMsg]);
13729
+ setMessages((prev) => [tempMsg, ...prev]);
13730
13730
  const res = await actions.sendMessage(activeConversationId, text, orgId);
13731
13731
  if (res.success && res.data) {
13732
13732
  setMessages((prev) => prev.map((m) => m.id === tempMsg.id ? res.data : m));
@@ -13806,14 +13806,14 @@ var import_lucide_react15 = require("lucide-react");
13806
13806
  var import_jsx_runtime21 = require("react/jsx-runtime");
13807
13807
  function ChatWindow({ activeConversation, messages, isLoading, isSending, onSendMessage }) {
13808
13808
  const [inputText, setInputText] = (0, import_react22.useState)("");
13809
- const messagesEndRef = (0, import_react22.useRef)(null);
13810
- const scrollToBottom = () => {
13809
+ const messagesTopRef = (0, import_react22.useRef)(null);
13810
+ const scrollToTop = () => {
13811
13811
  var _a;
13812
- (_a = messagesEndRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
13812
+ (_a = messagesTopRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
13813
13813
  };
13814
13814
  (0, import_react22.useEffect)(() => {
13815
- scrollToBottom();
13816
- }, [messages]);
13815
+ scrollToTop();
13816
+ }, [messages.length, activeConversation == null ? void 0 : activeConversation.id]);
13817
13817
  const handleSend = (e) => {
13818
13818
  e.preventDefault();
13819
13819
  if (!inputText.trim() || isSending) return;
@@ -13835,17 +13835,17 @@ function ChatWindow({ activeConversation, messages, isLoading, isSending, onSend
13835
13835
  ] })
13836
13836
  ] }),
13837
13837
  /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex-1 overflow-y-auto p-6 space-y-4", children: [
13838
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { ref: messagesTopRef }),
13838
13839
  isLoading ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex justify-center py-10", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_lucide_react15.Loader2, { className: "w-6 h-6 animate-spin text-emerald-600" }) }) : messages.map((msg, idx) => {
13839
13840
  const isOutbound = msg.direction === "OUTBOUND";
13840
13841
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: `flex ${isOutbound ? "justify-start" : "justify-end"}`, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: `max-w-[70%] rounded-2xl px-4 py-2 shadow-sm relative ${isOutbound ? "bg-[#d9fdd3] text-slate-900 rounded-tr-none" : "bg-white text-slate-900 rounded-tl-none"}`, children: [
13841
13842
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "text-sm whitespace-pre-wrap", children: msg.content }),
13842
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "text-[10px] text-slate-400 mt-1 text-left flex items-center justify-end gap-1", children: [
13843
- new Date(msg.createdAt).toLocaleTimeString("he-IL", { hour: "2-digit", minute: "2-digit" }),
13844
- isOutbound && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: msg.status === "READ" || msg.status === "DELIVERED" ? "text-blue-500" : "text-slate-400", children: msg.status === "READ" ? "\u2713\u2713" : msg.status === "DELIVERED" ? "\u2713\u2713" : "\u2713" })
13843
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "text-[11px] text-slate-600 mt-1 text-left flex items-center justify-end gap-1", children: [
13844
+ new Date(msg.createdAt).toLocaleString("he-IL", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit" }),
13845
+ isOutbound && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: msg.status === "READ" || msg.status === "DELIVERED" ? "text-blue-500" : "text-slate-500", children: msg.status === "READ" ? "\u2713\u2713" : msg.status === "DELIVERED" ? "\u2713\u2713" : "\u2713" })
13845
13846
  ] })
13846
13847
  ] }) }, msg.id || idx);
13847
- }),
13848
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { ref: messagesEndRef })
13848
+ })
13849
13849
  ] }),
13850
13850
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "bg-slate-50 p-4 border-t border-slate-200 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("form", { onSubmit: handleSend, className: "flex items-end gap-2 max-w-4xl mx-auto", children: [
13851
13851
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex-1 bg-white border border-slate-300 rounded-2xl overflow-hidden focus-within:border-emerald-500 focus-within:ring-1 focus-within:ring-emerald-500", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
@@ -13981,12 +13981,17 @@ function WhatsAppComponent(props) {
13981
13981
  }
13982
13982
  },
13983
13983
  sendInboxMessageAction: async (convId, text, currentOrgId) => {
13984
- const res = await fetch(`/api/whatsapp/inbox/send`, {
13985
- method: "POST",
13986
- headers: { "Content-Type": "application/json" },
13987
- body: JSON.stringify({ conversationId: convId, text, orgId: currentOrgId })
13988
- });
13989
- return res.json();
13984
+ if (!executeAction) return { success: false, error: "executeAction missing" };
13985
+ try {
13986
+ const data = await executeAction("SEND_WHATSAPP_INBOX_MESSAGE", {
13987
+ conversationId: convId,
13988
+ text,
13989
+ orgId: currentOrgId
13990
+ });
13991
+ return { success: true, data };
13992
+ } catch (e) {
13993
+ return { success: false, error: (e == null ? void 0 : e.message) || "\u05E9\u05D2\u05D9\u05D0\u05D4 \u05D1\u05E9\u05DC\u05D9\u05D7\u05EA \u05D4\u05D5\u05D3\u05E2\u05D4" };
13994
+ }
13990
13995
  }
13991
13996
  }
13992
13997
  ) }) : /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
package/dist/index.mjs CHANGED
@@ -13624,8 +13624,8 @@ function useInboxState(orgId, actions) {
13624
13624
  setError(res.error);
13625
13625
  }
13626
13626
  }, [orgId]);
13627
- const fetchMessages = useCallback14(async (conversationId) => {
13628
- setIsLoading(true);
13627
+ const fetchMessages = useCallback14(async (conversationId, silent = false) => {
13628
+ if (!silent) setIsLoading(true);
13629
13629
  const res = await actionsRef.current.getMessages(conversationId);
13630
13630
  if (res.success && res.data) {
13631
13631
  setMessages(res.data);
@@ -13635,14 +13635,14 @@ function useInboxState(orgId, actions) {
13635
13635
  } else if (res.error) {
13636
13636
  setError(res.error);
13637
13637
  }
13638
- setIsLoading(false);
13638
+ if (!silent) setIsLoading(false);
13639
13639
  }, []);
13640
13640
  useEffect15(() => {
13641
13641
  fetchConversations();
13642
13642
  const interval = setInterval(() => {
13643
13643
  fetchConversations();
13644
13644
  if (activeConversationId) {
13645
- fetchMessages(activeConversationId);
13645
+ fetchMessages(activeConversationId, true);
13646
13646
  }
13647
13647
  }, 5e3);
13648
13648
  return () => clearInterval(interval);
@@ -13661,7 +13661,7 @@ function useInboxState(orgId, actions) {
13661
13661
  status: "SENDING",
13662
13662
  createdAt: /* @__PURE__ */ new Date()
13663
13663
  };
13664
- setMessages((prev) => [...prev, tempMsg]);
13664
+ setMessages((prev) => [tempMsg, ...prev]);
13665
13665
  const res = await actions.sendMessage(activeConversationId, text, orgId);
13666
13666
  if (res.success && res.data) {
13667
13667
  setMessages((prev) => prev.map((m) => m.id === tempMsg.id ? res.data : m));
@@ -13741,14 +13741,14 @@ import { Send as Send2, User as User2, Loader2 as Loader27 } from "lucide-react"
13741
13741
  import { jsx as jsx21, jsxs as jsxs20 } from "react/jsx-runtime";
13742
13742
  function ChatWindow({ activeConversation, messages, isLoading, isSending, onSendMessage }) {
13743
13743
  const [inputText, setInputText] = useState18("");
13744
- const messagesEndRef = useRef16(null);
13745
- const scrollToBottom = () => {
13744
+ const messagesTopRef = useRef16(null);
13745
+ const scrollToTop = () => {
13746
13746
  var _a;
13747
- (_a = messagesEndRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
13747
+ (_a = messagesTopRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
13748
13748
  };
13749
13749
  useEffect16(() => {
13750
- scrollToBottom();
13751
- }, [messages]);
13750
+ scrollToTop();
13751
+ }, [messages.length, activeConversation == null ? void 0 : activeConversation.id]);
13752
13752
  const handleSend = (e) => {
13753
13753
  e.preventDefault();
13754
13754
  if (!inputText.trim() || isSending) return;
@@ -13770,17 +13770,17 @@ function ChatWindow({ activeConversation, messages, isLoading, isSending, onSend
13770
13770
  ] })
13771
13771
  ] }),
13772
13772
  /* @__PURE__ */ jsxs20("div", { className: "flex-1 overflow-y-auto p-6 space-y-4", children: [
13773
+ /* @__PURE__ */ jsx21("div", { ref: messagesTopRef }),
13773
13774
  isLoading ? /* @__PURE__ */ jsx21("div", { className: "flex justify-center py-10", children: /* @__PURE__ */ jsx21(Loader27, { className: "w-6 h-6 animate-spin text-emerald-600" }) }) : messages.map((msg, idx) => {
13774
13775
  const isOutbound = msg.direction === "OUTBOUND";
13775
13776
  return /* @__PURE__ */ jsx21("div", { className: `flex ${isOutbound ? "justify-start" : "justify-end"}`, children: /* @__PURE__ */ jsxs20("div", { className: `max-w-[70%] rounded-2xl px-4 py-2 shadow-sm relative ${isOutbound ? "bg-[#d9fdd3] text-slate-900 rounded-tr-none" : "bg-white text-slate-900 rounded-tl-none"}`, children: [
13776
13777
  /* @__PURE__ */ jsx21("p", { className: "text-sm whitespace-pre-wrap", children: msg.content }),
13777
- /* @__PURE__ */ jsxs20("div", { className: "text-[10px] text-slate-400 mt-1 text-left flex items-center justify-end gap-1", children: [
13778
- new Date(msg.createdAt).toLocaleTimeString("he-IL", { hour: "2-digit", minute: "2-digit" }),
13779
- isOutbound && /* @__PURE__ */ jsx21("span", { className: msg.status === "READ" || msg.status === "DELIVERED" ? "text-blue-500" : "text-slate-400", children: msg.status === "READ" ? "\u2713\u2713" : msg.status === "DELIVERED" ? "\u2713\u2713" : "\u2713" })
13778
+ /* @__PURE__ */ jsxs20("div", { className: "text-[11px] text-slate-600 mt-1 text-left flex items-center justify-end gap-1", children: [
13779
+ new Date(msg.createdAt).toLocaleString("he-IL", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit" }),
13780
+ isOutbound && /* @__PURE__ */ jsx21("span", { className: msg.status === "READ" || msg.status === "DELIVERED" ? "text-blue-500" : "text-slate-500", children: msg.status === "READ" ? "\u2713\u2713" : msg.status === "DELIVERED" ? "\u2713\u2713" : "\u2713" })
13780
13781
  ] })
13781
13782
  ] }) }, msg.id || idx);
13782
- }),
13783
- /* @__PURE__ */ jsx21("div", { ref: messagesEndRef })
13783
+ })
13784
13784
  ] }),
13785
13785
  /* @__PURE__ */ jsx21("div", { className: "bg-slate-50 p-4 border-t border-slate-200 shrink-0", children: /* @__PURE__ */ jsxs20("form", { onSubmit: handleSend, className: "flex items-end gap-2 max-w-4xl mx-auto", children: [
13786
13786
  /* @__PURE__ */ jsx21("div", { className: "flex-1 bg-white border border-slate-300 rounded-2xl overflow-hidden focus-within:border-emerald-500 focus-within:ring-1 focus-within:ring-emerald-500", children: /* @__PURE__ */ jsx21(
@@ -13916,12 +13916,17 @@ function WhatsAppComponent(props) {
13916
13916
  }
13917
13917
  },
13918
13918
  sendInboxMessageAction: async (convId, text, currentOrgId) => {
13919
- const res = await fetch(`/api/whatsapp/inbox/send`, {
13920
- method: "POST",
13921
- headers: { "Content-Type": "application/json" },
13922
- body: JSON.stringify({ conversationId: convId, text, orgId: currentOrgId })
13923
- });
13924
- return res.json();
13919
+ if (!executeAction) return { success: false, error: "executeAction missing" };
13920
+ try {
13921
+ const data = await executeAction("SEND_WHATSAPP_INBOX_MESSAGE", {
13922
+ conversationId: convId,
13923
+ text,
13924
+ orgId: currentOrgId
13925
+ });
13926
+ return { success: true, data };
13927
+ } catch (e) {
13928
+ return { success: false, error: (e == null ? void 0 : e.message) || "\u05E9\u05D2\u05D9\u05D0\u05D4 \u05D1\u05E9\u05DC\u05D9\u05D7\u05EA \u05D4\u05D5\u05D3\u05E2\u05D4" };
13929
+ }
13925
13930
  }
13926
13931
  }
13927
13932
  ) }) : /* @__PURE__ */ jsxs22(Fragment8, { children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@universe-platform/ui",
3
- "version": "0.1.0-beta.27",
3
+ "version": "0.1.0-beta.29",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",