Skip to content

feat: reworked final submission & added step resolution for edit & revision - #3456

Closed
chesterkmr wants to merge 3 commits into
devfrom
bal-4374-during-edit-mode-if-refresh-to-page-is-done-before-final
Closed

chesterkmr wants to merge 3 commits into
devfrom
bal-4374-during-edit-mode-if-refresh-to-page-is-done-before-final

Conversation

@chesterkmr

@chesterkmr chesterkmr commented Jun 26, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added new helper functions to manage and navigate steps in the collection flow, including marking previous steps as completed and finding the next step or revision/edit step.
  • Bug Fixes

    • Improved the logic for disabling navigation buttons, ensuring they are only disabled during syncing.
  • Refactor

    • Consolidated and streamlined the submission flow for collection steps, unifying async handling, error management, and redirect logic.
    • Updated state management to allow dynamic reinitialization and explicit state resets.
    • Removed legacy final submission logic and related UI state properties.
  • Chores

    • Updated internal dependencies for workflow data migrations.
  • Tests

    • Removed obsolete unit tests related to the previous final submission logic.

@changeset-bot

changeset-bot Bot commented Jun 26, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8f8fcc6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 26, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@chesterkmr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between acd1e22 and 8f8fcc6.

📒 Files selected for processing (2)
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx (4 hunks)
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts (1 hunks)

Walkthrough

This change removes the isFinalSubmitted property and all related logic from the Collection Flow UI and its state management. Submission handling is refactored to use a unified async handler. Several helper functions are introduced for step management. The state machine is now dynamically re-initializable, and the submit button respects a global disabled state.

Changes

File(s) Change Summary
.../AppShell/Navigation.tsx Navigation button disabling logic simplified to depend only on isSyncing; isFinalSubmitted check removed.
.../DynamicUI/StateManager/StateManager.tsx, .../types.ts State machine management refactored for dynamic reinitialization; new helper and callback for state resets added.
.../DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts Added effect to sync component state with machine state/context on machineApi changes.
.../DynamicUI/hooks/useUIStateLogic/types.ts, .../GlobalUIState/GlobalUIState.context.ts, .../GlobalUIState.tsx Removed isFinalSubmitted from UI state interfaces and initial state.
.../CollectionFlowUI/CollectionFlowUI.tsx Submission logic consolidated; removed final submission hook/state; added unified async handler and error handling.
.../CollectionFlowUI/helpers/complete-previous-steps.ts Added helper to mark previous steps as completed.
.../CollectionFlowUI/helpers/get-current-step.ts Added helper to get current step by name.
.../CollectionFlowUI/helpers/get-next-not-completed-step.ts Added helper to get next revision/edit step.
.../CollectionFlowUI/helpers/get-next-step.ts Added helper to get next step in sequence.
.../CollectionFlowUI/hooks/useFinalSubmission/index.ts, .../useFinalSubmission.ts, .../useFinalSubmission.unit.test.ts Removed re-export, implementation, and tests for the useFinalSubmission hook.
.../Form/DynamicForm/controls/SubmitButton/SubmitButton.tsx Submit button loader now respects a global disabled state from form context.
services/workflows-service/prisma/data-migrations Updated subproject commit reference.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CollectionFlowUI
    participant StateManager
    participant Helpers
    participant API

    User->>CollectionFlowUI: Click Submit
    CollectionFlowUI->>Helpers: completePreviousSteps, getNextStep, etc.
    CollectionFlowUI->>StateManager: Update context, mark steps completed
    CollectionFlowUI->>API: finalSubmissionRequest (if last step)
    API-->>CollectionFlowUI: Submission result
    CollectionFlowUI->>User: Redirect or show error
Loading

Possibly related PRs

  • ballerine-io/ballerine#3236: Removes all logic related to isFinalSubmitted, including the useFinalSubmission hook, directly overlapping with this PR's changes.
  • ballerine-io/ballerine#3306: Refactors submission logic in CollectionFlowUI, closely related to the submission handling refactor in this PR.
  • ballerine-io/ballerine#3218: Adds isFinalSubmitted flag and disables navigation controls, which this PR now removes, showing direct code-level linkage.

Suggested reviewers

  • tomer-shvadron
  • Omri-Levy

Poem

In fields of code where flows once grew,
The final flag has bid adieu.
Steps now march in ordered line,
Helpers new, their roles define.
Submissions glide with less ado—
The rabbit hops, the UI shines anew!
🐇✨

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🔭 Outside diff range comments (1)
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx (1)

130-131: Fix TypeScript error instead of using @ts-ignore.

The @ts-ignore comment suppresses a TypeScript error that should be properly addressed. This reduces type safety.

Would you like me to help identify and fix the underlying TypeScript issue?

🧹 Nitpick comments (2)
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts (1)

24-31: Remove console.log statement and consider dependency optimization.

The synchronization logic is correct and ensures the component state reflects the latest machine state. However, the console.log should be removed for production.

Apply this diff to remove the debug log:

useEffect(() => {
  setState(prev => ({
    ...prev,
    machineState: machineApi.getState(),
    payload: machineApi.getContext() as CollectionFlowContext,
  }));
-  console.log('new state', machineApi.getState());
}, [machineApi]);
apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/CollectionFlowUI.tsx (1)

155-169: Enhance error handling with more specific error messages.

The generic error message doesn't provide users with actionable information about what went wrong.

Consider providing more specific error messages based on the error type:

 } catch (error) {
   trackEvent(CollectionFlowEvents.FLOW_FAILED);
-  toast.error('Failed to submit form.');
+  const errorMessage = error instanceof Error 
+    ? `Failed to submit form: ${error.message}`
+    : 'Failed to submit form. Please try again.';
+  toast.error(errorMessage);
   console.error(error);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8d1a2 and 68b1a4f.

📒 Files selected for processing (18)
  • apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx (1 hunks)
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx (4 hunks)
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts (1 hunks)
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts (1 hunks)
  • apps/kyb-app/src/components/organisms/DynamicUI/hooks/useUIStateLogic/types.ts (0 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/CollectionFlowV2.tsx (1 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/CollectionFlowUI.tsx (6 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/complete-previous-steps.ts (1 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-current-step.ts (1 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-not-completed-step.ts (1 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-step.ts (1 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/index.ts (0 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/useFinalSubmission.ts (0 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/useFinalSubmission.unit.test.ts (0 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/providers/GlobalUIState/GlobalUIState.context.ts (0 hunks)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/providers/GlobalUIState/GlobalUIState.tsx (0 hunks)
  • packages/ui/src/components/organisms/Form/DynamicForm/controls/SubmitButton/SubmitButton.tsx (2 hunks)
  • services/workflows-service/prisma/data-migrations (1 hunks)
💤 Files with no reviewable changes (6)
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/providers/GlobalUIState/GlobalUIState.tsx
  • apps/kyb-app/src/components/organisms/DynamicUI/hooks/useUIStateLogic/types.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/index.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/providers/GlobalUIState/GlobalUIState.context.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/useFinalSubmission.unit.test.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/hooks/useFinalSubmission/useFinalSubmission.ts
🧰 Additional context used
📓 Path-based instructions (1)
`apps/kyb-app/**/*.{ts,tsx}`: Use functional components with TypeScript. Export ...

apps/kyb-app/**/*.{ts,tsx}: Use functional components with TypeScript.
Export components as named exports.
Place components in feature-based directories.
Use FunctionComponent type for React components.
Use strict TypeScript configuration.
Define interfaces for all props.
Export types and interfaces from separate files.
Use discriminated unions for complex state.
Use Tailwind CSS for styling.
Use ctw utility for conditional classes.
Keep styles close to components.
Use CSS modules for complex styling needs.
Group related files in feature directories.
Use index files for clean exports.
Use barrel exports for cleaner imports.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/kyb-app.mdc)

List of files the instruction was applied to:

  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts
  • apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-current-step.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/complete-previous-steps.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-step.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/CollectionFlowV2.tsx
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-not-completed-step.ts
  • apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/CollectionFlowUI.tsx
  • apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
services/workflows-service/prisma/data-migrations (2)

undefined

<retrieved_learning>
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.954Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.954Z
Learning: Use consistent naming conventions for related components (workflows, UI definitions, filters) in Ballerine migrations to improve maintainability and clarity.
</retrieved_learning>

apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts (2)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use discriminated unions for managing complex state shapes, and leverage TypeScript's type inference to reduce redundancy.
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts (7)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Extract business logic into custom React hooks, placing them in dedicated hooks directories and using the 'use' prefix for naming, to promote reusability and separation of concerns.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Favor local state (useState) for simple, component-specific state, and useReducer for more complex state logic.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Always use the 'use' prefix for custom React hooks to ensure they are recognized by React's rules of hooks.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/workflows-dashboard.mdc:0-0
Timestamp: 2025-06-24T09:37:03.176Z
Learning: Custom hooks in React should be single-purpose, follow the 'use' prefix naming convention, and be placed within feature directories for better organization and reusability.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: In the apps/backoffice-v2 React TypeScript codebase, always use functional components and TypeScript for all UI components to ensure consistency and type safety.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Use React Query for managing server state and data fetching, and React Context for global UI state, to separate concerns effectively.
apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx (1)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: In the apps/backoffice-v2 React TypeScript codebase, always use functional components and TypeScript for all UI components to ensure consistency and type safety.
packages/ui/src/components/organisms/Form/DynamicForm/controls/SubmitButton/SubmitButton.tsx (5)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Use React Hook Form for form handling, including validation and submission state management.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/workflows-dashboard.mdc:0-0
Timestamp: 2025-06-24T09:37:03.176Z
Learning: Using React Hook Form for forms enables robust validation, controlled inputs, and user feedback, which are essential for reliable form handling.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Hook Form for form state management and Zod for schema validation, providing clear validation feedback and handling form submission states.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Extract business logic into custom React hooks, placing them in dedicated hooks directories and using the 'use' prefix for naming, to promote reusability and separation of concerns.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Always use the 'use' prefix for custom React hooks to ensure they are recognized by React's rules of hooks.
apps/kyb-app/src/pages/CollectionFlow/versions/v2/CollectionFlowV2.tsx (4)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: In the apps/backoffice-v2 React TypeScript codebase, always use functional components and TypeScript for all UI components to ensure consistency and type safety.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Keep components small, focused, and handle edge cases and loading states appropriately for robust React applications.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: For complex UIs in React, use the compound component pattern to allow flexible composition and encapsulation of related subcomponents.
apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/CollectionFlowUI.tsx (16)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: In the apps/backoffice-v2 React TypeScript codebase, always use functional components and TypeScript for all UI components to ensure consistency and type safety.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Use React Hook Form for form handling, including validation and submission state management.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Hook Form for form state management and Zod for schema validation, providing clear validation feedback and handling form submission states.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Use React Query for managing server state and data fetching, and React Context for global UI state, to separate concerns effectively.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Prefer local component state for UI-only concerns, and always follow unidirectional data flow for predictable state management.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: For complex UIs in React, use the compound component pattern to allow flexible composition and encapsulation of related subcomponents.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Extract business logic into custom React hooks, placing them in dedicated hooks directories and using the 'use' prefix for naming, to promote reusability and separation of concerns.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Export both components and hooks as named exports to improve discoverability and enable easier refactoring.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/workflows-dashboard.mdc:0-0
Timestamp: 2025-06-24T09:37:03.176Z
Learning: In React TypeScript projects, using the container/presenter pattern helps separate business logic from UI rendering, improving maintainability and testability.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/workflows-dashboard.mdc:0-0
Timestamp: 2025-06-24T09:37:03.176Z
Learning: Custom hooks in React should be single-purpose, follow the 'use' prefix naming convention, and be placed within feature directories for better organization and reusability.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Always use the 'use' prefix for custom React hooks to ensure they are recognized by React's rules of hooks.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Compose hooks where possible, keeping each hook focused on a single responsibility to maximize reusability and testability.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Define interfaces for all component props in TypeScript to ensure type safety and self-documenting code.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/workflows-dashboard.mdc:0-0
Timestamp: 2025-06-24T09:37:03.176Z
Learning: Using React Hook Form for forms enables robust validation, controlled inputs, and user feedback, which are essential for reliable form handling.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Query for all server state management and API calls, leveraging its caching, loading, and error handling features.
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx (7)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use React Context for shared state that needs to be accessed by multiple components, and implement state machines for managing complex flows.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/kyb-app.mdc:0-0
Timestamp: 2025-06-24T09:36:16.103Z
Learning: Favor local state (useState) for simple, component-specific state, and useReducer for more complex state logic.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: In the apps/backoffice-v2 React TypeScript codebase, always use functional components and TypeScript for all UI components to ensure consistency and type safety.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Extract business logic into custom React hooks, placing them in dedicated hooks directories and using the 'use' prefix for naming, to promote reusability and separation of concerns.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Use discriminated unions for managing complex state shapes, and leverage TypeScript's type inference to reduce redundancy.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/backoffice-v2.mdc:0-0
Timestamp: 2025-06-24T09:35:48.294Z
Learning: Prefer local component state for UI-only concerns, and always follow unidirectional data flow for predictable state management.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.954Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
🧬 Code Graph Analysis (4)
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts (2)
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useMachineLogic/useMachineLogic.ts (1)
  • StateMachineAPI (7-13)
packages/workflow-core/src/lib/workflow-runner.ts (1)
  • state (98-100)
apps/kyb-app/src/components/organisms/DynamicUI/StateManager/hooks/useStateLogic/useStateLogic.ts (1)
apps/kyb-app/src/domains/collection-flow/types/flow-context.types.ts (1)
  • CollectionFlowContext (4-4)
apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/complete-previous-steps.ts (1)
packages/common/src/utils/collection-flow/enums/collection-flow-step-state-enum.ts (1)
  • CollectionFlowStepStatesEnum (1-8)
apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-not-completed-step.ts (1)
packages/common/src/utils/collection-flow/enums/collection-flow-step-state-enum.ts (1)
  • CollectionFlowStepStatesEnum (1-8)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: test_linux
  • GitHub Check: lint
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (9)
services/workflows-service/prisma/data-migrations (1)

1-1: Submodule bump – please verify downstream effects on DB state

The pointer advance to 493a222 may introduce new or reordered migration scripts.
Confirm that:

  1. All target environments (dev / staging / prod) apply the new migrations without drift.
  2. No destructive operations (DROP / TRUNCATE) were added that could break existing data.
  3. The relationship convention (workflowDefinitionId only, no extra junction tables) is still respected.

You can diff the two revisions to spot hazardous changes:

#!/bin/bash
# Compare old vs new migration contents
old=7886a698d221e48e4393f6a17e4f24e520a20d77   # previous pointer
new=493a22283db566fbcd5381e71c6709223950370b

git -C services/workflows-service/prisma/data-migrations fetch origin $old $new

git -C services/workflows-service/prisma/data-migrations diff --stat $old $new
git -C services/workflows-service/prisma/data-migrations diff $old $new -- '*.sql' '*.ts' | less
apps/kyb-app/src/components/layouts/AppShell/Navigation.tsx (1)

28-28: LGTM - Simplified disabled condition aligns with final submission refactor.

The removal of uiState.isFinalSubmitted check correctly aligns with the broader refactoring that eliminated final submission state management. The navigation button's disabled state is now appropriately controlled solely by the syncing state.

apps/kyb-app/src/components/organisms/DynamicUI/StateManager/types.ts (1)

13-15: LGTM - Well-structured interface extension for dynamic state management.

The interface extension properly adds the setCollectionFlowState method to the state API, enabling dynamic state machine reinitialization. The method signature is appropriate and maintains type safety.

apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-current-step.ts (1)

3-8: LGTM!

Clean and well-typed utility function.

packages/ui/src/components/organisms/Form/DynamicForm/controls/SubmitButton/SubmitButton.tsx (1)

24-24: LGTM! Proper integration of global disabled state.

The changes correctly incorporate the global disabled state into the submit button's behavior, ensuring the loader displays when the form is globally disabled.

Also applies to: 72-74

apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/helpers/get-next-not-completed-step.ts (1)

3-16: LGTM!

Well-implemented utility for finding the next step requiring revision or edit.

apps/kyb-app/src/pages/CollectionFlow/versions/v2/components/organisms/CollectionFlowUI/CollectionFlowUI.tsx (1)

53-53: Good refactoring of submission logic!

The consolidation of submission handling into a single function with explicit state management is a significant improvement. The addition of isSubmitting state and proper async handling enhances the user experience.

Also applies to: 115-182, 202-202

apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx (2)

40-169: Well-structured implementation of dynamic state machine management!

The refactoring to support dynamic state machine reinitialization is well-implemented. The component properly follows React best practices with appropriate use of hooks and memoization.


35-35: Let’s pull in the createWorkflow definition from the SDK to see how it applies workflowContext:

#!/bin/bash
# 1. Find the line number of createWorkflow in the SDK file
line=$(rg -n "createWorkflow" sdks/workflow-browser-sdk/src/lib/workflow-browser-sdk.ts | head -n1 | cut -d: -f2)

# 2. Dump the code around its definition
sed -n "$((line-10)),$((line+50))p" sdks/workflow-browser-sdk/src/lib/workflow-browser-sdk.ts

Comment thread apps/kyb-app/src/pages/CollectionFlow/versions/v2/CollectionFlowV2.tsx Outdated
additionalContext,
);
initialContext,
initialState: initialContext?.collectionFlow?.state?.currentStep!,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace non-null assertion with safe fallback.

The non-null assertion operator on the optional chain is risky and could cause runtime errors. Provide a fallback value for safety.

-      initialState: initialContext?.collectionFlow?.state?.currentStep!,
+      initialState: initialContext?.collectionFlow?.state?.currentStep ?? 'initial',
🤖 Prompt for AI Agents
In apps/kyb-app/src/components/organisms/DynamicUI/StateManager/StateManager.tsx
at line 58, replace the non-null assertion operator on
initialContext?.collectionFlow?.state?.currentStep! with a safe fallback value
to avoid potential runtime errors. Use a default value such as null or an
appropriate initial step when currentStep is undefined or null.

@chesterkmr
chesterkmr force-pushed the bal-4374-during-edit-mode-if-refresh-to-page-is-done-before-final branch from 68b1a4f to acd1e22 Compare June 29, 2025 09:07
Comment on lines +129 to +131
const nextStep = isEditOrRevision
? getNextRevisionOrEditStep(steps || [], page.stateName)
: getNextStep(steps || [], page.stateName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's neither of the statuses?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App will follow finalSubmission logic and will be resolved to Thank you page

if (!redirectUrls?.success) {
setIsSubmitting(false);
} else {
location.href = redirectUrls.success;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we using a router's method for updating the URL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Router not supporting 3rd party urls.

@alonp99 alonp99 closed this Jul 8, 2026

This branch was previously deployed

1 inactive deployment
Preview — 8f8fcc6f Deployed Jul 2, 2025 by vercel[bot]
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