Skip to content

Refactor FormLayout.tsx — optimize conditions in update/create completion handlers #3870

@akanshaaa19

Description

@akanshaaa19

Summary

handleUpdateCompleted (lines 222–261) and handleCreateCompleted (lines 263–296) contain nearly identical conditional logic:

  1. Check for errors → delegate to customHandler or setErrorMessage
  2. Check isValid === false → set customError
  3. Else → run additionalQuery, set link, show notification, call afterSave

Both also share the saveOnPageChange || isSaveClick notification branching and the onSaveClick(false) cleanup.

Suggested approach

  • Extract the shared condition tree into a single helper (e.g. handleMutationCompleted) parameterized by the differences (mutation key, notification verb, link-setting logic).
  • Simplify the nested if/else if/else chain — consider early returns for error/invalid cases to flatten the nesting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions