Skip to content

Fix edge case during join#1979

Merged
kylemh merged 5 commits intomainfrom
fix-edge-case-during-join
Mar 1, 2026
Merged

Fix edge case during join#1979
kylemh merged 5 commits intomainfrom
fix-edge-case-during-join

Conversation

@kylemh
Copy link
Member

@kylemh kylemh commented Mar 1, 2026

Description of changes

Resolves issue where user would fill out all form steps, but not submit the final step. Also resolves UX if necessary cookie missing.

Copilot AI review requested due to automatic review settings March 1, 2026 19:02
@vercel
Copy link

vercel bot commented Mar 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
operation-code Ready Ready Preview, Comment Mar 1, 2026 7:37pm
storybook Ready Ready Preview, Comment Mar 1, 2026 7:37pm

Request Review

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 84.69% 5021 / 5928
🔵 Statements 84.69% 5021 / 5928
🔵 Functions 90.28% 158 / 175
🔵 Branches 93.53% 579 / 619
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
components/Forms/UpdateProfileForm/UpdateProfileForm.tsx 39.56% 50% 25% 39.56% 15-38, 60-93, 96-102, 106
components/Forms/UpdateProfileForm/steps/MilitaryDetails.tsx 100% 100% 100% 100%
Generated in workflow #53 for commit 4b86b66 by the Vitest Coverage Report Action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses an onboarding edge case where intermediate PATCH submissions could incorrectly clear the registration cookie (breaking subsequent steps), and adds a clearer UX path when the onboarding cookie/record is missing by redirecting users back to /join with an explanatory modal.

Changes:

  • Update /api/registration/update to clear the registration cookie only when the client explicitly sends finalize: true.
  • Redirect onboarding users to /join?registrationError=true on 401/404 and show an error modal on the join page.
  • Add an E2E test covering “fill last step → go back → change earlier answers → complete registration” to prevent regressions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pages/join/index.tsx Opens a modal when redirected back with registrationError query param.
pages/api/registration/update.ts Switches cookie-clearing logic to a finalize flag and adjusts 404 behavior.
components/Forms/UpdateProfileForm/UpdateProfileForm.tsx Adds redirect-on-401/404 and sends finalize: true on final submit.
common/constants/api.ts Broadens updateUser typing and adds finalize support in the client API call signature.
components/Forms/UpdateProfileForm/steps/MilitaryDetails.tsx Exports a step form-shape type for API typing.
e2e/join.spec.ts Adds coverage for the back-navigation + resubmit edge case.
Comments suppressed due to low confidence (2)

components/Forms/UpdateProfileForm/UpdateProfileForm.tsx:101

  • goToProfile catches all errors from updateUser and doesn't rethrow or redirect on 401/404. Because MultiStepForm treats a resolved onFinalSubmit as success, this can lead to the form being reset (and the user not being navigated to /join/success) even though the final PATCH failed. Handle 401/404 consistently (redirect to /join?registrationError=true) and rethrow for other errors so MultiStepForm can show an error instead of resetting.
  const goToProfile = async (values: UpdateProfileFormShape) => {
    try {
      await updateUser({ ...values, finalize: true });
      push('/join/success');
    } catch (error) {
      LogRocket.captureException(error as Error);
    }

pages/api/registration/update.ts:94

  • The cookie is cleared before the Airtable update call. If the Airtable update throws (network issue / validation), the cookie will already be gone and the user can’t retry the final submit. Consider only clearing the cookie after the Airtable update succeeds (i.e., set the Set-Cookie header right before returning 200).
      if (req.body.finalize) {
        res.setHeader('Set-Cookie', [
          `opCodeApplicantEmail=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`,
        ]);
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

await base(AIR_TABLE_TABLE_NAME).update(relevantRecord.id, parsedPayload);

return res.status(200).json({ message: 'Success' });
} else {
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

On the 404 path (No record found), the API no longer clears the stale opCodeApplicantEmail cookie. This can leave users stuck with a cookie that allows /join/form to load on a server refresh, but every subsequent PATCH will keep 404’ing and redirecting them back to /join. Consider clearing the cookie on this 404 response (as was done previously) so the server-side guard can reliably redirect users out of the onboarding flow.

Suggested change
} else {
} else {
// Clear stale registration cookie when no record is found so users
// are redirected out of the onboarding flow on subsequent requests.
res.setHeader('Set-Cookie', [
`opCodeApplicantEmail=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`,
]);

Copilot uses AI. Check for mistakes.
@kylemh
Copy link
Member Author

kylemh commented Mar 1, 2026

@kylemh kylemh merged commit 9f16962 into main Mar 1, 2026
12 checks passed
@kylemh kylemh deleted the fix-edge-case-during-join branch March 1, 2026 19:43
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.

2 participants