From fb6e9a0f319d5fe4bab59d8ea71a0288192c5fa4 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 12:09:00 +0100 Subject: [PATCH 1/6] feat(onboarding) - make work happen to load dynamic versions of basic information --- example/src/Onboarding.tsx | 3 +++ src/flows/Onboarding/api.ts | 17 +++++++++-------- src/flows/Onboarding/hooks.tsx | 5 +++-- src/flows/Onboarding/utils.ts | 11 +++++++++++ src/flows/types.ts | 1 + 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/example/src/Onboarding.tsx b/example/src/Onboarding.tsx index 3fd2b48f8..f14cd3e96 100644 --- a/example/src/Onboarding.tsx +++ b/example/src/Onboarding.tsx @@ -265,6 +265,9 @@ const OnboardingWithProps = ({ externalId={externalId} options={{ features: ['onboarding_reserves'], + jsonSchemaVersion: { + employment_basic_information: 'latest', + }, jsonSchemaVersionByCountry: { DEU: { contract_details: 1, diff --git a/src/flows/Onboarding/api.ts b/src/flows/Onboarding/api.ts index dc9c57d88..cac22a568 100644 --- a/src/flows/Onboarding/api.ts +++ b/src/flows/Onboarding/api.ts @@ -32,7 +32,7 @@ import { JSONSchemaFormType, FlowOptions, } from '@/src/flows/types'; -import { getContractDetailsSchemaVersion } from '@/src/flows/Onboarding/utils'; +import { getContractDetailsSchemaVersion, getBasicInformationSchemaVersion } from '@/src/flows/Onboarding/utils'; import { createHeadlessForm } from '@/src/common/createHeadlessForm'; import { countriesOptions } from '@/src/common/api/countries'; @@ -274,14 +274,15 @@ export const useBenefitOffersSchema = ( * Use this hook to create an employment * @returns */ -export const useCreateEmployment = () => { +export const useCreateEmployment = ( + options?: OnboardingFlowProps['options'], +) => { const { client } = useClient(); - // TODO: setting 1 as basic_information only supports v1 for now in the API - const jsonSchemaQueryParam = { - json_schema_version: 1, - }; return useMutation({ mutationFn: (payload: EmploymentCreateParams) => { + const jsonSchemaQueryParam = { + json_schema_version: getBasicInformationSchemaVersion(options), + }; return postCreateEmployment2({ client: client as Client, headers: { @@ -302,8 +303,8 @@ export const useUpdateEmployment = ( ) => { const { client } = useClient(); const jsonSchemaQueryParams = { - // TODO: setting 1 as basic_information only supports v1 for now in the API - employment_basic_information_json_schema_version: 1, + employment_basic_information_json_schema_version: + getBasicInformationSchemaVersion(options), contract_details_json_schema_version: getContractDetailsSchemaVersion(options, countryCode) || 1, }; diff --git a/src/flows/Onboarding/hooks.tsx b/src/flows/Onboarding/hooks.tsx index 21c884649..b44115c51 100644 --- a/src/flows/Onboarding/hooks.tsx +++ b/src/flows/Onboarding/hooks.tsx @@ -9,6 +9,7 @@ import { useStepState, Step } from '@/src/flows/useStepState'; import { disabledInviteButtonEmploymentStatus, getContractDetailsSchemaVersion, + getBasicInformationSchemaVersion, reviewStepAllowedEmploymentStatus, STEPS, STEPS_WITHOUT_SELECT_COUNTRY, @@ -233,7 +234,7 @@ export const useOnboarding = ({ }, }); - const createEmploymentMutation = useCreateEmployment(); + const createEmploymentMutation = useCreateEmployment(options); const updateEmploymentMutation = useUpdateEmployment( internalCountryCode as string, options, @@ -328,7 +329,7 @@ export const useOnboarding = ({ enabled: isBasicInformationDetailsEnabled, }, }, - jsonSchemaVersion: 1, + jsonSchemaVersion: getBasicInformationSchemaVersion(options), }); const annualGrossSalaryField = diff --git a/src/flows/Onboarding/utils.ts b/src/flows/Onboarding/utils.ts index 6f5c5a11e..12e34249f 100644 --- a/src/flows/Onboarding/utils.ts +++ b/src/flows/Onboarding/utils.ts @@ -77,3 +77,14 @@ export const getContractDetailsSchemaVersion = ( return requestedVersion; }; + +/** + * Gets the basic information schema version from options + * @param options - The flow options containing version configurations + * @returns The jsonSchemaVersion for basic information or default + */ +export const getBasicInformationSchemaVersion = ( + options: OnboardingFlowProps['options'], +): number | 'latest' => { + return options?.jsonSchemaVersion?.employment_basic_information || DEFAULT_VERSION; +}; diff --git a/src/flows/types.ts b/src/flows/types.ts index c1f5c438b..1df9f6680 100644 --- a/src/flows/types.ts +++ b/src/flows/types.ts @@ -97,6 +97,7 @@ export type FlowOptions = { }; benefit_offers_form_schema?: number; contractor_contract_details_form_schema?: number; + employment_basic_information?: number | 'latest'; }; }; From 92119bade14350cc15465a7990f2a8fa2fb4e7ad Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 12:43:04 +0100 Subject: [PATCH 2/6] correct docs --- src/flows/Onboarding/api.ts | 11 +++++--- src/flows/Onboarding/types.ts | 49 ++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/flows/Onboarding/api.ts b/src/flows/Onboarding/api.ts index cac22a568..69b85bec7 100644 --- a/src/flows/Onboarding/api.ts +++ b/src/flows/Onboarding/api.ts @@ -32,7 +32,10 @@ import { JSONSchemaFormType, FlowOptions, } from '@/src/flows/types'; -import { getContractDetailsSchemaVersion, getBasicInformationSchemaVersion } from '@/src/flows/Onboarding/utils'; +import { + getContractDetailsSchemaVersion, + getBasicInformationSchemaVersion, +} from '@/src/flows/Onboarding/utils'; import { createHeadlessForm } from '@/src/common/createHeadlessForm'; import { countriesOptions } from '@/src/common/api/countries'; @@ -278,11 +281,11 @@ export const useCreateEmployment = ( options?: OnboardingFlowProps['options'], ) => { const { client } = useClient(); + const jsonSchemaQueryParam = { + json_schema_version: getBasicInformationSchemaVersion(options), + }; return useMutation({ mutationFn: (payload: EmploymentCreateParams) => { - const jsonSchemaQueryParam = { - json_schema_version: getBasicInformationSchemaVersion(options), - }; return postCreateEmployment2({ client: client as Client, headers: { diff --git a/src/flows/Onboarding/types.ts b/src/flows/Onboarding/types.ts index 7355ad0cf..14d87b7d4 100644 --- a/src/flows/Onboarding/types.ts +++ b/src/flows/Onboarding/types.ts @@ -51,6 +51,26 @@ export type OnboardingRenderProps = { type OnboardingFeatures = 'onboarding_reserves'; +/** + * JSON schema version configuration for a specific country + */ +type CountryJsonSchemaVersion = { + /** + * @deprecated Use `jsonSchemaVersion.employment_basic_information` instead for global configuration. + * This country-specific override is no longer recommended. + * + * The json schema version to use for the basic information step by country. + * The default value is 1. + */ + employment_basic_information?: number; + /** + * The json schema version to use for the contract details step by country. + * This is used to override the json schema version for the contract details step by country. + * The default value is 1. + */ + contract_details?: number | 'latest'; +}; + export type OnboardingFlowProps = { /** * The country code to use for the onboarding. @@ -86,23 +106,40 @@ export type OnboardingFlowProps = { /** * The options to use for the onboarding. */ - options?: Omit & { + options?: Omit & { jsfModify?: { select_country?: JSFModify; basic_information?: JSFModify; contract_details?: JSFModify; benefits?: JSFModify; }; + /** + * The json schema version to use for the onboarding. + * These versions apply globally to all countries. + * For country-specific overrides (e.g., contract_details), use jsonSchemaVersionByCountry instead. + * The default value is 1. + */ + jsonSchemaVersion?: { + /** + * The json schema version to use for the basic information step. + * Applies globally to all countries. + * The default value is 1. + */ + employment_basic_information?: number | 'latest'; + /** + * The json schema version to use for the benefit offers step. + * This is used to override the json schema version for the benefit offers step. + * The default value is 1. + */ + benefit_offers_form_schema?: number | 'latest'; + }; /** * The json schema version to use for the onboarding by country. * This is used to override the json schema version for the onboarding by country. - * the old jsonSchemaVersion is not working well at the moment, don't use it for now. + * Current use case is to support contract_details */ jsonSchemaVersionByCountry?: { - [countryCode: string]: { - employment_basic_information?: number; - contract_details?: number | 'latest'; - }; + [countryCode: string]: CountryJsonSchemaVersion; }; /** * The features to use for the onboarding. From cc25c8c09c169b83e95aae2252c2a150ce38bd90 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 12:50:06 +0100 Subject: [PATCH 3/6] add benefits --- src/flows/Onboarding/api.ts | 27 ++++++++++----------------- src/flows/Onboarding/utils.ts | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/flows/Onboarding/api.ts b/src/flows/Onboarding/api.ts index 69b85bec7..5d7abcbb9 100644 --- a/src/flows/Onboarding/api.ts +++ b/src/flows/Onboarding/api.ts @@ -35,6 +35,7 @@ import { import { getContractDetailsSchemaVersion, getBasicInformationSchemaVersion, + getBenefitOffersSchemaVersion, } from '@/src/flows/Onboarding/utils'; import { createHeadlessForm } from '@/src/common/createHeadlessForm'; import { countriesOptions } from '@/src/common/api/countries'; @@ -235,14 +236,11 @@ export const useBenefitOffersSchema = ( fieldValues: FieldValues, options: OnboardingFlowProps['options'], ) => { - const jsonSchemaQueryParam = options?.jsonSchemaVersion - ?.benefit_offers_form_schema - ? { - json_schema_version: - options.jsonSchemaVersion.benefit_offers_form_schema, - } - : {}; const { client } = useClient(); + const jsonSchemaQueryParam = { + json_schema_version: getBenefitOffersSchemaVersion(options), + }; + return useQuery({ queryKey: ['benefit-offers-schema', employmentId], retry: false, @@ -346,22 +344,17 @@ export const useUpdateBenefitsOffers = ( }: UnifiedEmploymentUpsertBenefitOffersRequest & { employmentId: string; }) => { - const jsonSchemaQueryParam = options?.jsonSchemaVersion - ?.benefit_offers_form_schema - ? { - json_schema_version: - options.jsonSchemaVersion.benefit_offers_form_schema, - } - : {}; + const jsonSchemaQueryParam = { + json_schema_version: getBenefitOffersSchemaVersion(options), + }; + return putUpdateBenefitOffer({ client: client as Client, body: payload, path: { employment_id: employmentId, }, - query: { - ...jsonSchemaQueryParam, - }, + query: jsonSchemaQueryParam, }); }, }); diff --git a/src/flows/Onboarding/utils.ts b/src/flows/Onboarding/utils.ts index 12e34249f..4cf726e70 100644 --- a/src/flows/Onboarding/utils.ts +++ b/src/flows/Onboarding/utils.ts @@ -86,5 +86,20 @@ export const getContractDetailsSchemaVersion = ( export const getBasicInformationSchemaVersion = ( options: OnboardingFlowProps['options'], ): number | 'latest' => { - return options?.jsonSchemaVersion?.employment_basic_information || DEFAULT_VERSION; + return ( + options?.jsonSchemaVersion?.employment_basic_information || DEFAULT_VERSION + ); +}; + +/** + * Gets the benefit offers schema version from options + * @param options - The flow options containing version configurations + * @returns The jsonSchemaVersion for benefit offers or undefined if not set + */ +export const getBenefitOffersSchemaVersion = ( + options: OnboardingFlowProps['options'], +): number | 'latest' => { + return ( + options?.jsonSchemaVersion?.benefit_offers_form_schema || DEFAULT_VERSION + ); }; From e19d9658258b41fcf151951ac18583e5ca8e47b9 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 12:52:00 +0100 Subject: [PATCH 4/6] upgrade limits --- .sizelimit.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sizelimit.json b/.sizelimit.json index 032630516..2c87d676f 100644 --- a/.sizelimit.json +++ b/.sizelimit.json @@ -1,7 +1,7 @@ { "limits": { "total": 550000, - "totalGzip": 200000, + "totalGzip": 250000, "css": 150000, "cssGzip": 25000, "maxChunkSize": 50000, From aea5bd1eaba2673df11a0a561a3ad01b81c73c4b Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 13:00:10 +0100 Subject: [PATCH 5/6] add utils --- src/flows/Onboarding/tests/utils.test.ts | 47 +++++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/flows/Onboarding/tests/utils.test.ts b/src/flows/Onboarding/tests/utils.test.ts index a6f66e9e9..0fc83c124 100644 --- a/src/flows/Onboarding/tests/utils.test.ts +++ b/src/flows/Onboarding/tests/utils.test.ts @@ -1,4 +1,8 @@ -import { getContractDetailsSchemaVersion } from '../utils'; +import { + getBasicInformationSchemaVersion, + getBenefitOffersSchemaVersion, + getContractDetailsSchemaVersion, +} from '../utils'; describe('getContractDetailsSchemaVersion', () => { it('should return version 1 for all countries', () => { @@ -12,7 +16,6 @@ describe('getContractDetailsSchemaVersion', () => { jsonSchemaVersionByCountry: { DEU: { contract_details: 2, - employment_basic_information: 2, }, }, }; @@ -22,3 +25,43 @@ describe('getContractDetailsSchemaVersion', () => { expect(result).toEqual(2); }); }); + +describe('getBenefitOffersSchemaVersion', () => { + it('should return version 1 for all countries', () => { + const result = getBenefitOffersSchemaVersion(undefined); + + expect(result).toEqual(1); + }); + + it('should override external jsonSchemaVersion with version 2', () => { + const options = { + jsonSchemaVersion: { + benefit_offers_form_schema: 2, + }, + }; + + const result = getBenefitOffersSchemaVersion(options); + + expect(result).toEqual(2); + }); +}); + +describe('getBasicInformationSchemaVersion', () => { + it('should return version 1 for all countries', () => { + const result = getBasicInformationSchemaVersion(undefined); + + expect(result).toEqual(1); + }); + + it('should override external jsonSchemaVersion with version 2', () => { + const options = { + jsonSchemaVersion: { + employment_basic_information: 2, + }, + }; + + const result = getBasicInformationSchemaVersion(options); + + expect(result).toEqual(2); + }); +}); From 2a32b0413bd0336e915ed83c61358fe232b29aec Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 18 Mar 2026 13:06:13 +0100 Subject: [PATCH 6/6] add tests --- .../useOnboardingJsonSchemaVersion.test.tsx | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx b/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx index ad34fd7cc..dd1b1e19e 100644 --- a/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx +++ b/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx @@ -199,6 +199,73 @@ describe('useOnboarding jsonSchemaVersion', () => { }); }); }); + + it('should pass custom jsonSchemaVersion to basic information form', async () => { + const options = { + jsonSchemaVersion: { + employment_basic_information: 2, + }, + }; + const { result } = renderHook( + () => + useOnboarding({ + companyId: 'test-company-id', + countryCode: 'PRT', + employmentId: 'test-employment-id', + skipSteps: ['select_country'], + options, + }), + { wrapper: TestProviders }, + ); + await waitFor(() => { + expect(result.current.isLoading).toBe(false); + }); + await waitFor(() => { + expect(mockGetShowFormCountry).toHaveBeenCalled(); + }); + const call = mockGetShowFormCountry.mock.calls[0][0]; + expect(call.path).toEqual({ + country_code: 'PRT', + form: 'employment_basic_information', + }); + expect(call.query).toEqual({ + skip_benefits: true, + json_schema_version: 2, + }); + }); + + it('should pass custom benefit_offers_form_schema version to getShowSchema', async () => { + const options = { + jsonSchemaVersion: { + benefit_offers_form_schema: 2, + }, + }; + const { result } = renderHook( + () => + useOnboarding({ + companyId: 'test-company-id', + countryCode: 'PRT', + employmentId: 'test-employment-id', + skipSteps: ['select_country'], + options, + }), + { wrapper: TestProviders }, + ); + await waitFor(() => { + expect(result.current.isLoading).toBe(false); + }); + // Navigate to benefits step + act(() => { + result.current.goTo('benefits'); + }); + await waitFor(() => { + expect(mockGetShowSchema).toHaveBeenCalled(); + }); + const call = mockGetShowSchema.mock.calls[0][0]; + expect(call.query).toEqual({ + json_schema_version: 2, + }); + }); }); describe('useUpdateEmployment calls', () => {