Skip to content

ref(onboarding): Convert CreateSampleEventButton to functional component#115830

Open
ryan953 wants to merge 4 commits into
masterfrom
ryan953/ref/convert-create-sample-event-button
Open

ref(onboarding): Convert CreateSampleEventButton to functional component#115830
ryan953 wants to merge 4 commits into
masterfrom
ryan953/ref/convert-create-sample-event-button

Conversation

@ryan953
Copy link
Copy Markdown
Member

@ryan953 ryan953 commented May 19, 2026

Convert CreateSampleEventButton from a class component with withApi/withOrganization HOCs to a functional component using hooks. No behavior change.

API modernization

Replace api.requestPromise with TanStack Query primitives: useMutation + fetchMutation for the POST, and queryClient.fetchQuery with apiOptions, retry, and retryDelay for polling the latest event. The manual while-loop with setTimeout is removed entirely. Replace browserHistory.push with useNavigate. Switch from default export to named export.

Polling via fetchQuery

The create-and-poll lifecycle lives in a single useMutation. After the POST creates the sample group, queryClient.fetchQuery polls the latest-event endpoint using built-in retry/retryDelay options instead of an imperative loop. This eliminates the _isMounted guard — useMutation handles unmount cleanup automatically.

View Interactive Summary

Replace class component with function component using hooks. Replace
withApi/withOrganization HOCs with useApi/useOrganization hooks. Convert
api.requestPromise POST call to useMutation with fetchMutation, and the
polling loop to useQuery with retry/retryDelay. Replace browserHistory
with useNavigate. Switch from default export to named export.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.56%

Replace the imperative api.requestPromise polling loop and useQuery
bridge with queryClient.fetchQuery inside the mutation. This keeps the
entire create-and-poll lifecycle in a single useMutation, using
fetchQuery's built-in retry/retryDelay for polling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move fetchQuery polling out of mutationFn into onSuccess so the
mutation completes after the POST. Polling runs as a detached
.then()/.catch() chain, keeping isPending tied only to the sample
event creation request.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryan953 ryan953 marked this pull request as ready for review May 19, 2026 22:15
@ryan953 ryan953 requested a review from a team as a code owner May 19, 2026 22:15
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit efdf737. Configure here.

Comment thread static/app/views/onboarding/createSampleEventButton.tsx
Comment thread static/app/views/onboarding/createSampleEventButton.tsx
Comment thread static/app/views/onboarding/createSampleEventButton.tsx
Add an AbortController to cancel the fetchQuery polling when the
component unmounts or when a new sample event is created. This
prevents stale navigate, toast, and analytics calls from firing
after the user has left the page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant