Skip to content

Conversation

@codeunia-dev
Copy link
Owner

@codeunia-dev codeunia-dev commented Nov 21, 2025

This PR introduces a pre-registration validation check for companies and enhances the multi-step form experience by shifting submission control to an explicit button handler.


🔧 Key Changes

✔️ Pre-Registration Company Check

  • Added backend + UI logic to verify whether a company exists before continuing the registration flow.
  • Prevents duplicate company creation and ensures smoother onboarding.
  • Provides clear error messaging when a company already exists.

✔️ Multi-Step Form Enhancements

  • Replaced form auto-submit behavior with explicit onClick submission.
  • Provides better control over navigation between steps.
  • Reduces accidental submissions, especially in multi-step onboarding flows.

✔️ Code Cleanup & Refactor

  • Removed unused handlers.
  • Simplified state transitions between steps.
  • Improved reliability and clarity of the registration process.

🎯 Impact

  • Prevents multi-company duplication issues.
  • Improves user experience during onboarding.
  • Makes form submission logic more predictable and maintainable.

Authored by: @akshay0611

Summary by CodeRabbit

  • New Features
    • Registration page checks for existing company ownership and intelligently redirects based on company status: rejected companies return to the resubmit flow, while pending or verified companies redirect to the main application.
    • Form submission is now restricted to the final registration step, with Enter key submission disabled on earlier steps.

✏️ Tip: You can customize this high-level summary in your review settings.

… form submission logic to prevent early submission.
…prevent default `Enter` key form submission.
@vercel
Copy link

vercel bot commented Nov 21, 2025

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

Project Deployment Preview Comments Updated (UTC)
codeunia Building Building Preview Comment Nov 21, 2025 7:33am

@codeunia-dev codeunia-dev merged commit 8e2e80f into main Nov 21, 2025
2 of 4 checks passed
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The PR adds pre-emptive flow control to the company registration page that checks for existing company ownership on initial render and redirects users based on company status. The registration form submission logic is modified to restrict form submission to the final step with Enter key protection. A trailing space is introduced in the verification_document field name when appending to FormData.

Changes

Cohort / File(s) Summary
Registration Page Pre-check
app/companies/register/page.tsx
Adds useEffect hook that calls /api/companies/me on mount to check for existing owner-owned company. Redirects to resubmit flow if status is "rejected", navigates to /protected if "pending" or "verified", and allows form rendering otherwise. Includes guards for resubmit flow and missing user context.
Form Submission Control
components/companies/CompanyRegistrationForm.tsx
Restricts form submission to occur only on final step via handleSubmit guard function. Blocks Enter key form submission unless on final step. Changes final step submit button from type="submit" to type="button" wired to handleSubmit. Introduces trailing space in verification_document input name when appending to FormData.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RegPage as Register Page
    participant API as /api/companies/me
    participant RegForm as Registration Form
    participant NavService as Navigation

    User->>RegPage: Navigate to /companies/register
    RegPage->>RegPage: useEffect triggered (initial render)
    RegPage->>API: Check for existing company
    API-->>RegPage: Return owner companies
    
    alt Rejected Status
        RegPage->>NavService: Redirect to /companies/register?resubmitId=X
    else Pending or Verified Status
        RegPage->>RegPage: Show toast notification
        RegPage->>NavService: Navigate to /protected
    else No Valid Company
        RegPage->>RegForm: Render registration form
        User->>RegForm: Fill multi-step form
        User->>RegForm: Press Enter (non-final step)
        RegForm->>RegForm: Submission blocked
        User->>RegForm: Click Submit on Final Step
        RegForm->>RegForm: handleSubmit fires (type=button)
        RegForm->>API: Submit form data
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Extra attention areas:
    • Verify useEffect dependency array correctly prevents infinite loops and fires only on mount
    • Confirm API error handling doesn't break form rendering or cause silent failures
    • Review the trailing space in verification_document field name—confirm if intentional or if this causes backend field mismatch
    • Ensure form submission logic correctly gates submission to final step without breaking multi-step state transitions
    • Validate that Enter key prevention doesn't interfere with accessibility patterns

Possibly related PRs

Poem

🐰 A rabbit hops through forms so grand,
Step by step through registration land,
"Not yet, dear friend!" it warns with glee,
When Enter seeks to rush the spree,
Only the final step breaks free! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/companyregisterationflow

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbb0e24 and 234cca3.

📒 Files selected for processing (2)
  • app/companies/register/page.tsx (1 hunks)
  • components/companies/CompanyRegistrationForm.tsx (4 hunks)

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.

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.

3 participants