Skip to content

refactor: convert the requestCert writer to a React Query mutation - #1995

Merged
brian-smith-tcril merged 1 commit into
masterfrom
bsmith/react-query-request-cert-mutation
Aug 21, 2026
Merged

refactor: convert the requestCert writer to a React Query mutation#1995
brian-smith-tcril merged 1 commit into
masterfrom
bsmith/react-query-request-cert-mutation

Conversation

@brian-smith-tcril

@brian-smith-tcril brian-smith-tcril commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Convert the shared requestCert POST thunk to a useRequestCert React Query mutation and delete the thunk. Part of the Redux → React Query migration (#1946). Prerequisite below the outline-tab conversion (#1991) — outline's CertificateStatusAlert is one of this thunk's three callers, so converting requestCert first lets outline build on an already-converted base. Closes #1994.

requestCert is a fire-and-forget "request certificate" POST (postRequestCert/courses/{courseId}/generate_user_cert) shared by three tabs, so all three callers convert together — the only way to delete the thunk rather than leave a redundant POST path.

What changed

  • apiHooks.ts — add useRequestCert (mutationFn: ({ courseId }) => postRequestCert(courseId), onError: logError), mirroring the other course-home mutations.
  • Convert the three callers from dispatch(requestCert(courseId)) to useRequestCert().mutate({ courseId }), dropping each file's useDispatch + requestCert thunk import:
    • course-home/outline-tab/alerts/certificate-status-alert/CertificateStatusAlert.jsx
    • courseware/course/course-exit/CourseCelebration.jsx
    • course-home/progress-tab/certificate-status/CertificateStatus.jsx
  • data/thunks.js — delete the requestCert thunk and its now-unused postRequestCert import. (requestCert isn't re-exported from data/index.js, so no re-export change.)

Behavior

No user-facing change. The thunk and the mutation both call the same postRequestCert(courseId) → identical fire-and-forget POST, no response handling. The only delta is onError: logError (the thunk left failures unhandled) — a strict improvement.

Testing

npm run types, npm run lint, and the full npm test suite (106 suites, 3 pre-existing skips) pass. New useRequestCert coverage in apiHooks.test.tsx (asserts the POST + error logging). All three callers' click paths are now exercised: ProgressTab.test.jsx and CourseExit.test.jsx click the request-certificate button and assert the generate_user_cert POST fires; OutlineTab.test.jsx already clicks it. (The CourseExit click test was added here — its button previously rendered but was never clicked, leaving the mutate line uncovered.)

Decisions

Full decision log

Decisions — convert the requestCert writer to a React Query mutation (#1994)

Working notes for this PR (part of the Redux → React Query migration, #1946).
Not checked in. A prerequisite below the outline-tab conversion (#1991).

Whole-writer conversion, not per-tab

Decision. Convert requestCert across all three of its callers in one
PR and delete the thunk, rather than converting per-tab:

  • outline-tab/.../CertificateStatusAlert.jsx (outline)
  • courseware/course/course-exit/CourseCelebration.jsx (course-exit)
  • progress-tab/certificate-status/CertificateStatus.jsx (progress)

Why. requestCert is a single shared thunk with three callers. To actually
delete the thunk (not just relocate a redundant POST path), every caller must
stop using it. This surfaced while converting the outline tab (#1991): deleting
the thunk there would have broken course-exit and progress, which also dispatch
it.

Its own layer, below outline

Decision. requestCert converts in a dedicated layer beneath the
outline-tab conversion (#1991), not folded into it.

Why. Outline's CertificateStatusAlert is one of the three callers. Landing
the writer conversion below outline lets the outline PR build on an
already-converted CertificateStatusAlert and keeps a shared-code change out of
the tab-conversion diff. (dismissWelcomeMessage, which is genuinely
outline-only, stays in the outline PR.)

Behavior-preserving

Decision. useRequestCert is a fire-and-forget mutation calling the same
postRequestCert(courseId) the thunk did; onError: logError is the only delta.

Why. Both paths POST to /courses/{courseId}/generate_user_cert with no
response handling. The thunk left failures unhandled; the mutation logs them — a
strict improvement, no user-facing change.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.96%. Comparing base (db3808c) to head (4710859).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1995      +/-   ##
==========================================
+ Coverage   92.88%   92.96%   +0.08%     
==========================================
  Files         364      364              
  Lines        5943     5944       +1     
  Branches     1415     1415              
==========================================
+ Hits         5520     5526       +6     
+ Misses        403      399       -4     
+ Partials       20       19       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from a891582 to 82889d7 Compare August 12, 2026 14:10
@brian-smith-tcril
brian-smith-tcril marked this pull request as ready for review August 12, 2026 16:41
@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from 82889d7 to 02a07a7 Compare August 21, 2026 00:58
@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from 02a07a7 to b5b2f82 Compare August 21, 2026 01:59

@arbrandes arbrandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍🏼

@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from b5b2f82 to 597103e Compare August 21, 2026 14:48
@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from 597103e to 66efe59 Compare August 21, 2026 18:34
Base automatically changed from bsmith/react-query-tour-button-cleanup to master August 21, 2026 18:40
The shared `requestCert` POST thunk is used by three tabs — CertificateStatusAlert
(outline), CourseCelebration (course-exit), and CertificateStatus (progress).
Convert all three to a `useRequestCert` mutation (fire-and-forget POST to
generate_user_cert) and delete the thunk. Prerequisite below the outline-tab
conversion so outline builds on an already-converted CertificateStatusAlert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@brian-smith-tcril
brian-smith-tcril force-pushed the bsmith/react-query-request-cert-mutation branch from 66efe59 to 4710859 Compare August 21, 2026 18:40
@brian-smith-tcril
brian-smith-tcril merged commit 5fe995a into master Aug 21, 2026
7 checks passed
@brian-smith-tcril
brian-smith-tcril deleted the bsmith/react-query-request-cert-mutation branch August 21, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert the requestCert writer to a React Query mutation

2 participants