Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const hcmMock = gqlMock<HcmQuery, HcmQueryVariables>(HcmDocument, {
maximumContributionLimit: 45,
},
mhaRequest: {
currentApprovedOverallAmount: 10000,
currentTakenAmount: 500,
currentApprovedOverallAmount: 20000,
currentTakenAmount: 300,
},
exceptionSalaryCap: {
amount: null,
Expand All @@ -59,8 +59,8 @@ const hcmMock = gqlMock<HcmQuery, HcmQueryVariables>(HcmDocument, {
maximumContributionLimit: 47,
},
mhaRequest: {
currentApprovedOverallAmount: 12000,
currentTakenAmount: 800,
currentApprovedOverallAmount: 20000,
currentTakenAmount: 500,
},
exceptionSalaryCap: {
amount: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe('MhaRequestSection', () => {
const staffField = await findByTestId('current-mha-staff');
const spouseField = await findByTestId('current-mha-spouse');

expect(staffField).toHaveValue('$12,000');
expect(spouseField).toHaveValue('$19,200');
expect(staffField).toHaveValue('$7,200');
expect(spouseField).toHaveValue('$12,000');
});

it('should render new requested MHA input fields for both spouses', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export const MhaRequestSection: React.FC = () => {
schema,
totalRequestedMhaValue,
difference,
boardApprovedAmount,
approvedAmount,
progressPercentage,
currentTakenAmount,
currentApprovedSpouseAmountForStaff,
currentSpouseTakenAmount,
} = useMhaRequestData();

return (
Expand All @@ -72,12 +72,12 @@ export const MhaRequestSection: React.FC = () => {
<strong>
{hasSpouse
? t(
'You may request up to your Board-approved MHA amount of {{boardApprovedAmount}} combined.',
{ boardApprovedAmount },
'You may request up to your Board-approved MHA amount of {{approvedAmount}} combined.',
{ approvedAmount },
)
: t(
'You may request up to your Board Approved MHA Amount of {{boardApprovedAmount}}.',
{ boardApprovedAmount },
'You may request up to your Board Approved MHA Amount of {{approvedAmount}}.',
{ approvedAmount },
)}
</strong>{' '}
{t(
Expand Down Expand Up @@ -122,7 +122,7 @@ export const MhaRequestSection: React.FC = () => {
label={t('Current MHA')}
size="small"
fullWidth
value={currentApprovedSpouseAmountForStaff}
value={currentSpouseTakenAmount}
disabled
inputProps={{ 'data-testid': 'current-mha-spouse' }}
/>
Expand Down Expand Up @@ -160,7 +160,7 @@ export const MhaRequestSection: React.FC = () => {
{hasSpouse ? t('Combined MHA Requested') : t('New MHA Requested')}
</Typography>
<Typography variant="body2">
{totalRequestedMhaValue} / {boardApprovedAmount}
{totalRequestedMhaValue} / {approvedAmount}
</Typography>
</StyledProgressHeaderBox>
<LinearProgress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('useMhaRequestData', () => {
expect(result.current.hasSpouse).toBe(true);
});

expect(result.current.boardApprovedAmount).toBe('$22,000');
expect(result.current.currentTakenAmount).toBe('$12,000');
expect(result.current.currentApprovedSpouseAmountForStaff).toBe('$19,200');
expect(result.current.approvedAmount).toBe('$20,000');
expect(result.current.currentTakenAmount).toBe('$7,200');
expect(result.current.currentSpouseTakenAmount).toBe('$12,000');
});

it('should validate required fields and max amounts', async () => {
Expand All @@ -23,7 +23,7 @@ describe('useMhaRequestData', () => {
});

await waitFor(() => {
expect(result.current.boardApprovedAmount).toBe('$22,000');
expect(result.current.approvedAmount).toBe('$20,000');
});

const schema = result.current.schema;
Expand All @@ -33,15 +33,15 @@ describe('useMhaRequestData', () => {
).rejects.toThrow('MHA Amount is required');

await expect(
schema.validate({ mhaAmount: 15000, spouseMhaAmount: 5000 }),
schema.validate({ mhaAmount: 25000, spouseMhaAmount: 5000 }),
).rejects.toThrow(
'New Requested MHA cannot exceed Board Approved MHA Amount of $10,000',
'New Requested MHA cannot exceed Board Approved MHA Amount of $20,000',
);

await expect(
schema.validate({ mhaAmount: 5000, spouseMhaAmount: 15000 }),
schema.validate({ mhaAmount: 5000, spouseMhaAmount: 25000 }),
).rejects.toThrow(
'New Requested MHA cannot exceed Board Approved MHA Amount of $12,000',
'New Requested MHA cannot exceed Board Approved MHA Amount of $20,000',
);

await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,112 +13,95 @@

const hasSpouse = !!hcmSpouse;

const selfApprovedAmount =
hcmUser?.mhaRequest?.currentApprovedOverallAmount ?? 0;
const spouseApprovedAmount =
hcmSpouse?.mhaRequest?.currentApprovedOverallAmount ?? 0;

const selfApprovedAmountFormatted = useMemo(
() => currencyFormat(selfApprovedAmount, 'USD', locale),
[selfApprovedAmount, locale],
);
const spouseApprovedAmountFormatted = useMemo(
() => currencyFormat(spouseApprovedAmount, 'USD', locale),
[spouseApprovedAmount, locale],
const approvedAmount = hcmUser?.mhaRequest.currentApprovedOverallAmount ?? 0;
const approvedAmountFormatted = useMemo(
() => currencyFormat(approvedAmount, 'USD', locale),
[approvedAmount, locale],
);

const boardApprovedAmount = hasSpouse
? selfApprovedAmount + spouseApprovedAmount
: selfApprovedAmount;

const schema = useMemo(() => {
const baseSchema = {
mhaAmount: amount(t('New Requested MHA'), t)
.max(
selfApprovedAmount,
approvedAmount,
t(
`New Requested MHA cannot exceed Board Approved MHA Amount of ${selfApprovedAmountFormatted}`,
'New Requested MHA cannot exceed Board Approved MHA Amount of {{amount}}',
{ amount: approvedAmountFormatted },
),
)
.required(t('MHA Amount is required')),
};

if (hasSpouse) {
return yup.object({
...baseSchema,
spouseMhaAmount: amount(t('Spouse New Requested MHA'), t)
.max(
spouseApprovedAmount,
approvedAmount,
t(
`New Requested MHA cannot exceed Board Approved MHA Amount of ${spouseApprovedAmountFormatted}`,
'New Requested MHA cannot exceed Board Approved MHA Amount of {{amount}}',
{ amount: approvedAmountFormatted },
),
)
.required(t('Spouse MHA Amount is required')),
});
}

return yup.object(baseSchema);
}, [t, hasSpouse, selfApprovedAmount, spouseApprovedAmount]);
}, [t, hasSpouse, approvedAmount]);

// Multiply by 24 to annualize the monthly amounts from HCM
const currentAmountForStaff =
(hcmUser?.mhaRequest?.currentTakenAmount ?? 0) * 24;
(hcmUser?.mhaRequest.currentTakenAmount ?? 0) * 24;
const spouseCurrentAmountForStaff =
(hcmSpouse?.mhaRequest?.currentTakenAmount ?? 0) * 24;
(hcmSpouse?.mhaRequest.currentTakenAmount ?? 0) * 24;

const newRequestedMhaValue = calculation?.mhaAmount ?? 0;
const newRequestedSpouseMhaValue = calculation?.spouseMhaAmount ?? 0;
const totalRequestedMhaValue = useMemo(
() =>
hasSpouse
? newRequestedMhaValue + newRequestedSpouseMhaValue
: newRequestedMhaValue,
[hasSpouse, newRequestedMhaValue, newRequestedSpouseMhaValue],
);

const progressPercentage = useMemo(
() =>
boardApprovedAmount > 0
? (totalRequestedMhaValue / boardApprovedAmount) * 100
: 0,
[totalRequestedMhaValue, boardApprovedAmount],
approvedAmount > 0 ? (totalRequestedMhaValue / approvedAmount) * 100 : 0,
[totalRequestedMhaValue, approvedAmount],
);

const difference = useMemo(
() => boardApprovedAmount - totalRequestedMhaValue,
[boardApprovedAmount, totalRequestedMhaValue],
() => approvedAmount - totalRequestedMhaValue,
[approvedAmount, totalRequestedMhaValue],
);

const currentTakenAmountFormatted = useMemo(
() => currencyFormat(currentAmountForStaff, 'USD', locale),
[currentAmountForStaff, locale],
);
const currentApprovedSpouseAmountForStaffFormatted = useMemo(
const currentApprovedSpouseTakenAmountFormatted = useMemo(
() => currencyFormat(spouseCurrentAmountForStaff, 'USD', locale),
[spouseCurrentAmountForStaff, locale],
);
const totalRequestedMhaFormatted = useMemo(
() => currencyFormat(totalRequestedMhaValue, 'USD', locale),
[totalRequestedMhaValue, locale],
);
const boardApprovedAmountFormatted = useMemo(
() => currencyFormat(boardApprovedAmount, 'USD', locale),
[boardApprovedAmount, locale],
);
const differenceFormatted = useMemo(
() => currencyFormat(difference, 'USD', locale),
[difference, locale],
);

return {
hasSpouse,
schema,
currentTakenAmount: currentTakenAmountFormatted,
currentApprovedSpouseAmountForStaff:
currentApprovedSpouseAmountForStaffFormatted,
currentSpouseTakenAmount: currentApprovedSpouseTakenAmountFormatted,
totalRequestedMhaValue: totalRequestedMhaFormatted,
difference: differenceFormatted,
boardApprovedAmount: boardApprovedAmountFormatted,
approvedAmount: approvedAmountFormatted,

Check notice on line 104 in src/components/Reports/SalaryCalculator/YourInformation/MhaRequestSection/useMhaRequestData.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Complex Method

useMhaRequestData decreases in cyclomatic complexity from 15 to 9, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
progressPercentage,
};
};
Loading