Skip to content

fix(settings): stop create-admin sheet crash after save - #335

Draft
JohnChantz wants to merge 1 commit into
ui-rewritefrom
cursor/fix-create-admin-user-ec01
Draft

JohnChantz wants to merge 1 commit into
ui-rewritefrom
cursor/fix-create-admin-user-ec01

Conversation

@JohnChantz

@JohnChantz JohnChantz commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the master branch
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx, where "xxx" is the issue number)

What was broken

Clicking Create on Settings → Admin Users → "Create new admin user" saved the admin, then crashed the page with a Next.js overlay (Maximum update depth exceeded in AlertProvider).

Cause

postNewAdminUser succeeded. Closing the sheet ran a useEffect that treated the dirty form as an unsaved discard, called addAlert on every render (unstable setOpen in the effect deps), and looped. Inputs also had no defaultValues, so they flipped between uncontrolled and controlled.

Fix

  • Keep the create form controlled with empty defaults
  • Confirm discard from onOpenChange instead of an effect
  • Reset, then close, after a successful create
  • Wrap admin API failures as plain Errors so Server Actions can serialize them
  • Subscribe AlertProvider to isOpen instead of the undefined open identifier

Test plan

  • Vitest: AddAdminSheet controlled defaults and successful create without the unsaved-changes dialog
  • Vitest: withAdminApiError serializes axios-like failures and rethrows Next redirects
  • Manual: log in, create uiadmin_fixed, confirm success toast, table row, and no overlay

Create new admin user sheet filled in
Success toast and uiadmin_fixed in the table
Admin users table after create with no error overlay
create_admin_user_success.mp4

Other information:

Targets ui-rewrite.

Open in Web Open in Cursor 

Creating an admin succeeded, then closing the sheet re-ran a dirty-form
effect and looped AlertProvider. Keep inputs controlled and confirm
discard from onOpenChange instead.
@JohnChantz
JohnChantz force-pushed the cursor/fix-create-admin-user-ec01 branch from 26dfeaf to 20a60b5 Compare September 25, 2026 14:37
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