From 209a79bbcf6d8a820025da7b6472a9d595af4114 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 9 Apr 2024 11:38:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=81=E7=A7=BB=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/commons.js | 2 +- src/views/Conversations/History/MessagesList.jsx | 4 ++-- src/views/Conversations/Online/MessagesList.jsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/commons.js b/src/utils/commons.js index c6d548d..10ceb56 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -169,7 +169,7 @@ export function merge(...objects) { * - 相当于 lodash 的 _.groupBy * @see https://www.lodashjs.com/docs/lodash.groupBy#_groupbycollection-iteratee_identity */ -export function groupBy(array, callback) { +export function groupBy(array = [], callback) { return array.reduce((groups, item) => { const key = typeof callback === 'function' ? callback(item) : item[callback]; diff --git a/src/views/Conversations/History/MessagesList.jsx b/src/views/Conversations/History/MessagesList.jsx index 1d95413..97288d5 100644 --- a/src/views/Conversations/History/MessagesList.jsx +++ b/src/views/Conversations/History/MessagesList.jsx @@ -4,7 +4,7 @@ import { LoadingOutlined } from '@ant-design/icons'; import { MessageBox } from 'react-chat-elements'; import { MESSAGE_PAGE_SIZE, fetchMessagesHistory } from '@/actions/ConversationActions'; import useFormStore from '@/stores/FormStore'; -import { isEmpty, stringToColour, groupBy } from '@/utils/commons'; +import { isEmpty, stringToColour, groupBy, isNotEmpty } from '@/utils/commons'; import { useShallow } from 'zustand/react/shallow'; const BIG_PAGE_SIZE = MESSAGE_PAGE_SIZE * 100; @@ -134,7 +134,7 @@ const MessagesList = ({ ...props }) => { const RenderText = memo(function renderText({ str, className, template }) { let headerObj, footerObj, buttonsArr; - if (!isEmpty(template)) { + if (!isEmpty(template) && !isEmpty(template.components)) { const componentsObj = groupBy(template.components, (item) => item.type); headerObj = componentsObj?.header?.[0]; footerObj = componentsObj?.footer?.[0]; diff --git a/src/views/Conversations/Online/MessagesList.jsx b/src/views/Conversations/Online/MessagesList.jsx index 16fdddb..61ddefc 100644 --- a/src/views/Conversations/Online/MessagesList.jsx +++ b/src/views/Conversations/Online/MessagesList.jsx @@ -43,7 +43,7 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get const RenderText = memo(function renderText({ str, className, template }) { let headerObj, footerObj, buttonsArr; - if (!isEmpty(template)) { + if (!isEmpty(template) && !isEmpty(template.components)) { const componentsObj = groupBy(template.components, (item) => item.type); headerObj = componentsObj?.header?.[0]; footerObj = componentsObj?.footer?.[0];