-
Notifications
You must be signed in to change notification settings - Fork 0
feat(preonboardings-requirements) - make employment readonly when shouldFreezeEmploymentData is true #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(preonboardings-requirements) - make employment readonly when shouldFreezeEmploymentData is true #1213
Changes from all commits
f2e2cd0
863a180
f73ffd3
3131855
ffd16a3
0310adf
839497e
69cfea7
20eaf22
110942d
0d44c2f
d4f935a
baa0df5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { FieldError, mutationToPromise } from '@/src/lib/mutations'; | |
| import { SuccessResponse } from '@/src/client'; | ||
| import { useOnboardingContext } from '@/src/flows/Onboarding/context'; | ||
| import { useFormFields } from '@/src/context'; | ||
| import { statusesWithReserveAlreadyHandled } from '@/src/flows/Onboarding/utils'; | ||
|
|
||
| export type OnboardingInviteProps = Omit< | ||
| ButtonHTMLAttributes<HTMLButtonElement>, | ||
|
|
@@ -56,15 +57,20 @@ export function OnboardingInvite({ | |
| onboardingBag.creditRiskStatus === 'deposit_required' || | ||
| onboardingBag.onboardingReservesStatus === 'deposit_required'; | ||
|
|
||
| const isReserveFlow = Boolean( | ||
| isDepositRequired && | ||
| onboardingBag.employment?.status && | ||
| !statusesWithReserveAlreadyHandled.includes( | ||
| onboardingBag.employment.status, | ||
| ), | ||
| ); | ||
|
|
||
| const shouldCreateReserve = Boolean(isReserveFlow && onboardingBag.canInvite); | ||
|
|
||
| const handleSubmit = async () => { | ||
| try { | ||
| await onSubmit?.(); | ||
| if ( | ||
| isDepositRequired && | ||
| onboardingBag.employmentId && | ||
| onboardingBag.employment?.status && | ||
| !onboardingBag.isEmploymentReadOnly | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we cannot rely anymore on the employment being readonly because that would mean that you cannot create a reserve if a preonboarding requirement has shouldFreezeEmploymentData |
||
| ) { | ||
| if (shouldCreateReserve && onboardingBag.employmentId) { | ||
| const response = await createReserveInvoiceMutationAsync({ | ||
| employment_slug: onboardingBag.employmentId, | ||
| }); | ||
|
|
@@ -121,11 +127,6 @@ export function OnboardingInvite({ | |
| } | ||
| }; | ||
|
|
||
| const isReserveFlow = | ||
| isDepositRequired && | ||
| onboardingBag.employment?.status && | ||
| !onboardingBag.isEmploymentReadOnly; | ||
|
|
||
| const CustomButton = components?.button; | ||
| if (!CustomButton) { | ||
| throw new Error(`Button component not found`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,8 @@ const getLoadingStates = ({ | |
| contractDetailsFields, | ||
| arePreOnboardingRequirementsFulfilled, | ||
| isLoadingOnboardingReservesStatus, | ||
| isLoadingPreOnboardingRequirements, | ||
| shouldFreezeEmploymentData, | ||
| }: { | ||
| isLoadingBasicInformationForm: boolean; | ||
| isLoadingContractDetailsForm: boolean; | ||
|
|
@@ -102,13 +104,15 @@ const getLoadingStates = ({ | |
| isLoadingCompany: boolean; | ||
| isLoadingCountries: boolean; | ||
| isLoadingEmploymentAgreementPreview: boolean; | ||
| isLoadingPreOnboardingRequirements: boolean; | ||
| employmentStatus?: Employment['status']; | ||
| employmentId?: string; | ||
| currentStepName: string; | ||
| basicInformationFields: JSFFields; | ||
| contractDetailsFields: JSFFields; | ||
| arePreOnboardingRequirementsFulfilled: boolean; | ||
| isLoadingOnboardingReservesStatus: boolean; | ||
| shouldFreezeEmploymentData: boolean; | ||
| }) => { | ||
| const initialLoading = | ||
| isLoadingBasicInformationForm || | ||
|
|
@@ -121,17 +125,22 @@ const getLoadingStates = ({ | |
| isLoadingCompany || | ||
| isLoadingCountries || | ||
| isLoadingEmploymentAgreementPreview || | ||
| isLoadingContractDetailsFormV1; | ||
| isLoadingContractDetailsFormV1 || | ||
| isLoadingPreOnboardingRequirements || | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we were missing some loadings here |
||
| isLoadingOnboardingReservesStatus; | ||
|
|
||
| // employment needs to be readonly if its one of the following conditions is met: | ||
| // - the employment status is in the review step allowed employment status list | ||
| // - the employment data is frozen by a pre-onboarding requirement | ||
| const isEmploymentReadOnly = | ||
| employmentStatus && | ||
| reviewStepAllowedEmploymentStatus.includes(employmentStatus); | ||
| (employmentStatus && | ||
| reviewStepAllowedEmploymentStatus.includes(employmentStatus)) || | ||
| shouldFreezeEmploymentData; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| const canInvite = | ||
| employmentStatus && | ||
| !disabledInviteButtonEmploymentStatus.includes(employmentStatus) && | ||
| arePreOnboardingRequirementsFulfilled && | ||
| !isLoadingOnboardingReservesStatus; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loading not needed here as we put it in the initialLoading |
||
| arePreOnboardingRequirementsFulfilled; | ||
|
|
||
| const shouldHandleReadOnlyEmployment = Boolean( | ||
| employmentId && isEmploymentReadOnly && currentStepName !== 'review', | ||
|
|
@@ -391,6 +400,10 @@ export const useOnboarding = ({ | |
| }, | ||
| }); | ||
|
|
||
| const shouldFreezeEmploymentData = Boolean( | ||
| requirements?.some((requirement) => requirement.freeze_employment_data), | ||
| ); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| const arePreOnboardingRequirementsFulfilled = useMemo(() => { | ||
| // While loading, block the invite | ||
| if (isLoadingPreOnboardingRequirements) { | ||
|
|
@@ -923,6 +936,7 @@ export const useOnboarding = ({ | |
| isLoadingEmployment, | ||
| isLoadingBenefitsOffersSchema, | ||
| isLoadingBenefitOffers, | ||
| isLoadingPreOnboardingRequirements, | ||
| isLoadingCompany, | ||
| isLoadingCountries, | ||
| isLoadingEmploymentAgreementPreview, | ||
|
|
@@ -933,6 +947,7 @@ export const useOnboarding = ({ | |
| currentStepName: currentStepName, | ||
| arePreOnboardingRequirementsFulfilled, | ||
| isLoadingOnboardingReservesStatus, | ||
| shouldFreezeEmploymentData, | ||
| }), | ||
| [ | ||
| isLoadingBasicInformationForm, | ||
|
|
@@ -942,6 +957,7 @@ export const useOnboarding = ({ | |
| isLoadingEmployment, | ||
| isLoadingBenefitsOffersSchema, | ||
| isLoadingBenefitOffers, | ||
| isLoadingPreOnboardingRequirements, | ||
| isLoadingCompany, | ||
| isLoadingCountries, | ||
| isLoadingEmploymentAgreementPreview, | ||
|
|
@@ -953,6 +969,7 @@ export const useOnboarding = ({ | |
| arePreOnboardingRequirementsFulfilled, | ||
| isLoadingOnboardingReservesStatus, | ||
| isLoadingContractDetailsFormV1, | ||
| shouldFreezeEmploymentData, | ||
| ], | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1319,16 +1319,10 @@ describe('OnboardingInvite', () => { | |
| }); | ||
|
|
||
| it('should keep button disabled during requirements loading to prevent race condition', async () => { | ||
| let resolveRequirements: (value: unknown) => void; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplified the test |
||
| const requirementsPromise = new Promise((resolve) => { | ||
| resolveRequirements = resolve; | ||
| }); | ||
|
|
||
| server.use( | ||
| http.get( | ||
| '*/v1/onboarding/employments/:employmentId/pre-onboarding-requirements', | ||
| '*/v1/onboarding/employments/*/pre-onboarding-requirements', | ||
| async () => { | ||
| await requirementsPromise; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| return HttpResponse.json({ | ||
| data: [ | ||
| { | ||
|
|
@@ -1352,11 +1346,6 @@ describe('OnboardingInvite', () => { | |
| await waitForElementToBeRemoved(() => screen.getByTestId('spinner')); | ||
|
|
||
| const inviteButton = screen.getByTestId('onboarding-invite'); | ||
| expect(inviteButton).toBeDisabled(); | ||
|
|
||
| await act(async () => { | ||
| resolveRequirements!({}); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(inviteButton).not.toBeDisabled(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.