Fix chat deletion toast bug - add wasCancelled flag

- Modify useDeleteChat hook to return object with wasCancelled boolean
- Update ChatHeaderDropdown to check wasCancelled before showing toast
- Clicking Cancel on delete modal no longer shows 'Chat deleted' toast
- Clicking OK still deletes chat and shows success toast as expected

Fixes BUS-1523

Co-Authored-By: nate@buster.so <nate@buster.so>
This commit is contained in:
Devin AI 2025-07-24 21:09:49 +00:00
parent 4d61349c6c
commit 5403313628
2 changed files with 22 additions and 10 deletions

View File

@ -216,23 +216,33 @@ export const useDeleteChat = () => {
}) => {
const method = () => deleteChat(data);
if (useConfirmModal) {
return await openConfirmModal({
const result = await openConfirmModal({
title: 'Delete Chat',
content: 'Are you sure you want to delete this chat?',
onOk: method
});
return {
wasCancelled: result === undefined,
result
};
}
return method();
const result = await method();
return {
wasCancelled: false,
result
};
}
);
return useMutation({
mutationFn,
onSuccess() {
queryClient.invalidateQueries({
queryKey: chatQueryKeys.chatsGetList().queryKey,
refetchType: 'all'
});
onSuccess(data) {
if (!data.wasCancelled) {
queryClient.invalidateQueries({
queryKey: chatQueryKeys.chatsGetList().queryKey,
refetchType: 'all'
});
}
}
});
};

View File

@ -46,9 +46,11 @@ export const ChatContainerHeaderDropdown: React.FC<{
deleteChat(
{ data: [chatId] },
{
onSuccess: () => {
onChangePage({ route: BusterRoutes.APP_CHAT });
openSuccessMessage('Chat deleted');
onSuccess: (data) => {
if (!data.wasCancelled) {
onChangePage({ route: BusterRoutes.APP_CHAT });
openSuccessMessage('Chat deleted');
}
}
}
)