mirror of https://github.com/buster-so/buster.git
On success callback updated
This commit is contained in:
parent
d134883db0
commit
09e0e3ec84
|
@ -214,7 +214,9 @@ export const useDeleteChat = () => {
|
||||||
data: Parameters<typeof deleteChat>[0];
|
data: Parameters<typeof deleteChat>[0];
|
||||||
useConfirmModal?: boolean;
|
useConfirmModal?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const method = () => deleteChat(data);
|
const method = async () => {
|
||||||
|
await deleteChat(data);
|
||||||
|
};
|
||||||
if (useConfirmModal) {
|
if (useConfirmModal) {
|
||||||
return await openConfirmModal({
|
return await openConfirmModal({
|
||||||
title: 'Delete Chat',
|
title: 'Delete Chat',
|
||||||
|
@ -228,7 +230,8 @@ export const useDeleteChat = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn,
|
mutationFn,
|
||||||
onSuccess() {
|
retry: false,
|
||||||
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: chatQueryKeys.chatsGetList().queryKey,
|
queryKey: chatQueryKeys.chatsGetList().queryKey,
|
||||||
refetchType: 'all'
|
refetchType: 'all'
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type {
|
||||||
ConfirmProps as BaseConfirmProps,
|
ConfirmProps as BaseConfirmProps,
|
||||||
ConfirmModalProps
|
ConfirmModalProps
|
||||||
} from '@/components/ui/modal/ConfirmModal';
|
} from '@/components/ui/modal/ConfirmModal';
|
||||||
|
import { USER_CANCELLED_ERROR } from '../BusterReactQuery/queryClientConfig';
|
||||||
|
|
||||||
interface ConfirmProps<T = unknown> extends Omit<BaseConfirmProps, 'onOk'> {
|
interface ConfirmProps<T = unknown> extends Omit<BaseConfirmProps, 'onOk'> {
|
||||||
title: string | React.ReactNode;
|
title: string | React.ReactNode;
|
||||||
|
@ -15,7 +16,7 @@ const defaultConfirmModalProps: ConfirmProps<unknown> = {
|
||||||
title: '',
|
title: '',
|
||||||
content: '',
|
content: '',
|
||||||
onOk: () => undefined,
|
onOk: () => undefined,
|
||||||
onCancel: async () => {}
|
onCancel: async () => Promise.reject(USER_CANCELLED_ERROR)
|
||||||
};
|
};
|
||||||
|
|
||||||
interface QueuedModal<T = unknown> extends Omit<ConfirmProps<T>, 'onOk' | 'onCancel'> {
|
interface QueuedModal<T = unknown> extends Omit<ConfirmProps<T>, 'onOk' | 'onCancel'> {
|
||||||
|
|
|
@ -57,12 +57,6 @@ export const BusterReactQueryProvider = ({ children }: { children: React.ReactNo
|
||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// const busterApiContext = useMemo(() => {
|
|
||||||
// return {
|
|
||||||
// honoInstance: createHonoInstance(BASE_API_URL_V2, checkTokenValidity)
|
|
||||||
// };
|
|
||||||
// }, [checkTokenValidity]);
|
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
'meta+shift+i',
|
'meta+shift+i',
|
||||||
(e) => {
|
(e) => {
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import { isServer, QueryClient } from '@tanstack/react-query';
|
import { isServer, QueryClient } from '@tanstack/react-query';
|
||||||
import type { useBusterNotifications } from '../BusterNotifications';
|
import type { useBusterNotifications } from '../BusterNotifications';
|
||||||
import { openErrorNotification as openErrorNotificationMethod } from '../BusterNotifications';
|
import { openErrorNotification as openErrorNotificationMethod } from '../BusterNotifications';
|
||||||
|
import {
|
||||||
|
ERROR_RETRY_DELAY,
|
||||||
|
GC_TIME,
|
||||||
|
PREFETCH_STALE_TIME,
|
||||||
|
USER_CANCELLED_ERROR
|
||||||
|
} from './queryClientConfig';
|
||||||
|
|
||||||
type OpenErrorNotification = ReturnType<typeof useBusterNotifications>['openErrorNotification'];
|
type OpenErrorNotification = ReturnType<typeof useBusterNotifications>['openErrorNotification'];
|
||||||
|
|
||||||
const PREFETCH_STALE_TIME = 1000 * 10; // 10 seconds
|
|
||||||
const ERROR_RETRY_DELAY = 1 * 1000; // 1 second delay after error
|
|
||||||
const GC_TIME = 1000 * 60 * 60 * 24 * 3; // 24 hours - matches persistence duration
|
|
||||||
|
|
||||||
function makeQueryClient(params?: {
|
function makeQueryClient(params?: {
|
||||||
openErrorNotification?: OpenErrorNotification;
|
openErrorNotification?: OpenErrorNotification;
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
|
@ -34,7 +36,7 @@ function makeQueryClient(params?: {
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
retry: (failureCount, error) => {
|
retry: (failureCount, error) => {
|
||||||
if (params?.openErrorNotification) {
|
if (params?.openErrorNotification && error !== USER_CANCELLED_ERROR) {
|
||||||
params.openErrorNotification(error);
|
params.openErrorNotification(error);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
export const PREFETCH_STALE_TIME = 1000 * 10; // 10 seconds
|
||||||
|
export const ERROR_RETRY_DELAY = 1 * 1000; // 1 second delay after error
|
||||||
|
export const GC_TIME = 1000 * 60 * 60 * 24 * 3; // 24 hours - matches persistence duration
|
||||||
|
export const USER_CANCELLED_ERROR = new Error('User cancelled');
|
|
@ -112,7 +112,14 @@ const ThreeDotDropdown: React.FC<{
|
||||||
icon: <Trash />,
|
icon: <Trash />,
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
try {
|
try {
|
||||||
await deleteCollection({ id });
|
await deleteCollection(
|
||||||
|
{ id },
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
onChangePage({ route: BusterRoutes.APP_COLLECTIONS });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
onChangePage({ route: BusterRoutes.APP_COLLECTIONS });
|
onChangePage({ route: BusterRoutes.APP_COLLECTIONS });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue