Fix toast accept showing false error when invalidations fail

Separate API error handling from query invalidation in
NotificationToaster's handleConnectionRespond so a failed refetch
doesn't surface as "Failed to respond" after a successful accept.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kyle 2026-03-04 10:15:23 +08:00
parent f854987f53
commit 5828bbf8e2

View File

@ -17,17 +17,17 @@ export default function NotificationToaster() {
async (requestId: number, action: 'accept' | 'reject', toastId: string | number) => { async (requestId: number, action: 'accept' | 'reject', toastId: string | number) => {
try { try {
await api.put(`/connections/requests/${requestId}/respond`, { action }); await api.put(`/connections/requests/${requestId}/respond`, { action });
toast.dismiss(toastId);
toast.success(action === 'accept' ? 'Connection accepted' : 'Request declined');
await Promise.all([
queryClient.invalidateQueries({ queryKey: ['connections'] }),
queryClient.invalidateQueries({ queryKey: ['people'] }),
queryClient.invalidateQueries({ queryKey: ['notifications'] }),
]);
} catch (err) { } catch (err) {
toast.dismiss(toastId); toast.dismiss(toastId);
toast.error(getErrorMessage(err, 'Failed to respond to request')); toast.error(getErrorMessage(err, 'Failed to respond to request'));
return;
} }
toast.dismiss(toastId);
toast.success(action === 'accept' ? 'Connection accepted' : 'Request declined');
// Fire-and-forget — invalidation errors should not surface as "Failed to respond"
queryClient.invalidateQueries({ queryKey: ['connections'] });
queryClient.invalidateQueries({ queryKey: ['people'] });
queryClient.invalidateQueries({ queryKey: ['notifications'] });
}, },
[queryClient], [queryClient],
); );