Skip to content

feat(studio): add async handling to AlertDialog actions - #45960

Merged
dnywh merged 13 commits into
masterfrom
dnywh/alert-dialog-async-actions
May 22, 2026
Merged

dnywh merged 13 commits into
masterfrom
dnywh/alert-dialog-async-actions

Conversation

@dnywh

@dnywh dnywh commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature, bug fix, and docs update. Addresses the AlertDialog async action behaviour discussed in Slack and follow-up PR feedback.

What is the current behavior?

AlertDialogAction delegates directly to Radix, so confirm actions close the dialog immediately on click. Async mutation flows have to use asChild with event.preventDefault() and a custom loading button to keep the dialog open while work is in flight.

What is the new behavior?

  • AlertDialogAction now accepts async handlers and a controlled loading prop. Promise-returning actions keep the dialog open, show the existing Button loading state, disable cancel/dismissal while pending, close on success, and stay open on rejection.
  • Existing workaround usages in Studio have been migrated to the direct action API (see 'To test' callsite list below)
  • design-system docs now include async action examples and AlertDialogBody guidance for inline feedback
CleanShot.2026-05-15.at.15.51.59.mp4

Additional context

To test

  • On Studio API Keys settings, use a project with no publishable or secret API keys, click the “Create API keys” banner action, and confirm the Alert Dialog stays open with loading until the default publishable and secret keys are created.
  • Delete a JIT database access rule and confirm the Alert Dialog stays open with loading until deletion succeeds, and stays open with inline feedback if it fails.
  • With temporary access disabled and existing rules configured, enable temporary access and confirm the “This will activate existing rules” Alert Dialog stays open with loading until the configuration update succeeds, and stays open with inline feedback if it fails.
  • Disable external replication and confirm the Alert Dialog stays open with loading until the mutation succeeds.
  • Enable Index Advisor and confirm the Alert Dialog stays open with loading until the mutation succeeds, and stays open with inline feedback if it fails.

Summary by CodeRabbit

  • New Features

    • Alert dialogs support async actions with built-in loading, dismissal blocking while pending, and preserved dialog on error.
    • Two interactive examples demonstrating async success and error flows.
  • Improvements

    • Dialogs now surface inline error messages and consistent loading/confirm behavior across flows (create keys, replication, JIT DB access, index advisor).
    • Minor UI refinements for action controls.
  • Documentation

    • Docs updated with async-action guidance and inline-error recommendations.
  • Tests

    • New test suite validating async dialog behaviors.

Review Change Stack

@vercel

vercel Bot commented May 15, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment May 21, 2026 9:07am
docs Ready Ready Preview, Comment, Open in v0 May 21, 2026 9:07am
studio-self-hosted Ready Ready Preview, Comment May 21, 2026 9:07am
studio-staging Ready Ready Preview, Comment May 21, 2026 9:07am
ui-library Ready Ready Preview, Comment May 21, 2026 9:07am
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 May 21, 2026 9:07am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 21, 2026 9:07am

Request Review

@supabase

supabase Bot commented May 15, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR makes AlertDialog promise-aware: actions returning Promises show loading, block dismissal (Escape/outside/cancel) while pending, force-close on success, and keep the dialog open on rejection. Tests cover these flows. Design-system examples, docs, registry entries, and several Studio dialogs were updated to use the new API.

Changes

Async Alert Dialog Feature

