update delete endpoints

This commit is contained in:
Nate Kelley 2025-03-28 13:49:19 -06:00
parent 94be03ee93
commit 0ce645d893
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 26 additions and 14 deletions

View File

@ -10,7 +10,7 @@ export const createApiKey = async (name: string) => {
}; };
export const deleteApiKey = async (id: string) => { export const deleteApiKey = async (id: string) => {
return mainApi.delete(`/api_keys/${id}`).then(() => {}); return mainApi.delete(`/api_keys/${id}`).then((res) => res.data);
}; };
export const getApiKey = async (id: string) => { export const getApiKey = async (id: string) => {

View File

@ -60,8 +60,8 @@ export const updateChat = async ({
return mainApi.put<BusterChat>(`${CHATS_BASE}/${id}`, data).then((res) => res.data); return mainApi.put<BusterChat>(`${CHATS_BASE}/${id}`, data).then((res) => res.data);
}; };
export const deleteChat = async (ids: string[]): Promise<void> => { export const deleteChat = async (data: string[]): Promise<void> => {
return mainApi.delete(`${CHATS_BASE}`, { data: { ids } }).then((res) => res.data); return mainApi.delete(`${CHATS_BASE}`, { data }).then((res) => res.data);
}; };
export const duplicateChat = async ({ export const duplicateChat = async ({

View File

@ -64,13 +64,15 @@ export const collectionsUpdateCollection = async (params: {
.then((res) => res.data); .then((res) => res.data);
}; };
export const collectionsDeleteCollection = async (params: { export const collectionsDeleteCollection = async (data: {
/** Array of collection IDs to be deleted */ /** Array of collection IDs to be deleted */
ids: string[]; ids: string[];
}) => { }) => {
return await mainApi.delete<BusterCollection>('/collections', { return await mainApi
data: { ids: params.ids } .delete<BusterCollection>('/collections', {
}).then((res) => res.data); data
})
.then((res) => res.data);
}; };
// share collections // share collections

View File

@ -72,8 +72,8 @@ export const dashboardsUpdateDashboard = async (params: {
.then((res) => res.data); .then((res) => res.data);
}; };
export const dashboardsDeleteDashboard = async ({ ids }: { ids: string[] }) => { export const dashboardsDeleteDashboard = async (data: { ids: string[] }) => {
return await mainApi.delete<null>(`/dashboards`, { data: { ids } }).then((res) => res.data); return await mainApi.delete<null>(`/dashboards`, { data }).then((res) => res.data);
}; };
// share dashboards // share dashboards

View File

@ -25,8 +25,8 @@ export const updateDatasetGroup = async (
return mainApi.put(`/dataset_groups`, data).then((res) => res.data); return mainApi.put(`/dataset_groups`, data).then((res) => res.data);
}; };
export const deleteDatasetGroup = async (ids: string[]) => { export const deleteDatasetGroup = async (data: string[]) => {
return mainApi.delete(`/dataset_groups`, { data: { ids } }).then((res) => res.data); return mainApi.delete(`/dataset_groups`, { data }).then((res) => res.data);
}; };
export const getDatasetGroup = async (id: string) => { export const getDatasetGroup = async (id: string) => {

View File

@ -5,12 +5,15 @@ import { Copy, Trash, Pencil } from '@/components/ui/icons';
import { useDeleteChat, useDuplicateChat } from '@/api/buster_rest/chats'; import { useDeleteChat, useDuplicateChat } from '@/api/buster_rest/chats';
import { CHAT_HEADER_TITLE_ID } from '../ChatHeaderTitle'; import { CHAT_HEADER_TITLE_ID } from '../ChatHeaderTitle';
import { timeout } from '@/lib'; import { timeout } from '@/lib';
import { useRouter } from 'next/navigation';
import { BusterRoutes, createBusterRoute } from '@/routes';
export const ChatContainerHeaderDropdown: React.FC<{ export const ChatContainerHeaderDropdown: React.FC<{
children: React.ReactNode; children: React.ReactNode;
}> = React.memo(({ children }) => { }> = React.memo(({ children }) => {
const chatId = useChatIndividualContextSelector((state) => state.chatId); const chatId = useChatIndividualContextSelector((state) => state.chatId);
const { mutate: deleteChat } = useDeleteChat(); const router = useRouter();
const { mutate: deleteChat, isPending: isDeleting } = useDeleteChat();
const { mutate: duplicateChat } = useDuplicateChat(); const { mutate: duplicateChat } = useDuplicateChat();
const currentMessageId = useChatIndividualContextSelector((state) => state.currentMessageId); const currentMessageId = useChatIndividualContextSelector((state) => state.currentMessageId);
@ -20,7 +23,14 @@ export const ChatContainerHeaderDropdown: React.FC<{
label: 'Delete chat', label: 'Delete chat',
value: 'delete', value: 'delete',
icon: <Trash />, icon: <Trash />,
onClick: () => chatId && deleteChat([chatId]) loading: isDeleting,
onClick: () =>
chatId &&
deleteChat([chatId], {
onSuccess: () => {
router.push(createBusterRoute({ route: BusterRoutes.APP_CHAT }));
}
})
}, },
{ {
label: 'Duplicate chat', label: 'Duplicate chat',
@ -44,7 +54,7 @@ export const ChatContainerHeaderDropdown: React.FC<{
} }
} }
]; ];
}, [chatId, currentMessageId, deleteChat, duplicateChat]); }, [chatId, isDeleting, currentMessageId, deleteChat, duplicateChat]);
return ( return (
<Dropdown align="end" items={menuItem}> <Dropdown align="end" items={menuItem}>