Repository navigation
feat(contract-document): scaffold the standalone ContractDocument flow #1319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jordividaller
merged 3 commits into
main
from
feat/pbyr-4779-contract-document-scaffold
Sep 16, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { ContractDocumentFlow } from '@remoteoss/remote-flows'; | ||
| import { RemoteFlows } from './RemoteFlows'; | ||
| import './css/main.css'; | ||
|
|
||
| export function ContractDocument() { | ||
| return ( | ||
| <RemoteFlows proxy={{ url: window.location.origin }}> | ||
| <div style={{ width: 640, padding: 20, margin: '80px auto' }}> | ||
| <ContractDocumentFlow | ||
| render={() => ( | ||
| <div className='onboarding-form-container'> | ||
| <h2>Create contract document</h2> | ||
| <p>To be continued…</p> | ||
| </div> | ||
| )} | ||
| /> | ||
| </div> | ||
| </RemoteFlows> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { useId } from 'react'; | ||
| import { ContractDocumentContext } from '@/src/flows/ContractDocument/context'; | ||
| import { useContractDocument } from '@/src/flows/ContractDocument/hooks'; | ||
| import { ContractDocumentFlowProps } from '@/src/flows/ContractDocument/types'; | ||
|
|
||
| /** | ||
| * Standalone contract-document flow: contract details, then contract preview. Mount it | ||
| * anywhere — it does not depend on the contractor onboarding flow. | ||
| */ | ||
| export const ContractDocumentFlow = ({ render }: ContractDocumentFlowProps) => { | ||
| const formId = useId(); | ||
| const contractDocumentBag = useContractDocument(); | ||
|
|
||
| return ( | ||
| <ContractDocumentContext.Provider value={{ formId, contractDocumentBag }}> | ||
| {render(contractDocumentBag)} | ||
| </ContractDocumentContext.Provider> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Contract Document Docs | ||
|
|
||
| Welcome to the Contract Document flow docs. | ||
|
|
||
| A standalone flow for creating a contractor's contract document — the contract details and | ||
| contract preview screens of contractor onboarding, mountable on their own. It does not depend | ||
| on the onboarding flow. | ||
|
|
||
| If you want these screens **inside** contractor onboarding, that is part of the | ||
| [Contractor Onboarding](../ContractorOnboarding/README.md) flow instead. | ||
|
|
||
| > **Work in progress.** This release ships the two-step shell only: the steps exist and can | ||
| > be navigated, but no form is rendered and no request is made yet. | ||
|
|
||
| # Table of Contents | ||
|
|
||
| - [Getting Started](#getting-started) | ||
| - [Full Example](#full-example) | ||
| - [Components API](#components-api) | ||
| - [ContractDocumentFlow](#contractdocumentflow) | ||
| - [The bag](#the-bag) | ||
|
|
||
| ## Getting Started | ||
|
|
||
| After installation, import the main CSS file in your application: | ||
|
|
||
| ```css | ||
| @import '@remoteoss/remote-flows/styles.css'; | ||
| ``` | ||
|
|
||
| ### Full Example | ||
|
|
||
| ```tsx | ||
| import { ContractDocumentFlow, RemoteFlows } from '@remoteoss/remote-flows'; | ||
|
|
||
| export function CreateContractDocument() { | ||
| return ( | ||
| <RemoteFlows auth={/* your token fetcher */}> | ||
| <ContractDocumentFlow | ||
| render={(contractDocumentBag) => { | ||
| const { stepState, back, next } = contractDocumentBag; | ||
|
|
||
| return ( | ||
| <> | ||
| <h2>{stepState.currentStep.name}</h2> | ||
| <button type='button' onClick={back}> | ||
| Back | ||
| </button> | ||
| <button type='button' onClick={next}> | ||
| Next | ||
| </button> | ||
| </> | ||
| ); | ||
| }} | ||
| /> | ||
| </RemoteFlows> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Components API | ||
|
|
||
| ### ContractDocumentFlow | ||
|
|
||
| | Prop | Type | Required | Description | | ||
| | -------- | -------------------- | -------- | ----------------------------------- | | ||
| | `render` | `(bag) => ReactNode` | Yes | Render prop receiving the flow bag. | | ||
|
|
||
| ## The bag | ||
|
|
||
| `useContractDocument()` is the headless equivalent of the render prop, for fully custom UIs. | ||
| Both surfaces expose the same bag: | ||
|
|
||
| | Key | Description | | ||
| | -------------- | ----------------------------------------------------------------------- | | ||
| | `stepState` | Current step (`contract_details` or `contract_preview`) and step count. | | ||
| | `steps` | Every step of the flow, in order, with its label. | | ||
| | `next` | Moves to the next step. | | ||
| | `back` | Moves to the previous step. | | ||
| | `goTo` | Moves to a specific step. | | ||
| | `fields` | Form fields for the current step. Empty for now. | | ||
| | `isLoading` | True while the flow is loading data. Always `false` for now. | | ||
| | `isSubmitting` | True while a submission is in flight. Always `false` for now. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { createContext, useContext } from 'react'; | ||
| import { useContractDocument } from '@/src/flows/ContractDocument/hooks'; | ||
|
|
||
| export const ContractDocumentContext = createContext<{ | ||
| formId: string | undefined; | ||
| contractDocumentBag: ReturnType<typeof useContractDocument> | null; | ||
| }>({ | ||
| formId: undefined, | ||
| contractDocumentBag: null, | ||
| }); | ||
|
|
||
| export const useContractDocumentContext = () => { | ||
| const context = useContext(ContractDocumentContext); | ||
| if (!context.formId || !context.contractDocumentBag) { | ||
| throw new Error( | ||
| 'useContractDocumentContext must be used within a ContractDocumentFlow', | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| formId: context.formId, | ||
| contractDocumentBag: context.contractDocumentBag, | ||
| } as const; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { Fields } from '@remoteoss/remote-json-schema-form-kit'; | ||
| import { ContractDocumentStepKeys } from '@/src/flows/ContractDocument/types'; | ||
| import { STEPS, STEPS_ARRAY } from '@/src/flows/ContractDocument/utils'; | ||
| import { useStepState } from '@/src/flows/useStepState'; | ||
|
|
||
| /** | ||
| * Headless hook powering the standalone contract-document flow: the contract details and | ||
| * contract preview screens of contractor onboarding, mountable on their own. | ||
| */ | ||
| export const useContractDocument = () => { | ||
| const { stepState, nextStep, previousStep, goToStep } = | ||
| useStepState<ContractDocumentStepKeys>(STEPS); | ||
|
|
||
| return { | ||
| /** | ||
| * Current step state containing the current step and total number of steps. | ||
| */ | ||
| stepState, | ||
| /** | ||
| * Every step of the flow, in order. | ||
| */ | ||
| steps: STEPS_ARRAY, | ||
| /** | ||
| * Moves to the next step. | ||
| */ | ||
| next: nextStep, | ||
| /** | ||
| * Moves to the previous step. | ||
| */ | ||
| back: previousStep, | ||
| /** | ||
| * Moves to a specific step. | ||
| */ | ||
| goTo: goToStep, | ||
| /** | ||
| * Form fields for the current step. | ||
| */ | ||
| fields: [] as Fields, | ||
| /** | ||
| * True while the flow is loading data. | ||
| */ | ||
| isLoading: false, | ||
| /** | ||
| * True while a submission is in flight. | ||
| */ | ||
| isSubmitting: false, | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export { ContractDocumentFlow } from './ContractDocumentFlow'; | ||
| export { useContractDocument } from './hooks'; | ||
| export type { | ||
| ContractDocumentFlowProps, | ||
| ContractDocumentStepKeys, | ||
| } from './types'; |
28 changes: 28 additions & 0 deletions
28
src/flows/ContractDocument/tests/ContractDocumentFlow.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { queryClient, TestProviders } from '@/src/tests/testHelpers'; | ||
| import { ContractDocumentFlow } from '@/src/flows/ContractDocument/ContractDocumentFlow'; | ||
|
|
||
| describe('ContractDocumentFlow', () => { | ||
| beforeEach(() => { | ||
| queryClient.clear(); | ||
| }); | ||
|
|
||
| it('renders the render prop on the contract details step', () => { | ||
| render( | ||
| <ContractDocumentFlow | ||
| render={({ stepState }) => ( | ||
| <> | ||
| <h2>Create contract document</h2> | ||
| <p>{stepState.currentStep.name}</p> | ||
| </> | ||
| )} | ||
| />, | ||
| { wrapper: TestProviders }, | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByRole('heading', { name: 'Create contract document' }), | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText('contract_details')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
43 changes: 43 additions & 0 deletions
43
src/flows/ContractDocument/tests/useContractDocument.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
| import { queryClient, TestProviders } from '@/src/tests/testHelpers'; | ||
| import { useContractDocument } from '@/src/flows/ContractDocument/hooks'; | ||
|
|
||
| describe('useContractDocument', () => { | ||
| beforeEach(() => { | ||
| queryClient.clear(); | ||
| }); | ||
|
|
||
| it('exposes the two-step shell', () => { | ||
| const { result } = renderHook(() => useContractDocument(), { | ||
| wrapper: TestProviders, | ||
| }); | ||
|
|
||
| expect(result.current.stepState.currentStep.name).toBe('contract_details'); | ||
| expect(result.current.stepState.totalSteps).toBe(2); | ||
| expect(result.current.steps).toEqual([ | ||
| { index: 0, name: 'contract_details', label: 'Contract Details' }, | ||
| { index: 1, name: 'contract_preview', label: 'Contract Preview' }, | ||
| ]); | ||
| expect(result.current.fields).toEqual([]); | ||
| expect(result.current.isLoading).toBe(false); | ||
| expect(result.current.isSubmitting).toBe(false); | ||
| }); | ||
|
|
||
| it('moves between steps with next, back and goTo', () => { | ||
| const { result } = renderHook(() => useContractDocument(), { | ||
| wrapper: TestProviders, | ||
| }); | ||
|
|
||
| act(() => result.current.next()); | ||
| expect(result.current.stepState.currentStep.name).toBe('contract_preview'); | ||
|
|
||
| act(() => result.current.next()); | ||
| expect(result.current.stepState.currentStep.name).toBe('contract_preview'); | ||
|
|
||
| act(() => result.current.back()); | ||
| expect(result.current.stepState.currentStep.name).toBe('contract_details'); | ||
|
|
||
| act(() => result.current.goTo('contract_preview')); | ||
| expect(result.current.stepState.currentStep.name).toBe('contract_preview'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import React from 'react'; | ||
| import { useContractDocument } from '@/src/flows/ContractDocument/hooks'; | ||
|
|
||
| export type ContractDocumentStepKeys = 'contract_details' | 'contract_preview'; | ||
|
|
||
| export type ContractDocumentFlowProps = { | ||
| render: ( | ||
| contractDocumentBag: ReturnType<typeof useContractDocument>, | ||
| ) => React.ReactNode; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Step } from '@/src/flows/useStepState'; | ||
| import { ContractDocumentStepKeys } from '@/src/flows/ContractDocument/types'; | ||
|
|
||
| export const STEPS: Record< | ||
| ContractDocumentStepKeys, | ||
| Step<ContractDocumentStepKeys> | ||
| > = { | ||
| contract_details: { index: 0, name: 'contract_details' }, | ||
| contract_preview: { index: 1, name: 'contract_preview' }, | ||
| }; | ||
|
|
||
| const STEP_LABELS: Record<ContractDocumentStepKeys, string> = { | ||
| contract_details: 'Contract Details', | ||
| contract_preview: 'Contract Preview', | ||
| }; | ||
|
|
||
| export const STEPS_ARRAY = Object.values(STEPS).map((step) => ({ | ||
| ...step, | ||
| label: STEP_LABELS[step.name], | ||
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.