OpnForm icon indicating copy to clipboard operation
OpnForm copied to clipboard

Refactor form rendering

Open chiragchhatrala opened this issue 1 year ago • 1 comments

Summary by CodeRabbit

  • New Features
    • Introduced modular services for form initialization, validation, payment processing, and submission, providing a more structured and maintainable form experience.
  • Refactor
    • Replaced inline logic in form components with dedicated service classes, improving code organization and reliability.
  • Chores
    • Removed unused record loading logic from the form page, streamlining performance.

chiragchhatrala avatar Apr 18 '25 17:04 chiragchhatrala

Walkthrough

This update introduces a major refactor of the form handling logic in the client application. Core responsibilities such as form initialization, structure management, validation, payment processing, and submission are modularized into dedicated service classes: FormInitializationService, FormStructureService, FormValidationService, FormPaymentService, and FormSubmissionService. Components like OpenForm.vue and OpenCompleteForm.vue are updated to utilize these services, replacing extensive inline logic with service calls. Additional changes include the removal of direct record loading in the form page and the addition of comprehensive error handling and state management within the new service classes.

Changes

File(s) Change Summary
client/components/open/forms/OpenCompleteForm.vue Refactored to use new service classes for form initialization, validation, payment, and submission. Added initializeForm method, updated submitForm to async, and introduced a watcher on the form prop to trigger re-initialization.
client/components/open/forms/OpenForm.vue Refactored to delegate field grouping, page management, initialization, validation, and payment logic to new service classes. Replaced inline logic with service calls and updated method signatures accordingly. Added emitSubmit method for submission events.
client/pages/forms/[slug]/index.vue Removed logic that started record loading when a submission_id query parameter was present. No other changes to exported entities.
client/services/form/services/FormInitializationService.js New file introducing FormInitializationService class to manage form data initialization, including handling of default data, pending submissions, editable submissions, and URL parameter prefill. Provides multiple methods for applying and prioritizing data sources.
client/services/form/services/FormPaymentService.js New file introducing FormPaymentService class to manage Stripe payment processing within forms, including readiness checks, payment intent handling, error reporting, and busy state management.
client/services/form/services/FormStructureService.js New file introducing FormStructureService class to manage form structure, including field grouping by pages, page break management, payment block detection, field visibility, and drag-and-drop index calculations.
client/services/form/services/FormSubmissionService.js New file introducing FormSubmissionService class to manage form submission, including posting data, handling success/failure, analytics, UI feedback, and integration with parent windows or iframes.
client/services/form/services/FormValidationService.js New file introducing FormValidationService class to handle form validation, error navigation, scrolling, and logic validation for form properties. Includes methods for validating fields, handling errors, and managing UI responses to validation failures.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OpenFormComponent
    participant FormInitializationService
    participant FormStructureService
    participant FormValidationService
    participant FormPaymentService
    participant FormSubmissionService
    participant Server

    User->>OpenFormComponent: Loads form
    OpenFormComponent->>FormInitializationService: initializeForm()
    FormInitializationService->>Server: Fetch submission/pending data (if needed)
    FormInitializationService-->>OpenFormComponent: Set up form data

    User->>OpenFormComponent: Fills form, navigates pages
    OpenFormComponent->>FormStructureService: Get fields/pages info

    User->>OpenFormComponent: Submits form
    OpenFormComponent->>FormValidationService: validateCurrentPage()
    FormValidationService-->>OpenFormComponent: Validation result

    alt Payment required
        OpenFormComponent->>FormPaymentService: processPayment()
        FormPaymentService->>Server: Stripe payment processing
        FormPaymentService-->>OpenFormComponent: Payment result
    end

    OpenFormComponent->>FormSubmissionService: submit()
    FormSubmissionService->>Server: Post form data
    Server-->>FormSubmissionService: Submission response
    FormSubmissionService-->>OpenFormComponent: Handle success/failure

Possibly related PRs

  • JhumanJ/OpnForm#584: Refactors OpenCompleteForm.vue to delegate form submission to FormSubmissionService.submit(), which includes logic for showing the first submission modal, directly relating to the modularization and service-based approach introduced here.

Suggested reviewers

  • JhumanJ

Poem

In the warren, code hops anew,
Each service with a task to do—
Structure, payment, validation, too,
Submission handled, errors few.
Forms now prance with modular grace,
The bunnies cheer this tidy place!
🐇✨

[!TIP]

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 18 '25 17:04 coderabbitai[bot]

Closed in favor of https://github.com/JhumanJ/OpnForm/pull/747

JhumanJ avatar May 01 '25 10:05 JhumanJ