Skip to content

Commit b3df589

Browse files
authored
feat(contractor-onboarding) - add default legal entity (#727)
* feat(contractor-onboarding) - add default legal entity * reorder
1 parent 6c19bb3 commit b3df589

3 files changed

Lines changed: 96 additions & 40 deletions

File tree

example/src/ContractorOnboarding.tsx

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
TabsTrigger,
2424
TabsList,
2525
} from '@remoteoss/remote-flows/internals';
26+
import Flag from 'react-flagpack';
2627
import React, { useState } from 'react';
2728
import { RemoteFlows } from './RemoteFlows';
2829
import { AlertError } from './AlertError';
@@ -311,29 +312,46 @@ const OnBoardingRender = ({
311312

312313
return (
313314
<>
314-
<div className='steps-contractor-onboarding-navigation'>
315-
<ul>
316-
{STEPS.map((step, index) => (
317-
<li
318-
key={index}
319-
className={`step-contractor-onboarding-item ${index === currentStepIndex ? 'active' : ''}`}
320-
>
321-
{index + 1}. {step}
322-
</li>
323-
))}
324-
</ul>
325-
</div>
326-
327-
{contractorOnboardingBag.isLoading ? (
328-
<div className='contractor-onboarding-form-layout'>
329-
<p>Loading...</p>
315+
{contractorOnboardingBag.defaultLegalEntity && (
316+
<div className='contractor-onboarding-default-legal-entity'>
317+
<div className='text-sm text-[#27272A] flex items-center justify-center gap-2 uppercase mb-2 font-medium'>
318+
<Flag
319+
size='s'
320+
code={
321+
contractorOnboardingBag.defaultLegalEntity
322+
.country_code as string
323+
}
324+
/>
325+
{contractorOnboardingBag.defaultLegalEntity.name}
326+
</div>
330327
</div>
331-
) : (
332-
<MultiStepForm
333-
contractorOnboardingBag={contractorOnboardingBag}
334-
components={components}
335-
/>
336328
)}
329+
<Header />
330+
<Card className='px-0 py-0'>
331+
<div className='steps-contractor-onboarding-navigation'>
332+
<ul>
333+
{STEPS.map((step, index) => (
334+
<li
335+
key={index}
336+
className={`step-contractor-onboarding-item ${index === currentStepIndex ? 'active' : ''}`}
337+
>
338+
{index + 1}. {step}
339+
</li>
340+
))}
341+
</ul>
342+
</div>
343+
344+
{contractorOnboardingBag.isLoading ? (
345+
<div className='contractor-onboarding-form-layout'>
346+
<p>Loading...</p>
347+
</div>
348+
) : (
349+
<MultiStepForm
350+
contractorOnboardingBag={contractorOnboardingBag}
351+
components={components}
352+
/>
353+
)}
354+
</Card>
337355
</>
338356
);
339357
};
@@ -364,29 +382,26 @@ export const ContractorOnboardingWithProps = ({
364382
proxy={{ url: window.location.origin }}
365383
>
366384
<div className='contractor-onboarding-content'>
367-
<Header />
368-
<Card className='px-0 py-0'>
369-
<ContractorOnboardingFlow
370-
render={OnBoardingRender}
371-
employmentId={employmentId}
372-
externalId={externalId}
373-
options={{
374-
jsfModify: {
375-
contract_details: {
376-
fields: {
377-
'payment_terms.payment_terms_type': {
378-
'x-jsf-presentation': {
379-
Component: (props: JSFCustomComponentProps) => (
380-
<Switcher {...props} />
381-
),
382-
},
385+
<ContractorOnboardingFlow
386+
render={OnBoardingRender}
387+
employmentId={employmentId}
388+
externalId={externalId}
389+
options={{
390+
jsfModify: {
391+
contract_details: {
392+
fields: {
393+
'payment_terms.payment_terms_type': {
394+
'x-jsf-presentation': {
395+
Component: (props: JSFCustomComponentProps) => (
396+
<Switcher {...props} />
397+
),
383398
},
384399
},
385400
},
386401
},
387-
}}
388-
/>
389-
</Card>
402+
},
403+
}}
404+
/>
390405
</div>
391406
</RemoteFlows>
392407
</div>

src/common/api/legal-entities.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import { getIndexCompanyLegalEntities } from '@/src/client';
3+
import { Client } from '@/src/client/client';
4+
import { useClient } from '@/src/context';
5+
6+
/**
7+
* Hook to get the legal entities for a company
8+
* @param companyId - The company ID
9+
* @returns The legal entities
10+
*/
11+
export const useLegalEntities = (companyId: string) => {
12+
const { client } = useClient();
13+
return useQuery({
14+
queryKey: ['legal-entities'],
15+
queryFn: () =>
16+
getIndexCompanyLegalEntities({
17+
client: client as Client,
18+
path: {
19+
company_id: companyId,
20+
},
21+
}),
22+
select: (data) => data.data?.data?.legal_entities,
23+
enabled: !!companyId,
24+
});
25+
};
26+
27+
export const useDefaultLegalEntity = (companyId: string) => {
28+
const { data: legalEntities } = useLegalEntities(companyId);
29+
return legalEntities?.find((legalEntity) => legalEntity.is_default);
30+
};

src/flows/ContractorOnboarding/hooks.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
import { useUploadFile } from '@/src/common/api/files';
5959
import { dataURLtoFile } from '@/src/lib/files';
6060
import { useEmploymentQuery } from '@/src/common/api/employment';
61+
import { useDefaultLegalEntity } from '@/src/common/api/legal-entities';
6162

6263
type useContractorOnboardingProps = Omit<
6364
ContractorOnboardingFlowProps,
@@ -140,6 +141,10 @@ export const useContractorOnboarding = ({
140141
queryParams: { exclude_files: true },
141142
});
142143

144+
const defaultLegalEntity = useDefaultLegalEntity(
145+
employment?.company_id as string,
146+
);
147+
143148
const { status: employmentStatus } = employment || {};
144149

145150
const isEmploymentReadOnly =
@@ -982,5 +987,11 @@ export const useContractorOnboarding = ({
982987
* @returns {Employment}
983988
*/
984989
employment,
990+
991+
/**
992+
* Default legal entity
993+
* @returns {CompanyLegalEntity}
994+
*/
995+
defaultLegalEntity,
985996
};
986997
};

0 commit comments

Comments
 (0)