From d3d325b7f03caf90c0d86234998d5f40b93d61dd Mon Sep 17 00:00:00 2001 From: Shahrukh khan <59122336+shahrukh802@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:52:49 +0500 Subject: [PATCH] [PAN-820]: archive api integrated on frontend (#1210) * archive conversation api added * archive conversation integrated on frontend --- client/Providers/AppProvider.tsx | 2 + .../LayoutComponents/ConversationItem.tsx | 6 +- client/hooks/useConversations.tsx | 14 +-- client/services/chat.ts | 94 ------------------- client/services/conversations.ts | 12 ++- 5 files changed, 18 insertions(+), 110 deletions(-) diff --git a/client/Providers/AppProvider.tsx b/client/Providers/AppProvider.tsx index ccf1a7a8f..9d32f888c 100644 --- a/client/Providers/AppProvider.tsx +++ b/client/Providers/AppProvider.tsx @@ -13,6 +13,7 @@ import mixpanel from "mixpanel-browser"; import { Provider as RollbarProvider, ErrorBoundary } from "@rollbar/react"; import QueryProvider from "./QueryProvider"; import Intercom from "@/components/Intercom/Intercom"; +import { ToastContainer } from "react-toastify"; import "styles/globals.css"; import "styles/App.css"; import "styles/multi-range-slider.css"; @@ -49,6 +50,7 @@ export default function AppProvider({ children }: { children: ReactNode }) { + {children} diff --git a/client/components/LayoutComponents/ConversationItem.tsx b/client/components/LayoutComponents/ConversationItem.tsx index 4bca3e2ce..e9836cd10 100644 --- a/client/components/LayoutComponents/ConversationItem.tsx +++ b/client/components/LayoutComponents/ConversationItem.tsx @@ -1,5 +1,4 @@ "use client"; -import { ArchiveConversationApi } from "services/chat"; import { FETCH_CONVERSATION, useConversationsContext, @@ -12,7 +11,10 @@ import { useAppStore } from "store"; import { isToday, isYesterday, startOfWeek, isWithinInterval } from "date-fns"; import { ConversationsHistoryLoader } from "components/Skeletons"; import ConfirmationDialog from "components/ConfirmationDialog"; -import { GetConversations } from "@/services/conversations"; +import { + ArchiveConversationApi, + GetConversations, +} from "@/services/conversations"; interface IProps { collapsed: boolean; diff --git a/client/hooks/useConversations.tsx b/client/hooks/useConversations.tsx index 3b240b3df..44c18016e 100644 --- a/client/hooks/useConversations.tsx +++ b/client/hooks/useConversations.tsx @@ -1,17 +1,5 @@ import { useQuery } from "@tanstack/react-query"; -import { - ConversationChatBySpaceApi, - ExplainConversationMessage, - GetChatLabel, -} from "@/services/chat"; - -export const useGetConversations = (spaceId, page, rowsPerPage) => { - const { data, isLoading, error, isError, refetch, isFetching } = useQuery({ - queryKey: ["ConversationChatApi"], - queryFn: () => ConversationChatBySpaceApi(spaceId, page, rowsPerPage), - }); - return { data, isLoading, error, isError, refetch, isFetching }; -}; +import { ExplainConversationMessage, GetChatLabel } from "@/services/chat"; export const useGetChatLabel = (chatId: string) => { const { data, isLoading, error, isError } = useQuery({ diff --git a/client/services/chat.ts b/client/services/chat.ts index 1cedf268c..38f9013ea 100644 --- a/client/services/chat.ts +++ b/client/services/chat.ts @@ -12,27 +12,6 @@ export const ChatApi = async (chatdata) => { throw error; } }; -export const ChatReactionApi = async (id, chatdata) => { - const apiUrl = `${chatApiUrl}/conversation-message/${id}/user-rating`; - try { - const response = await PostRequest(apiUrl, chatdata); - return response; - } catch (error) { - console.error('Get request failed', error); - throw error; - } -}; - -export const ChatMessageRetry = async (messageId: string) => { - const apiUrl = `${chatApiUrl}/conversation-message/${messageId}/retry-code`; - try { - const response = await GetRequest(apiUrl); - return response; - } catch (error) { - console.error('Get request failed', error); - throw error; - } -}; export const FetchDataframe = async (id: number | string) => { const apiUrl = `${chatApiUrl}/conversation-message-dataframe/${id}`; @@ -44,48 +23,7 @@ export const FetchDataframe = async (id: number | string) => { throw error; } }; -export const AddPartialDF = async (conversationId: string, body) => { - const apiUrl = `${chatApiUrl}/conversation-message/${conversationId}/partial-df`; - try { - const response = await PostRequest(apiUrl, body); - return response; - } catch (error) { - console.error("Get request failed", error); - throw error; - } -}; - -export const ConversationChatApi = async (page, rowsPerPage) => { - const apiUrl = `${chatApiUrl}/conversations?page_number=${page}&rows_per_page=${rowsPerPage}`; - try { - const response = await GetRequest(apiUrl); - return response; - } catch (error) { - console.error('Get request failed', error); - throw error; - } -}; -export const ConversationChatBySpaceApi = async (spaceId, page, rowsPerPage) => { - const apiUrl = `${chatApiUrl}/conversations?space_id=${spaceId}&page_number=${page}&rows_per_page=${rowsPerPage}`; - try { - const response = await GetRequest(apiUrl); - return response; - } catch (error) { - console.error('Get request failed', error); - throw error; - } -}; -export const ArchiveConversationApi = async (conversationId) => { - const apiUrl = `${chatApiUrl}/conversation/${conversationId}`; - try { - const response = await DeleteRequest(apiUrl); - return response; - } catch (error) { - console.error('Get request failed', error); - throw error; - } -}; export const ConversationHistory = async ( conversationId: string, page: number @@ -100,18 +38,6 @@ export const ConversationHistory = async ( } }; -export const EditCode = async ( - messageId: string, - dataToUpdate, -) => { - const addUrl = `${chatApiUrl}/conversation-message/${messageId}/code`; - try { - const response = await PatchRequest(addUrl, dataToUpdate); - return response; - } catch (error) { - console.error("Update request failed", error); - } -}; export const FetchFollowUpQuestions = async (conversationId: string) => { const apiUrl = `${chatApiUrl}/conversations/${conversationId}/followup-questions`; try { @@ -142,24 +68,4 @@ export const ExplainConversationMessage = async (conversationId: string, message console.error("Get request failed", error); throw error; } -}; -export const GetDataframeFilters = async (messageId: string) => { - const apiUrl = `${chatApiUrl}/conversation-message/${messageId}/dataframe-filter`; - try { - const response = await GetRequest(apiUrl); - return response; - } catch (error) { - console.error("Get request failed", error); - throw error; - } -}; -export const AddDataframeFilters = async (messageId: string, body) => { - const apiUrl = `${chatApiUrl}/conversation-message/${messageId}/apply-filters`; - try { - const response = await PostRequest(apiUrl, body); - return response; - } catch (error) { - console.error("Get request failed", error); - throw error; - } }; \ No newline at end of file diff --git a/client/services/conversations.ts b/client/services/conversations.ts index b16bd65ec..6cbd8722f 100644 --- a/client/services/conversations.ts +++ b/client/services/conversations.ts @@ -1,4 +1,4 @@ -import { GetRequest } from "@/utils/apiUtils"; +import { DeleteRequest, GetRequest } from "@/utils/apiUtils"; const apiUrl = `/v1/conversations`; @@ -24,4 +24,14 @@ export const ConversationMessages = async ( console.error('Get request failed', error); throw error; } +}; + +export const ArchiveConversationApi = async (conversationId) => { + try { + const response = await DeleteRequest(`${apiUrl}/${conversationId}`); + return response; + } catch (error) { + console.error('Get request failed', error); + throw error; + } }; \ No newline at end of file