Skip to content

Commit

Permalink
[PAN-820]: archive api integrated on frontend (#1210)
Browse files Browse the repository at this point in the history
* archive conversation api added

* archive conversation integrated on frontend
  • Loading branch information
shahrukh802 authored Jun 6, 2024
1 parent 19a837a commit d3d325b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 110 deletions.
2 changes: 2 additions & 0 deletions client/Providers/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -49,6 +50,7 @@ export default function AppProvider({ children }: { children: ReactNode }) {
<ErrorBoundary>
<ContextProvider>
<NoSSR>
<ToastContainer autoClose={3000} className="w-64 text-white" />
<QueryProvider>{children}</QueryProvider>
</NoSSR>
</ContextProvider>
Expand Down
6 changes: 4 additions & 2 deletions client/components/LayoutComponents/ConversationItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
import { ArchiveConversationApi } from "services/chat";
import {
FETCH_CONVERSATION,
useConversationsContext,
Expand All @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions client/hooks/useConversations.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
94 changes: 0 additions & 94 deletions client/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
};
12 changes: 11 additions & 1 deletion client/services/conversations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetRequest } from "@/utils/apiUtils";
import { DeleteRequest, GetRequest } from "@/utils/apiUtils";

const apiUrl = `/v1/conversations`;

Expand All @@ -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;
}
};

0 comments on commit d3d325b

Please sign in to comment.