mirror of https://github.com/buster-so/buster.git
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:
parent
4d61349c6c
commit
5403313628
|
@ -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'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue