From 16f7859d441a22f456c8e07abaada4336f742507 Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Mon, 28 Jul 2025 21:36:08 +0200 Subject: [PATCH 1/4] fix utils --- src/components/form/utils.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/form/utils.ts b/src/components/form/utils.ts index 6af81cf0..092392ee 100644 --- a/src/components/form/utils.ts +++ b/src/components/form/utils.ts @@ -286,11 +286,23 @@ export function parseFormValuesToAPI( formValues: Record = {}, fields: any[], ) { - const filteredFields = fields.filter( - (field) => - formValues[field.name!] || - (field.type === supportedTypes.FIELDSET && field.valueGroupingDisabled), - ); + const filteredFields = fields.filter((field) => { + const fieldValue = formValues[field.name!]; + + // Always include fieldsets with valueGroupingDisabled + if (field.type === supportedTypes.FIELDSET && field.valueGroupingDisabled) { + return true; + } + + // For number fields, include them even if the value is 0 or empty string + // The transformation will handle converting empty strings to appropriate values + if (field.type === supportedTypes.NUMBER) { + return fieldValue !== undefined && fieldValue !== null; + } + + // For all other fields, use the original truthy check + return !!fieldValue; + }); const parsedFormValues = filteredFields.reduce( (acc, field) => { From 95a35f422cd03a02bccec03e751caf36d17c895d Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 30 Jul 2025 12:55:02 +0200 Subject: [PATCH 2/4] fix custom fields --- src/flows/Onboarding/hooks.tsx | 247 +++++++++++++++++++++++---------- 1 file changed, 170 insertions(+), 77 deletions(-) diff --git a/src/flows/Onboarding/hooks.tsx b/src/flows/Onboarding/hooks.tsx index c3e08bcc..8fd5ef69 100644 --- a/src/flows/Onboarding/hooks.tsx +++ b/src/flows/Onboarding/hooks.tsx @@ -1,9 +1,10 @@ import { + Company, Employment, EmploymentCreateParams, EmploymentFullParams, } from '@/src/client'; -import { Fields } from '@remoteoss/json-schema-form'; +import { Fields, ModifyConfig } from '@remoteoss/json-schema-form'; import { useStepState, Step } from '@/src/flows/useStepState'; import { @@ -60,6 +61,168 @@ const stepToFormSchemaMap: Record< review: null, }; +const jsfByCountry = ( + fields: ModifyConfig['fields'], +): { [key: string]: Record } => { + const workHoursPerWeekField = fields?.work_hours_per_week; + return { + DOM: { + work_hours_per_week: { + ...workHoursPerWeekField, + presentation: { + calculateDynamicProperties: () => { + return { + value: 0, + }; + }, + }, + }, + }, + HND: { + work_hours_per_week: { + ...workHoursPerWeekField, + presentation: { + calculateDynamicProperties: () => { + return { + value: 0, + }; + }, + }, + }, + }, + KOR: { + work_hours_per_week: { + ...workHoursPerWeekField, + presentation: { + calculateDynamicProperties: () => { + return { + value: 0, + }; + }, + }, + }, + }, + MUS: { + work_hours_per_week: { + ...workHoursPerWeekField, + presentation: { + calculateDynamicProperties: () => { + return { + value: 0, + }; + }, + }, + }, + }, + VNM: { + work_hours_per_week: { + ...workHoursPerWeekField, + presentation: { + calculateDynamicProperties: () => { + return { + value: 0, + }; + }, + }, + }, + }, + }; +}; + +const useCustomFields = ({ + options, + company, + countryCode, +}: { + options: OnboardingHookProps['options']; + company?: Company; + countryCode: string | null; +}) => { + const fields = options?.jsfModify?.contract_details?.fields; + const jsfModifyByCountry = useMemo(() => { + return countryCode ? jsfByCountry(fields)[countryCode] || {} : {}; + }, [countryCode, fields]); + const annualGrossSalaryField = fields?.annual_gross_salary; + const annualSalaryFieldPresentation = + annualGrossSalaryField && + typeof annualGrossSalaryField === 'object' && + 'presentation' in annualGrossSalaryField + ? ( + annualGrossSalaryField as { + presentation?: { + annual_gross_salary_conversion_properties?: { + label?: string; + description?: string; + }; + }; + } + ).presentation + : undefined; + + const equityCompensationField = fields?.equity_compensation; + + const customFields = useMemo( + () => ({ + fields: { + ...jsfModifyByCountry, + annual_gross_salary: { + ...annualGrossSalaryField, + presentation: { + annual_gross_salary_conversion_properties: { + label: + annualSalaryFieldPresentation + ?.annual_gross_salary_conversion_properties?.label, + description: + annualSalaryFieldPresentation + ?.annual_gross_salary_conversion_properties?.description, + }, + desiredCurrency: company?.desired_currency, + Component: (props: JSFField & { currency: string }) => { + return ( + + ); + }, + }, + }, + equity_compensation: { + ...equityCompensationField, + presentation: { + calculateDynamicProperties: ( + values: FieldValues, + field: JSFField, + ) => { + const offerEquity = + values.equity_compensation?.offer_equity_compensation; + const equityCost = field?.meta?.cost; + + return { + extra: ( + + ), + }; + }, + }, + }, + }, + }), + [ + annualGrossSalaryField, + annualSalaryFieldPresentation, + company?.desired_currency, + equityCompensationField, + jsfModifyByCountry, + ], + ); + + return customFields; +}; + const getLoadingStates = ({ isLoadingBasicInformationForm, isLoadingContractDetailsForm, @@ -277,83 +440,13 @@ export const useOnboarding = ({ }, }); - const annualGrossSalaryField = - options?.jsfModify?.contract_details?.fields?.annual_gross_salary; - const annualSalaryFieldPresentation = - annualGrossSalaryField && - typeof annualGrossSalaryField === 'object' && - 'presentation' in annualGrossSalaryField - ? ( - annualGrossSalaryField as { - presentation?: { - annual_gross_salary_conversion_properties?: { - label?: string; - description?: string; - }; - }; - } - ).presentation - : undefined; - - const equityCompensationField = - options?.jsfModify?.contract_details?.fields?.equity_compensation; - - const customFields = useMemo( - () => ({ - fields: { - annual_gross_salary: { - ...annualGrossSalaryField, - presentation: { - annual_gross_salary_conversion_properties: { - label: - annualSalaryFieldPresentation - ?.annual_gross_salary_conversion_properties?.label, - description: - annualSalaryFieldPresentation - ?.annual_gross_salary_conversion_properties?.description, - }, - desiredCurrency: company?.desired_currency, - Component: (props: JSFField & { currency: string }) => { - return ( - - ); - }, - }, - }, - equity_compensation: { - ...equityCompensationField, - presentation: { - calculateDynamicProperties: ( - values: FieldValues, - field: JSFField, - ) => { - const offerEquity = - values.equity_compensation?.offer_equity_compensation; - const equityCost = field?.meta?.cost; + const customFields = useCustomFields({ + options, + company, + countryCode: internalCountryCode, + }); - return { - extra: ( - - ), - }; - }, - }, - }, - }, - }), - [ - annualGrossSalaryField, - annualSalaryFieldPresentation, - company?.desired_currency, - equityCompensationField, - ], - ); + console.log({ customFields }); const { data: contractDetailsForm, isLoading: isLoadingContractDetailsForm } = useJSONSchema({ From e03fabc0d7d25bbc8f81c1fa4d9791a00863813c Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 30 Jul 2025 13:01:09 +0200 Subject: [PATCH 3/4] fix utils --- src/components/form/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/form/utils.ts b/src/components/form/utils.ts index 08cd868c..b5825bac 100644 --- a/src/components/form/utils.ts +++ b/src/components/form/utils.ts @@ -296,7 +296,7 @@ export function parseFormValuesToAPI( // For number fields, include them even if the value is 0 or empty string // The transformation will handle converting empty strings to appropriate values - if (field.type === supportedTypes.NUMBER) { + if (field.type === supportedTypes.NUMBER && !field.isVisible) { return fieldValue !== undefined && fieldValue !== null; } From 92020380d3bebc8667ba0cd5e698ce30907f810d Mon Sep 17 00:00:00 2001 From: Gabriel Garcia Date: Wed, 30 Jul 2025 13:17:54 +0200 Subject: [PATCH 4/4] remove log --- src/flows/Onboarding/hooks.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/flows/Onboarding/hooks.tsx b/src/flows/Onboarding/hooks.tsx index 8fd5ef69..ee32a93a 100644 --- a/src/flows/Onboarding/hooks.tsx +++ b/src/flows/Onboarding/hooks.tsx @@ -446,8 +446,6 @@ export const useOnboarding = ({ countryCode: internalCountryCode, }); - console.log({ customFields }); - const { data: contractDetailsForm, isLoading: isLoadingContractDetailsForm } = useJSONSchema({ form: 'contract_details',