diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 1f65477..719164d 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -62,6 +62,12 @@ export const addConversationList = (data) => { payload: data, }; }; +export const delConversationitem = (data) => { + return { + type: NAME_SPACE + 'DEL_CONVERSATIONS_ITEM', + payload: data, + }; +}; // export const updateConversationListItemNew = (message) => ({ // type: NAME_SPACE + 'UPDATE_CONVERSATION_LIST_ITEM_NEW', // payload: message, @@ -122,8 +128,8 @@ export const fetchCustomerProfile = async (colisn) => { return data; }; -export const postConversationItemClose = async (body) => { +export const fetchConversationItemClose = async (body) => { const getParams = body ? new URLSearchParams(body).toString() : ''; - const { result } = await postJSON(`${API_HOST}/closeconversation?${getParams}`); + const { result } = await fetchJSON(`${API_HOST}/closeconversation?${getParams}`); return result; }; diff --git a/src/reducers/ConversationReducer.js b/src/reducers/ConversationReducer.js index 9460f68..1917345 100644 --- a/src/reducers/ConversationReducer.js +++ b/src/reducers/ConversationReducer.js @@ -27,6 +27,19 @@ const ConversationReducer = (state = initialState, action) => { activeConversations: { ...activeConversations, ...newConversationsMapped }, }; } + case NAME_SPACE + 'DEL_CONVERSATIONS_ITEM': { + const { conversationsList, activeConversations, currentConversation, customerOrderProfile } = state; + const targetId = action.payload.sn; + const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId)); + conversationsList.splice(targetIndex, 1); + return { + ...state, + conversationsList: [...conversationsList], + activeConversations: { ...activeConversations, [`${targetId}`]: [] }, + currentConversation: {}, + customerOrderProfile: {}, + }; + } case NAME_SPACE + 'SET_TEMPLATE_LIST': return { ...state, templates: action.payload }; @@ -39,10 +52,10 @@ const ConversationReducer = (state = initialState, action) => { const { conversationsList } = state; const targetId = action.payload.sn; const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId)); - conversationsList.splice(targetIndex, 1, { + targetIndex !== -1 ? conversationsList.splice(targetIndex, 1, { ...conversationsList[targetIndex], unread_msg_count: 0, - }); + }) : null; return { ...state, currentConversation: action.payload, conversationsList: [...conversationsList] }; } diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index a28fc4b..27aac42 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -1,19 +1,55 @@ import { useRef, useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; -import { List, Avatar, Flex } from 'antd'; +import { List, Avatar, Flex, Popconfirm, Button, Dropdown } from 'antd'; +import { SendOutlined, MessageOutlined, SmileOutlined, PictureOutlined, CommentOutlined, UploadOutlined, CloudUploadOutlined, FolderAddOutlined, FilePdfOutlined, CloseCircleOutlined, CloseCircleFilled, MoreOutlined } from '@ant-design/icons'; import { useAuthContext } from '@/stores/AuthContext'; import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext'; import { fetchCustomerProfile, receivedCustomerProfile, setCurrentConversation, - addConversationList, - postConversationItemClose, + addConversationList, delConversationitem, + fetchConversationItemClose, fetchMessages, receivedMessageList, } from '@/actions/ConversationActions'; -import { ChatList } from 'react-chat-elements'; +import { ChatList, } from 'react-chat-elements'; import { isEmpty, pick } from '@/utils/utils'; import { v4 as uuid } from 'uuid'; + +const CDropdown = () => { + const { loginUser } = useAuthContext(); + const { userId } = loginUser; + const { currentConversation } = useConversationState(); + const dispatch = useConversationDispatch(); + const handleConversationItemClose = async (item) => { + await fetchConversationItemClose({ conversationid: item.sn, opisn: userId }); + dispatch(delConversationitem(item)); + }; + return ( + { + switch (key) { + case 'close': + return handleConversationItemClose(currentConversation); + + default: + return; + } + }, + }}> +