diff --git a/src/chat/components/ProjectsPanel.client.tsx b/src/chat/components/ProjectsPanel.client.tsx
index aab031c3a..74a926a31 100644
--- a/src/chat/components/ProjectsPanel.client.tsx
+++ b/src/chat/components/ProjectsPanel.client.tsx
@@ -55,10 +55,7 @@ export function ProjectsPanel({ userId }: { userId: string }) {
if (!project) throw new Error('This project template is unavailable.')
return createBuilderProject(project)
},
- onSuccess: async (project) => {
- await setSelected(project.id)
- await client.invalidateQueries({ queryKey })
- },
+ onSuccess: () => client.invalidateQueries({ queryKey }),
})
const active = selected ?? projects.data?.[0]?.id
const open = async (id: string) => {
@@ -111,7 +108,11 @@ export function ProjectsPanel({ userId }: { userId: string }) {
/>
diff --git a/src/components/DocFeedbackNote.tsx b/src/components/DocFeedbackNote.tsx
index a0918a5d8..652e07a13 100644
--- a/src/components/DocFeedbackNote.tsx
+++ b/src/components/DocFeedbackNote.tsx
@@ -136,8 +136,6 @@ export function DocFeedbackNote({
queryClient.setQueryData(queryKey, data)
})
}
- setDeleteError(error.message)
- setIsDeleting(false)
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
@@ -199,10 +197,6 @@ export function DocFeedbackNote({
return { previousData }
},
- onSuccess: () => {
- setIsSaving(false)
- setSaveError(null)
- },
onError: (error: Error, variables, context) => {
// Rollback on error
if (context?.previousData) {
@@ -210,8 +204,6 @@ export function DocFeedbackNote({
queryClient.setQueryData(queryKey, data)
})
}
- setSaveError(error.message)
- setIsSaving(false)
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
@@ -291,7 +283,15 @@ export function DocFeedbackNote({
if (!isDeleting && confirm('Are you sure you want to delete this note?')) {
setIsDeleting(true)
setDeleteError(null)
- deleteMutation.mutate({ data: { feedbackId: note.id } })
+ deleteMutation.mutate(
+ { data: { feedbackId: note.id } },
+ {
+ onError: (error: Error) => {
+ setDeleteError(error.message)
+ setIsDeleting(false)
+ },
+ },
+ )
}
}
@@ -303,12 +303,24 @@ export function DocFeedbackNote({
setIsSaving(true)
setSaveError(null)
- updateMutation.mutate({
- data: {
- feedbackId: note.id,
- content: content.trim(),
+ updateMutation.mutate(
+ {
+ data: {
+ feedbackId: note.id,
+ content: content.trim(),
+ },
},
- })
+ {
+ onSuccess: () => {
+ setIsSaving(false)
+ setSaveError(null)
+ },
+ onError: (error: Error) => {
+ setSaveError(error.message)
+ setIsSaving(false)
+ },
+ },
+ )
}
const handleCancel = () => {
diff --git a/src/components/DocFeedbackProvider.tsx b/src/components/DocFeedbackProvider.tsx
index 26125bcba..2a53f0eee 100644
--- a/src/components/DocFeedbackProvider.tsx
+++ b/src/components/DocFeedbackProvider.tsx
@@ -650,9 +650,6 @@ function CreatingFeedbackNote({
return { previousData }
},
- onSuccess: () => {
- onClose()
- },
onError: (error: Error, variables, context) => {
// Rollback on error
if (context?.previousData) {
@@ -660,8 +657,6 @@ function CreatingFeedbackNote({
queryClient.setQueryData(queryKey, data)
})
}
- setError(error.message)
- setIsSaving(false)
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
@@ -684,18 +679,29 @@ function CreatingFeedbackNote({
setIsSaving(true)
setError(null)
- createMutation.mutate({
- data: {
- type,
- content: content.trim(),
- pagePath,
- libraryId,
- libraryVersion,
- blockSelector,
- blockContentHash,
- blockMarkdown,
+ createMutation.mutate(
+ {
+ data: {
+ type,
+ content: content.trim(),
+ pagePath,
+ libraryId,
+ libraryVersion,
+ blockSelector,
+ blockContentHash,
+ blockMarkdown,
+ },
},
- })
+ {
+ onSuccess: () => {
+ onClose()
+ },
+ onError: (error: Error) => {
+ setError(error.message)
+ setIsSaving(false)
+ },
+ },
+ )
}
const charCount = content.length
diff --git a/src/components/FeedbackModerationPage.tsx b/src/components/FeedbackModerationPage.tsx
index d22514821..2d408d226 100644
--- a/src/components/FeedbackModerationPage.tsx
+++ b/src/components/FeedbackModerationPage.tsx
@@ -33,29 +33,9 @@ export function FeedbackModerationPage() {
const moderateMutation = useMutation({
mutationFn: moderateDocFeedback,
- onSuccess: (_, variables) => {
- notify(
-
-
Feedback moderated
-
- Feedback{' '}
- {variables.data.action === 'approve' ? 'approved' : 'denied'}{' '}
- successfully.
-
-
,
- )
+ onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['docFeedback', 'moderation'] })
},
- onError: (error: Error) => {
- notify(
-
-
Moderation failed
-
- {error.message}
-
-
,
- )
- },
})
const handleFilterChange = (filters: Partial) => {
@@ -89,13 +69,39 @@ export function FeedbackModerationPage() {
action: 'approve' | 'deny',
moderationNote?: string,
) => {
- moderateMutation.mutate({
- data: {
- feedbackId,
- action,
- moderationNote,
+ moderateMutation.mutate(
+ {
+ data: {
+ feedbackId,
+ action,
+ moderationNote,
+ },
},
- })
+ {
+ onSuccess: (_, variables) => {
+ notify(
+
+
Feedback moderated
+
+ Feedback{' '}
+ {variables.data.action === 'approve' ? 'approved' : 'denied'}{' '}
+ successfully.
+
+
,
+ )
+ },
+ onError: (error: Error) => {
+ notify(
+
+
Moderation failed
+
+ {error.message}
+
+
,
+ )
+ },
+ },
+ )
}
return (
diff --git a/src/components/NewsletterSignup.tsx b/src/components/NewsletterSignup.tsx
index 26fd70b83..486864247 100644
--- a/src/components/NewsletterSignup.tsx
+++ b/src/components/NewsletterSignup.tsx
@@ -31,30 +31,7 @@ export function NewsletterSignup({
const { mutate, isPending } = useMutation({
mutationFn: () => addUserSignupSource({ data: { source: 'newsletter' } }),
- onSuccess: async (result) => {
- await queryClient.invalidateQueries(currentUserQueryOptions)
-
- notify(
-
-
- {result.alreadyTagged ? 'Already subscribed' : "You're subscribed"}
-
-
- We'll use your TanStack login email.
-
-
,
- )
- },
- onError: () => {
- notify(
-
-
Subscription failed
-
- Please try again in a moment
-
-
,
- )
- },
+ onSuccess: () => queryClient.invalidateQueries(currentUserQueryOptions),
})
const handleSubscribe = React.useCallback(() => {
@@ -62,15 +39,43 @@ export function NewsletterSignup({
return
}
+ const subscribe = () =>
+ mutate(undefined, {
+ onSuccess: (result) => {
+ notify(
+
+
+ {result.alreadyTagged
+ ? 'Already subscribed'
+ : "You're subscribed"}
+
+
+ We'll use your TanStack login email.
+
+
,
+ )
+ },
+ onError: () => {
+ notify(
+
+
Subscription failed
+
+ Please try again in a moment
+
+
,
+ )
+ },
+ })
+
if (!user) {
openLoginModal({
- onSuccess: () => mutate(),
+ onSuccess: subscribe,
})
return
}
- mutate()
- }, [isPending, isSubscribed, mutate, openLoginModal, user])
+ subscribe()
+ }, [isPending, isSubscribed, mutate, notify, openLoginModal, user])
if (isSubscribed) {
return (
diff --git a/src/components/ShowcaseModerationPage.tsx b/src/components/ShowcaseModerationPage.tsx
index 68024b685..cea5f58dc 100644
--- a/src/components/ShowcaseModerationPage.tsx
+++ b/src/components/ShowcaseModerationPage.tsx
@@ -35,50 +35,16 @@ export function ShowcaseModerationPage() {
const featuredMutation = useMutation({
mutationFn: setShowcaseFeatured,
- onSuccess: (_, variables) => {
- notify(
-
-
Featured status updated
-
- Showcase {variables.data.isFeatured ? 'featured' : 'unfeatured'}{' '}
- successfully.
-
-
,
- )
+ onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['showcases'] })
},
- onError: (error: Error) => {
- notify(
-
-
Update failed
-
- {error.message}
-
-
,
- )
- },
})
const deleteMutation = useMutation({
mutationFn: adminDeleteShowcase,
onSuccess: () => {
- notify(
- ,
- )
queryClient.invalidateQueries({ queryKey: ['showcases'] })
},
- onError: (error: Error) => {
- notify(
-
-
Delete failed
-
- {error.message}
-
-
,
- )
- },
})
const voteMutation = useMutation({
@@ -115,18 +81,64 @@ export function ShowcaseModerationPage() {
}
const handleToggleFeatured = (showcaseId: string, isFeatured: boolean) => {
- featuredMutation.mutate({
- data: {
- showcaseId,
- isFeatured,
+ featuredMutation.mutate(
+ {
+ data: {
+ showcaseId,
+ isFeatured,
+ },
},
- })
+ {
+ onSuccess: (_, variables) => {
+ notify(
+
+
Featured status updated
+
+ Showcase {variables.data.isFeatured ? 'featured' : 'unfeatured'}{' '}
+ successfully.
+
+
,
+ )
+ },
+ onError: (error: Error) => {
+ notify(
+
+
Update failed
+
+ {error.message}
+
+
,
+ )
+ },
+ },
+ )
}
const handleDelete = (showcaseId: string) => {
- deleteMutation.mutate({
- data: { showcaseId },
- })
+ deleteMutation.mutate(
+ {
+ data: { showcaseId },
+ },
+ {
+ onSuccess: () => {
+ notify(
+ ,
+ )
+ },
+ onError: (error: Error) => {
+ notify(
+
+
Delete failed
+
+ {error.message}
+
+
,
+ )
+ },
+ },
+ )
}
const handleVote = (showcaseId: string, value: 1 | -1) => {
diff --git a/src/components/ShowcaseSubmitForm.tsx b/src/components/ShowcaseSubmitForm.tsx
index 1e37322ad..30911ea20 100644
--- a/src/components/ShowcaseSubmitForm.tsx
+++ b/src/components/ShowcaseSubmitForm.tsx
@@ -91,14 +91,10 @@ export function ShowcaseSubmitForm({ showcase }: ShowcaseSubmitFormProps) {
const createMutation = useMutation({
mutationFn: submitShowcase,
- onSuccess,
- onError,
})
const editMutation = useMutation({
mutationFn: updateShowcase,
- onSuccess,
- onError,
})
const isPending = createMutation.isPending || editMutation.isPending
@@ -179,11 +175,14 @@ export function ShowcaseSubmitForm({ showcase }: ShowcaseSubmitFormProps) {
}
if (isEditMode) {
- editMutation.mutate({
- data: { ...formData, showcaseId: showcase.id },
- })
+ editMutation.mutate(
+ {
+ data: { ...formData, showcaseId: showcase.id },
+ },
+ { onSuccess, onError },
+ )
} else {
- createMutation.mutate({ data: formData })
+ createMutation.mutate({ data: formData }, { onSuccess, onError })
}
}
diff --git a/src/routes/-shop-browse.tsx b/src/routes/-shop-browse.tsx
index f26f3396c..514905380 100644
--- a/src/routes/-shop-browse.tsx
+++ b/src/routes/-shop-browse.tsx
@@ -104,12 +104,6 @@ export function ShopBrowsePage({
},
})
},
- onSuccess: (next) => {
- if (!next) return
- setAccumulated((prev) => [...prev, ...next.nodes])
- setEndCursor(next.pageInfo.endCursor)
- setHasNextPage(next.pageInfo.hasNextPage)
- },
})
const allProducts = React.useMemo(
@@ -222,7 +216,16 @@ export function ShopBrowsePage({
{hasNextPage ? (
loadMore.mutate()}
+ onClick={() =>
+ loadMore.mutate(undefined, {
+ onSuccess: (next) => {
+ if (!next) return
+ setAccumulated((prev) => [...prev, ...next.nodes])
+ setEndCursor(next.pageInfo.endCursor)
+ setHasNextPage(next.pageInfo.hasNextPage)
+ },
+ })
+ }
disabled={loadMore.isPending}
>
{loadMore.isPending ? 'Loading...' : 'Load more'}
diff --git a/src/routes/account/integrations.tsx b/src/routes/account/integrations.tsx
index dfe58ae16..0d47d1204 100644
--- a/src/routes/account/integrations.tsx
+++ b/src/routes/account/integrations.tsx
@@ -50,30 +50,8 @@ function IntegrationsPage() {
const createMutation = useMutation({
mutationFn: createMcpApiKey,
- onSuccess: (data) => {
+ onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['api-keys'] })
- setNewlyCreatedKey(data.rawKey)
- setIsCreating(false)
- setNewKeyName('')
- setExpiresInDays(undefined)
- notify(
-
-
API key created
-
- Copy it now, you won't see it again
-
-
,
- )
- },
- onError: (error) => {
- notify(
-
-
Error
-
- {error instanceof Error ? error.message : 'Failed to create key'}
-
-
,
- )
},
})
@@ -81,11 +59,6 @@ function IntegrationsPage() {
mutationFn: revokeMcpApiKey,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['api-keys'] })
- notify(
- ,
- )
},
})
@@ -93,11 +66,6 @@ function IntegrationsPage() {
mutationFn: deleteMcpApiKey,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['api-keys'] })
- notify(
- ,
- )
},
})
@@ -110,22 +78,47 @@ function IntegrationsPage() {
mutationFn: revokeConnectedApp,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['connected-apps'] })
- notify(
- ,
- )
},
})
const handleCreate = () => {
if (!newKeyName.trim()) return
- createMutation.mutate({
- data: {
- name: newKeyName.trim(),
- expiresInDays,
+ createMutation.mutate(
+ {
+ data: {
+ name: newKeyName.trim(),
+ expiresInDays,
+ },
},
- })
+ {
+ onSuccess: (data) => {
+ setNewlyCreatedKey(data.rawKey)
+ setIsCreating(false)
+ setNewKeyName('')
+ setExpiresInDays(undefined)
+ notify(
+
+
API key created
+
+ Copy it now, you won't see it again
+
+
,
+ )
+ },
+ onError: (error) => {
+ notify(
+
+
Error
+
+ {error instanceof Error
+ ? error.message
+ : 'Failed to create key'}
+
+
,
+ )
+ },
+ },
+ )
}
const handleCopy = async () => {
@@ -349,7 +342,20 @@ function IntegrationsPage() {
{key.isActive && (