test: 关闭会话;

dev/chat
Lei OT 2 years ago
parent 3a342331d6
commit 9a3dbf634f

@ -1,5 +1,6 @@
import { groupBy } from '@/utils/utils';
import { fetchJSON, postJSON } from '@/utils/request'
const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_callback';
@ -97,33 +98,8 @@ export const fetchCustomerProfile = async (colisn) => {
return data;
};
export async function fetchJSON(url, data) {
let params = '';
let ifp = '';
if (data) {
params = new URLSearchParams(data).toString();
ifp = params ? '?' : ifp;
}
ifp = url.includes('?') ? '' : ifp;
const host = /^https?:\/\//i.test(url) ? '' : API_HOST;
const response = await fetch(`${host}${url}${ifp}${params}`);
return await response.json();
}
export async function postJSON(url, obj) {
try {
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(obj),
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
return await response.json();
} catch (error) {
console.error('fetch error:', error);
throw error;
}
}
export const postConversationItemClose = async (body) => {
const getParams = body ? new URLSearchParams(body).toString() : '';
const { result } = await postJSON(`${API_HOST}/closeconversation?${getParams}`);
return result;
};

@ -20,13 +20,15 @@ export function fetchText(url) {
})
}
export function fetchJSON(url) {
return fetch(url)
export function fetchJSON(url, data) {
const params = data ? new URLSearchParams(data).toString() : '';
const ifp = url.includes('?') ? '&' : '?';
return fetch(`${url}${ifp}${params}`)
.then(checkStatus)
.then(response => response.json())
.catch(error => {
throw error
})
throw error;
});
}
export function postForm(url, data) {

@ -1,8 +1,9 @@
import { useRef, useEffect, useState } from 'react';
import { useParams, useNavigate } from "react-router-dom";
import { List, Avatar, Flex } from 'antd';
import { useAuthContext } from '@/stores/AuthContext';
import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext';
import { fetchCustomerProfile, receivedCustomerProfile, setCurrentConversation, addConversationList, setActiveConversations } from '@/actions/ConversationActions'
import { fetchCustomerProfile, receivedCustomerProfile, setCurrentConversation, addConversationList, setActiveConversations, postConversationItemClose } from '@/actions/ConversationActions'
import { ChatList } from 'react-chat-elements';
import { isEmpty, pick } from '@/utils/utils';
import { v4 as uuid } from 'uuid';
@ -12,6 +13,8 @@ import { v4 as uuid } from 'uuid';
const Conversations = (() => {
const { order_sn } = useParams();
const navigate = useNavigate();
const { loginUser } = useAuthContext();
const { userId } = loginUser;
const {conversationsList} = useConversationState();
const dispatch = useConversationDispatch();
const [chatlist, setChatlist] = useState([]);
@ -93,7 +96,10 @@ const Conversations = (() => {
}
}
const onCloseConversationItem = (item) => { }
const handleConversationItemClose = async (item) => {
console.log('invoke close', item);
const data = await postConversationItemClose({ conversationid: item.sn, opisn: userId });
}
return (
<>
@ -102,7 +108,7 @@ const Conversations = (() => {
// console.log(item, i, e);
// return ( <p>ppp</p> )
// }}
onClickMute={onCloseConversationItem}
onClickMute={handleConversationItemClose}
/>
</>
);

Loading…
Cancel
Save