Repository navigation
feat(studio): add auth email template reset flow - #45572
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR implements email template reset functionality across API types, domain/network layers, TemplateEditor UI, and tests. It adds a new ChangesEmail Template Reset Feature
Sequence DiagramsequenceDiagram
participant User
participant Editor as TemplateEditor
participant Dialog as AlertDialog
participant Mutation as ResetMutation
participant API as API Endpoint
participant Cache as React Query Cache
participant Toast as Sonner Toast
User->>Editor: view template with custom content
Editor->>Editor: show Reset button
User->>Editor: click reset button
Editor->>Dialog: open confirmation dialog
User->>Dialog: confirm reset action
Dialog->>Editor: on confirm callback
Editor->>Mutation: mutate with projectRef and template
Mutation->>API: POST /platform/auth/{ref}/templates/{template}/reset
API-->>Mutation: GoTrueConfigResponse with reset config
Mutation->>Cache: setQueryData for authConfig
Mutation->>Cache: invalidate authConfig no refetch
Mutation->>Cache: invalidate lint query async
Mutation->>Editor: on success with reset response
Editor->>Editor: reset form values from response
Editor->>Editor: update editor body from response
Editor->>Editor: clear unsaved changes state
Editor->>Toast: success notification
Toast-->>User: show success message
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
|
@dnywh btw this would be another example for async handling in AlertDialog haha if you recall the thread we had before - if we should bake that behaviour into the UI component |
|
@dnywh alrighty - code changes wise should be good now, just needs e2e testing when the BE changes are through 🙏 🙂 |
## Context Reworks the template variables section of an email template a little - Add a section header with docs button <img width="1112" height="133" alt="image" src="https://github.com/user-attachments/assets/34f27c81-a7d7-430c-b23b-f95bf6572c8c" /> - Refactor `AuthTemplatesValidation` to remove unnecessary description parsing logic in `TemplateEditor` - Update tooltip content to match [docs](https://supabase.com/docs/guides/local-development/customizing-email-templates#template-variables) - e.g `SiteURL`: Add inline link for configuration <img width="480" height="96" alt="image" src="https://github.com/user-attachments/assets/731312bd-e46b-4cd2-81e9-85a67c9e318e" /> - e.g `Token`: Mention that its swappable with `ConfirmationURL` if both parameters are available for use in the template (Counter example is the reauthentication template which there's only `Token` variable available) <img width="462" height="93" alt="image" src="https://github.com/user-attachments/assets/63017f28-3d84-4840-8217-ba113646b63b" /> <img width="262" height="122" alt="image" src="https://github.com/user-attachments/assets/e3450eb8-7ff5-4eec-920f-77bb5fd4f367" /> --------- Co-authored-by: Danny White <[email protected]>
ChrisChinchilla
left a comment
There was a problem hiding this comment.
From a docs perspective ✅
…ywh/auth-879-reset-email-template-defaults # Conflicts: # apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
joshenlim
left a comment
There was a problem hiding this comment.
Verified changes on preview!
Braintrust eval report
|
## 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 https://github.com/user-attachments/assets/1af66410-e9f9-4231-9c6d-fe650bd717a4 ## Additional context - [ ] Once #45572 is rebased onto this change, `ResetTemplateDialog` should use `AlertDialogAction loading={isResettingTemplate}` with a promise-returning reset handler instead of a plain loading `Button` in `AlertDialogFooter`. ## To test - [x] 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. - [x] 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. - [x] 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. - [x] Disable external replication and confirm the Alert Dialog stays open with loading until the mutation succeeds. - [x] 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. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45960) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Gildas Garcia <[email protected]>
…#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 -->
What kind of change does this PR introduce?
Feature. Resolves AUTH-879.
What is the current behavior?
Studio does not provide a way to reset an Auth email template back to the default subject and body once it has been customised.
What is the new behavior?
Studio shows a
Reset templateaction when Platform reports that the selected Auth email template subject or body has been customised. The action opens a confirmation dialog, calls the dedicated Platform reset endpoint, and refreshes the editor with the default subject and body returned by the API.The Auth config save/reset mutations now run their user-facing success handling before refreshing Auth lint data, so the success toast and local editor cleanup are not delayed by lint refetches.
Additional context
Depends on supabase/platform#32417.
Summary by CodeRabbit
New Features
Tests
Documentation