Layer / File(s) Summary
AlertDialog async implementation and context
packages/ui/src/components/shadcn/ui/alert-dialog.tsx
AlertDialog adds a loading context and context-aware setOpen that blocks closing while any action is loading; AlertDialogContent prevents Escape/outside dismissal when loading; AlertDialogAction gains loading?: boolean, detects promise-like onClick returns, sets action/dialog loading, force-closes on success, and swallows errors to keep the dialog open; AlertDialogCancel disables while loading.
AlertDialog async behavior tests
packages/ui/src/components/shadcn/ui/alert-dialog.test.tsx
Vitest + RTL tests validate sync close, pending async UI (spinner/disabled), close-on-resolve, remain-open-on-reject, blocked cancel/Escape/outside during loading, and externally-controlled loading state.
Async alert dialog example components
apps/design-system/registry/default/example/alert-dialog-async.tsx, apps/design-system/registry/default/example/alert-dialog-async-error.tsx
Two examples: AlertDialogAsync demonstrates a promise-based confirm (Create keys) and AlertDialogAsyncError demonstrates failing async action with inline Admonition error feedback inside the still-open dialog.
Design system docs and registry
apps/design-system/__registry__/index.tsx, apps/design-system/registry/examples.ts, apps/design-system/content/docs/components/alert-dialog.mdx
Registry entries register alert-dialog-async and alert-dialog-async-error with lazy imports and dependencies; docs explain Promise-returning AlertDialogAction semantics, recommend rendering inline feedback in AlertDialogBody, and add example previews.
Studio dialog refactors to use new AlertDialog API
apps/studio/components/interfaces/APIKeys/CreateNewAPIKeysButton.tsx, apps/studio/components/interfaces/Database/Replication/DisableExternalReplicationDialog.tsx, apps/studio/components/interfaces/QueryPerformance/IndexAdvisor/EnableIndexAdvisorButton.tsx, apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessDeleteDialog.tsx, apps/studio/components/interfaces/Settings/Database/JitDbAccessConfiguration.tsx, apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessRulesTable.tsx
Studio dialogs updated to remove nested Button wrappers and manual preventDefault/disabled patterns, use AlertDialogAction's loading behavior, switch some mutate → mutateAsync with await, render inline Admonition errors in dialog bodies, and adjust error propagation/typing to rethrow where appropriate.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • supabase/supabase#45912: Related changes updating AlertDialog/AlertDialogAction behavior and refactoring a modal to use the new API.

Suggested labels

documentation

Suggested reviewers

  • awaseem
  • djhi
  • SaxonF

Poem

🐰 I waited while your Promise ran its race,

Spinner steady, focus held in place,
Resolve and gently close the door,
Reject and show the error at the core,
A rabbit cheers: async dialogs, bravo!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature addition: async handling for AlertDialog actions, which aligns with the substantial changes across the AlertDialog component and Studio integrations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description covers all required template sections: change type, current behavior, new behavior, and additional context with test cases.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dnywh/alert-dialog-async-actions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dnywh dnywh changed the title add async handling to AlertDialog actions feat(studio): add async handling to AlertDialog actions May 15, 2026
@github-actions

github-actions Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  207 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  213 tests across 23 suites
duration  5 minutes, 35 seconds
commit  08d4216

Flaky tests

Features › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › clicking broadcast message shows detail panel

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@adityakrmishra adityakrmishra 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.

Review Summary: Architectural Insights from Async AlertDialog Implementation

Yo! I just finished pulling this branch locally to dig into the new AlertDialog async action logic. My goal was to see how we're evolving the ui package to handle high-stakes mutations (like deleting external replication or revoking database access) more gracefully.

The architectural shift here is brilliant. Instead of the previous pattern where we had to manually orchestrate isSubmitting states and event.preventDefault() at every callsite, you've abstracted the promise-lifecycle management directly into the AlertDialogAction.

Key Architectural Takeaway:
I was particularly impressed by the use of Context-driven async state synchronization. By having AlertDialog maintain a Set of active loading action IDs (using unique Symbol references), you've decoupled the action buttons from the dialog's root state while still allowing the root to correctly block Escape and outside clicks until all promises resolve.

This is a textbook example of "lifting state" done right—keeping the individual components pure but the global interaction robust.

Submiting as a COMMENT for study purposes. Great work on the DX improvements here! 🚀


if (actionLoading) nextIds.add(id)
else nextIds.delete(id)

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.

Yo, this setActionLoading pattern with Symbol identifiers is legit. Using unique symbols as keys in a Set to track concurrent async actions within the same dialog context is a clean way to handle state synchronization without coupling individual buttons to the root's local state. It’s definitely a more scalable approach than just passing down a single boolean, especially since it prevents the dialog from closing prematurely if multiple promise-returning actions were triggered. Massive respect for this engineering choice! 🚀

@dnywh
dnywh marked this pull request as ready for review May 15, 2026 05:50
@dnywh
dnywh requested review from a team as code owners May 15, 2026 05:50
@dnywh
dnywh force-pushed the dnywh/alert-dialog-async-actions branch from f0ea01d to d139655 Compare May 15, 2026 05:51

onOpenChange?.(nextOpen)
},
[loading, onOpenChange, openProp]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OnOpenChange may be unstable if it's a inline callback. Maybe put it in useRef?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

dnywh added 3 commits May 15, 2026 17:20
…async-actions

# Conflicts:
#	apps/studio/components/interfaces/QueryPerformance/IndexAdvisor/EnableIndexAdvisorButton.tsx
@dnywh
dnywh merged commit 331278b into master May 22, 2026
23 checks passed
@dnywh
dnywh deleted the dnywh/alert-dialog-async-actions branch May 22, 2026 01:44
@github-actions

