Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/components/form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,23 @@ export function parseFormValuesToAPI(
formValues: Record<string, any> = {},
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 && !field.isVisible) {
return fieldValue !== undefined && fieldValue !== null;
}

// For all other fields, use the original truthy check
return !!fieldValue;
});

const parsedFormValues = filteredFields.reduce(
(acc, field) => {
Expand Down
247 changes: 169 additions & 78 deletions src/flows/Onboarding/hooks.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -60,6 +61,168 @@ const stepToFormSchemaMap: Record<
review: null,
};

const jsfByCountry = (
fields: ModifyConfig['fields'],
): { [key: string]: Record<string, unknown> } => {
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 (
<AnnualGrossSalary
desiredCurrency={company?.desired_currency || ''}
{...props}
/>
);
},
},
},
equity_compensation: {
...equityCompensationField,
presentation: {
calculateDynamicProperties: (
values: FieldValues,
field: JSFField,
) => {
const offerEquity =
values.equity_compensation?.offer_equity_compensation;
const equityCost = field?.meta?.cost;

return {
extra: (
<EquityPriceDetails
offerEquity={offerEquity}
equityCost={equityCost as $TSFixMe}
/>
),
};
},
},
},
},
}),
[
annualGrossSalaryField,
annualSalaryFieldPresentation,
company?.desired_currency,
equityCompensationField,
jsfModifyByCountry,
],
);

return customFields;
};

const getLoadingStates = ({
isLoadingBasicInformationForm,
isLoadingContractDetailsForm,
Expand Down Expand Up @@ -277,83 +440,11 @@ 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 (
<AnnualGrossSalary
desiredCurrency={company?.desired_currency || ''}
{...props}
/>
);
},
},
},
equity_compensation: {
...equityCompensationField,
presentation: {
calculateDynamicProperties: (
values: FieldValues,
field: JSFField,
) => {
const offerEquity =
values.equity_compensation?.offer_equity_compensation;
const equityCost = field?.meta?.cost;

return {
extra: (
<EquityPriceDetails
offerEquity={offerEquity}
equityCost={equityCost as $TSFixMe}
/>
),
};
},
},
},
},
}),
[
annualGrossSalaryField,
annualSalaryFieldPresentation,
company?.desired_currency,
equityCompensationField,
],
);
const customFields = useCustomFields({
options,
company,
countryCode: internalCountryCode,
});

const { data: contractDetailsForm, isLoading: isLoadingContractDetailsForm } =
useJSONSchema({
Expand Down
Loading