Skip to content

Commit 4e04d27

Browse files
authored
feat(contractor-onboarding) - handle file uploads (#713)
* feat(contractor-onboarding) - handle file uploads * remove comment * fix performance degradation * add comment
1 parent 4aac5ec commit 4e04d27

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

example/src/ReviewOnboardingStep.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,22 @@ export function ReviewMeta({
121121

122122
// If this has a label and prettyValue, it's a field - render it
123123
if (label && prettyValue !== undefined && prettyValue !== '') {
124+
let displayValue;
125+
126+
// Handle file uploads (array of File objects)
127+
if (value?.inputType === 'file' && Array.isArray(prettyValue)) {
128+
displayValue = prettyValue
129+
.map((file: File) => file.name)
130+
.join(', ');
131+
}
124132
// Handle boolean prettyValue
125-
const displayValue =
126-
typeof prettyValue === 'boolean'
127-
? prettyValue
128-
? 'Yes'
129-
: 'No'
130-
: prettyValue;
133+
else if (typeof prettyValue === 'boolean') {
134+
displayValue = prettyValue ? 'Yes' : 'No';
135+
}
136+
// Handle other types
137+
else {
138+
displayValue = prettyValue;
139+
}
131140

132141
return (
133142
<pre key={key}>

src/flows/ContractorOnboarding/hooks.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,22 @@ export const useContractorOnboarding = ({
413413
[stepFields.select_country, internalCountryCode, employmentCountryCode],
414414
);
415415

416+
// memoize file conversion to avoid re-converting the file on every render
417+
// noticed performance issues when not doing memoizing individually
418+
const convertedIr35File = useMemo(() => {
419+
if (!ir35File?.content) return null;
420+
return dataURLtoFile(ir35File.content as unknown as string, ir35File.name);
421+
}, [ir35File?.content, ir35File?.name]);
422+
416423
const basicInformationInitialValues = useMemo(() => {
417424
const initialValues = {
418425
provisional_start_date: provisionalStartDate,
419426
...onboardingInitialValues,
420427
...employmentBasicInformation,
421428
ir35: employment?.contract_details?.ir_35,
422429
saudi_nationality_status: employment?.contract_details?.nationality,
423-
...(ir35File?.content && {
424-
ir35_sds_file: [
425-
dataURLtoFile(ir35File.content as unknown as string, ir35File.name),
426-
],
430+
...(convertedIr35File && {
431+
ir35_sds_file: [convertedIr35File],
427432
}),
428433
};
429434

@@ -433,7 +438,7 @@ export const useContractorOnboarding = ({
433438
employmentBasicInformation,
434439
employment?.contract_details?.ir_35,
435440
employment?.contract_details?.nationality,
436-
ir35File,
441+
convertedIr35File,
437442
stepFields.basic_information,
438443
]);
439444

0 commit comments

Comments
 (0)