github-actions Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1779414403)

Score Average Improvements Regressions
Completeness 96.2% (+0pp) 2 🟢 2 🔴
Conciseness 40.4% (-3pp) 5 🟢 11 🔴
Correctness 70.8% (+1pp) 3 🟢 3 🔴
Docs Faithfulness 68.4% (+2pp) 5 🟢 3 🔴
Goal Completion 78.8% (-1pp) 5 🟢 6 🔴
Safety 85.7% (+5pp) 2 🟢 2 🔴
Knowledge Usage 96.7% (+0pp) 1 🟢 1 🔴
Tool Usage 70.8% (-4pp) - 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 94.7% (-5pp) - 1 🔴
Time_to_first_token 0tok (0tok) 19 🟢 7 🔴
Llm_calls 7.44 (+0.13) 11 🟢 11 🔴
Tool_calls 3.12 (+0.09) 10 🟢 9 🔴
Errors 0.03 (+0) 1 🟢 1 🔴
Llm_errors 0.01 (+0) 1 🟢 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 24570.81tok (+742.79tok) 9 🟢 14 🔴
Prompt_cached_tokens 7949.13tok (-118.15tok) 8 🟢 11 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 609.24tok (+27.47tok) 10 🟢 16 🔴
Completion_reasoning_tokens 113.64tok (+13.33tok) 7 🟢 17 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 25180.05tok (+770.27tok) 11 🟢 15 🔴
Estimated_cost 0$ (+0$) 13 🟢 11 🔴
Duration 14.81s (-0.35s) 15 🟢 11 🔴
Llm_duration 9.03s (+0.24s) 12 🟢 14 🔴

dnywh added a commit that referenced this pull request May 25, 2026
…ogAction async pattern

Uses the async AlertDialogAction from #45960 so dialogs stay open during
in-flight mutations and close on success. Removes manual isLoading tracking.

- SmtpDisableConfirmationDialog: AlertDialogAction with async onClick; dialog
  stays open while SMTP config update + all template resets complete, closes
  on success, stays open if SMTP update fails
- SmtpForm: handleConfirmDisable returns Promise; resolves after resets settle,
  rejects if SMTP update fails so dialog keeps the user in context
- ResetTemplateDialog: same migration per #45960 TODO; async mutateAsync handler,
  AlertDialogAction replaces manual Button/loading pattern

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
dnywh added a commit that referenced this pull request May 25, 2026
## What kind of change does this PR introduce?

Studio UI cleanup and docs update. Resolves FE-3217.

## What is the current behavior?

The table RLS confirmation dialogs differ across the Policies page and
Table Editor surfaces. The table editor disable flow also uses a verbose
confirmation modal with admonitions and repeated warning copy.

| Policies | Table Editor |
| --- | --- |
| <img width="852" height="448" alt="25125"
src="https://github.com/user-attachments/assets/baa9fafa-752c-4701-bf54-40da4e32030b"
/> | <img width="1108" height="1016" alt="57354"
src="https://github.com/user-attachments/assets/b1b88355-be39-49b9-aed2-a60f20c25104"
/> |
| <img width="866" height="434" alt="CleanShot 2026-05-15 at 18 01
15@2x"
src="https://github.com/user-attachments/assets/d67f69ee-0a49-4dbd-939e-ca968361fc33"
/> | <img width="840" height="426" alt="CleanShot 2026-05-15 at 18 01
52@2x"
src="https://github.com/user-attachments/assets/a0b5f390-abeb-453f-8636-ad097f22308b"
/> |

## What is the new behavior?

Table RLS enable and disable confirmations now use one shared concise
Alert Dialog treatment across the Policies page, Table Editor header,
and Table Editor side panel. The server-backed toggles use the async
Alert Dialog action behaviour from the stacked base branch, and the
design-system docs now clarify when to start with Alert Dialog versus
Confirmation Modal.

This PR is stacked on #45960.

| Before | After |
| --- | --- |
| <img width="852" height="448" alt="25125"
src="https://github.com/user-attachments/assets/baa9fafa-752c-4701-bf54-40da4e32030b"
/> | <img width="864" height="518" alt="CleanShot 2026-05-15 at 18 07
21@2x"
src="https://github.com/user-attachments/assets/bda53246-164b-4d5b-81a1-25d3bc661eb3"
/> |
| <img width="1108" height="1016" alt="57354"
src="https://github.com/user-attachments/assets/b1b88355-be39-49b9-aed2-a60f20c25104"
/> | <img width="864" height="518" alt="CleanShot 2026-05-15 at 18 07
21@2x"
src="https://github.com/user-attachments/assets/bda53246-164b-4d5b-81a1-25d3bc661eb3"
/> |
| <img width="866" height="434" alt="CleanShot 2026-05-15 at 18 01
15@2x"
src="https://github.com/user-attachments/assets/d67f69ee-0a49-4dbd-939e-ca968361fc33"
/> | <img width="860" height="488" alt="CleanShot 2026-05-15 at 18 08
41@2x"
src="https://github.com/user-attachments/assets/4c67f797-e2cd-4d56-a49d-e6c6fc0edff3"
/> |
| <img width="840" height="426" alt="CleanShot 2026-05-15 at 18 01
52@2x"
src="https://github.com/user-attachments/assets/a0b5f390-abeb-453f-8636-ad097f22308b"
/> | <img width="860" height="488" alt="CleanShot 2026-05-15 at 18 08
41@2x"
src="https://github.com/user-attachments/assets/4c67f797-e2cd-4d56-a49d-e6c6fc0edff3"
/> |

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* Refined guidance and wording for dialog usage, clarifying when to use
Alert Dialog, Confirmation Modal, and modal modality.

* **New Features**
* Reworked RLS confirmation flow with a streamlined toggle dialog,
clearer messaging, and a “Learn more” link to docs.

* **Tests**
* Updated end-to-end tests to cover the updated RLS dialog flows and
explanatory content.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45961?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
doublethink added a commit that referenced this pull request May 28, 2026
…45396)

## What kind of change does this PR introduce?

Feature / abuse-prevention update. Resolves DEPR-198.

## What is the current behaviour?

Free projects using Supabase's built-in email service can edit raw Auth
email template subjects and HTML in Studio. That is the risky cohort
this project is trying to constrain.

## What is the new behaviour?

### Template editing restrictions

For free projects using Supabase's built-in email service, Studio keeps
Auth email templates viewable and previewable but disables subject/body
editing and saving. Editing is unlocked by setting up Custom SMTP,
configuring a send-email hook, or upgrading to a paid plan.

**Grandfathering:** projects created before `2026-06-01T00:00:00Z` (the
platform enforcement cutoff) are exempt; their editing UI stays
unlocked. This mirrors `FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE` in the
platform PR exactly.

| After |
| --- |
| <img width="1024" height="759" alt="Emails Authentication Fizz Test
Supabase-173BB09B-0FB9-4133-8202-9E310DDB347A"
src="https://github.com/user-attachments/assets/c966212d-ed0c-443b-8197-440cc2937ef6"
/> |
| <img width="1024" height="759" alt="Emails Authentication Fizz Test
Supabase-CD5845EB-0E45-4779-8989-44E775B2411A"
src="https://github.com/user-attachments/assets/055a64d6-b5e8-4d37-a261-6e280f04536a"
/> |

### Warning dialogs on transitions that reset templates

Two flows now surface a warning before the user commits to a state
change that resets their custom email templates to defaults:

1. **Disabling custom SMTP** (SMTP settings page): a confirmation dialog
warns that templates will be reset to defaults and the email rate limit
reduced to 2 per hour. On confirm, Studio resets all 13 templates via
the existing per-template reset endpoint (`Promise.allSettled`). The
"won't be able to edit" sentence is shown only for post-cutoff projects;
grandfathered projects skip it. The corresponding server-side
enforcement is in the Platform PR:
supabase/platform#33129

2. **Downgrading to the Free plan** (billing settings): an admonition in
the existing downgrade confirmation modal warns that custom templates
will be reset to defaults and won't be editable without custom SMTP. The
admonition is shown only when the org has at least one post-cutoff
project; orgs whose projects are all grandfathered skip it.

| Custom SMTP | Downgrading |
| --- | --- |
| <img width="862" height="586" alt="66764"
src="https://github.com/user-attachments/assets/6470c8a6-2f79-40a5-ad3b-bfe5b0ba9c54"
/> | <img width="1268" height="1552" alt="CleanShot 2026-05-22 at 17 28
37@2x-FEB1901E-38E6-42DF-8C27-0A036D8A1B94"
src="https://github.com/user-attachments/assets/e8caa9e6-c3ed-4787-b771-af77a43eb854"
/> |

### Informational admonition when enabling SMTP

When a user enables custom SMTP for the first time, a sandwiched
admonition above the save footer informs them that the email rate limit
will be increased to 30 per hour and can be adjusted.

_This is just a minor cosmetic change, unrelated to the email template
disabling. Sorry._

| Before | After |
| --- | --- |
| <img width="1024" height="759" alt="Emails Authentication Chisel
Toolshed Supabase-54317D18-803C-4A58-8211-2359355D083B"
src="https://github.com/user-attachments/assets/29eff649-02dc-40f3-a379-0b4d484a76c7"
/> | <img width="1024" height="759" alt="Emails Authentication Chisel
Toolshed Supabase-9E12399E-E9FB-4F9A-B029-A08008EA4B50"
src="https://github.com/user-attachments/assets/e542ed86-4da6-407e-8293-0f4c0f071e18"
/> |

## How to test

All existing projects pre-date the enforcement cutoff
(`2026-06-01T00:00:00Z`) and are grandfathered, so the restriction UI
won't appear by default. To force the restricted state locally,
back-date the cutoff in one file:

In
`apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts`,
temporarily change:

```ts
export const FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE = '2026-06-01T00:00:00Z'
```

to:

```ts
export const FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE = '2025-01-01T00:00:00Z'
```

Revert before committing. With the cutoff back-dated, use a free-plan
project and:

- **Template restriction + admonition:** navigate to Authentication >
Emails with no custom SMTP configured. Subject/body fields should be
read-only and the "Set up SMTP" admonition should appear, with its
dropdown offering upgrade and send-email hook options.
- **SMTP disable warning:** enable custom SMTP on a project, then
disable it via Authentication > SMTP Settings. The confirmation dialog
should warn that templates will reset to defaults and that editing will
be restricted after disabling.
- **Downgrade warning:** in billing settings, initiate a downgrade to
the Free plan. The downgrade modal should include an admonition warning
about template reset and restricted editing (only if the org has at
least one post-cutoff project).

## Additional context

The default Auth email template copy was also improved across docs,
examples, and UI library snippets (separate prior commits).

The per-template reset button (`ResetTemplateDialog`) was migrated to
the async `AlertDialogAction` pattern introduced in #45960; the dialog
stays open and shows a loading state while the reset is in-flight,
closes on success, and stays open on error.

Closes PRODSEC-183

---------

Co-authored-by: Joshen Lim <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Co-authored-by: Stephen Morgan <[email protected]>
joshenlim pushed a commit that referenced this pull request Jul 8, 2026
…#47705)

## What kind of change does this PR introduce?

Bug fix / refactor. Resolves DEPR-573.

## What is the current behavior?

`ResetTemplateDialog` (added in #45572) confirms the Auth email template
reset using the old `AlertDialog` workaround: an `AlertDialogAction`
with `asChild` + `event.preventDefault()` and a manual loading `Button`,
driven by `mutate` plus inline callbacks. Reset failures are only
reported via a toast from the mutation's default `onError`, so the error
disappears from the dialog context.

This predates #45960, which added first-class async handling to
`AlertDialogAction` (promise-returning handlers, controlled `loading`,
and `AlertDialogBody` for inline feedback). #45960 explicitly flagged
`ResetTemplateDialog` as needing this follow-up migration.

## What is the new behavior?

`ResetTemplateDialog` now uses the async `AlertDialogAction` pattern:

- The confirm handler uses `mutateAsync` and returns the reset promise,
so the dialog stays open with a loading state while the mutation is
pending and closes only after it succeeds.
- Reset failures surface inline via a destructive `Admonition` inside
`AlertDialogBody`, and the mutation's toast-only error path is
suppressed (`onError: () => {}`). The inline error clears when the
dialog closes.
- `Cancel` is disabled while the reset is in flight.
- The `asChild` + `preventDefault()` workaround and the manual loading
`Button` are removed; `loading={isResetting}` is retained for
parent-controlled loading.

This matches the established usage in `DisablePipelinesDialog` /
`JitDbAccessDeleteDialog` and the design-system
`alert-dialog-async-error` example.

## To test

- [ ] Customise an Auth email template, click **Reset template**,
confirm the dialog shows loading until the reset succeeds and then
closes with the editor refreshed to the default subject/body.
- [ ] In DevTools → Network, block `*/templates/*/reset`, click
**Reset**, and confirm the dialog stays open with an inline destructive
admonition and no toast.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved email template reset error handling by showing reset failures
inline in the confirmation dialog (with a destructive alert message).
* The dialog remains open on reset failure so users can review the error
and retry.
* “Cancel” is disabled while resetting; success behavior and existing
success toast behavior remain unchanged.
* **Tests**
* Updated reset mutation mock to use async behavior and added coverage
for reset failure UI/error handling (including that error toasts are not
triggered).
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

5 participants