Skip to content

fix: prevent add-invitation form from resetting on submission error - #5498

Open
imrja8 wants to merge 1 commit into
Dokploy:canaryfrom
imrja8:fix/add-invitation-form-reset
Open

imrja8 wants to merge 1 commit into
Dokploy:canaryfrom
imrja8:fix/add-invitation-form-reset

Conversation

@imrja8

@imrja8 imrja8 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

What is this PR about?

The Add user invitation form was resetting when a submission error occurred (e.g. "email already has an account"). This happened because the form reset logic relied on isSubmitSuccessful, which triggered even when errors were caught.

What has changed (Fixes):

  • Before: When an API error occurred during user creation, the form fields would instantly reset, switching back to the default "Invitation Link" view while the user was still trying to read the error toast.
  • After (With this PR): The form no longer resets on error. It stays exactly as the user left it (all dropdowns, emails, and passwords remain filled in). The user can simply correct the email address and hit "Create" again without having to start from scratch.

Why this matters (Intent)

When a user selects the "Initial Credentials" flow, their clear intent is to create a new user using an email and password. If they enter an email that already exists, it is most likely a typo or mistake. While surfacing the error toast is helpful, but changing the form from "Initial Credentials" to "Invitation Link" creates a jarring experience and forces the user to re-select "Initial Credentials" before they can try again.

This fix respects the user's original intent by preserving the form state, allowing them to quickly correct the email address and retry the creation without having to start over.

Technical changes made:

  • Changed the form reset logic to trigger when the dialog closes (!open) rather than on isSubmitSuccessful.
  • Changed the "Invite Method" and "Email Provider" dropdowns to use value={field.value} instead of defaultValue={field.value} so their visual state stays fully controlled and in sync with the form.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #5497

Screenshots / Validation Proofs

Before Explanation
before 1. Got error for existing user.

2. Selector shows initial credentials.

3. But form changed to invite link.
After Explanation
after 1. Got error for existing user.

2. Selector shows initial credentials.

3. Form stays in initial credentials state.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the revised lifecycle preserves failed input while still resetting the form after successful submissions and other dialog closures.

Summary

This PR corrects the add-invitation dialog lifecycle so failed submissions retain the user's inputs while closing the dialog resets the form and clears its error state.

  • Moves form reset behavior from submission status to dialog closure.
  • Keeps invite-method and email-provider selectors synchronized with React Hook Form by making them controlled.
  • Successful submission and cancellation paths still close and reset the dialog.

Reviews (1) · Last reviewed commit: "fix: correct add-invitation form reset l..."

@imrja8
imrja8 requested a review from Siumauricio as a code owner September 21, 2026 11:18
@imrja8

imrja8 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@narcisonunez this pr is ready for review.

This branch has not been deployed

No deployments
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.

Bug: add-invitation form resets state on API error but leaves Select component visually out of sync

1 participant