Skip to content

Commit a2ebe17

Browse files
authored
Merge branch 'main' into kw/fix/SDK-198
2 parents 6fc0cd6 + 591bf6a commit a2ebe17

File tree

3 files changed

+94
-19
lines changed

3 files changed

+94
-19
lines changed

src/components/Payroll/PayrollEditEmployee/PayrollEditEmployee.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEmployeesGetSuspense } from '@gusto/embedded-api/react-query/employeesGet'
2+
import { useEmployeePaymentMethodsGetBankAccountsSuspense } from '@gusto/embedded-api/react-query/employeePaymentMethodsGetBankAccounts'
23
import { usePayrollsUpdateMutation } from '@gusto/embedded-api/react-query/payrollsUpdate'
34
import type { PayrollEmployeeCompensationsType } from '@gusto/embedded-api/models/components/payrollemployeecompensationstype'
45
import type { PayrollUpdateEmployeeCompensations } from '@gusto/embedded-api/models/components/payrollupdate'
@@ -39,6 +40,9 @@ export const Root = ({
3940
const { LoadingIndicator, baseSubmitHandler } = useBase()
4041

4142
const { data: employeeData } = useEmployeesGetSuspense({ employeeId })
43+
const { data: bankAccountsList } = useEmployeePaymentMethodsGetBankAccountsSuspense({
44+
employeeId,
45+
})
4246
const memoizedEmployeeId = useMemo(() => [employeeId], [])
4347
const { preparedPayroll, paySchedule, isLoading } = usePreparedPayrollData({
4448
companyId,
@@ -50,6 +54,8 @@ export const Root = ({
5054

5155
const employee = employeeData.employee!
5256
const employeeCompensation = preparedPayroll?.employeeCompensations?.at(0)
57+
const bankAccounts = bankAccountsList.employeeBankAccountList || []
58+
const hasDirectDepositSetup = bankAccounts.length > 0
5359

5460
const transformEmployeeCompensation = ({
5561
paymentMethod,
@@ -103,6 +109,7 @@ export const Root = ({
103109
paySchedule={paySchedule}
104110
isOffCycle={preparedPayroll?.offCycle}
105111
withReimbursements={withReimbursements}
112+
hasDirectDepositSetup={hasDirectDepositSetup}
106113
/>
107114
)
108115
}

src/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.test.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,4 +1037,68 @@ describe('PayrollEditEmployeePresentation', () => {
10371037
})
10381038
})
10391039
})
1040+
1041+
describe('Payment Method Visibility Based on Direct Deposit Setup', () => {
1042+
it('shows payment method control when employee has direct deposit set up', () => {
1043+
renderWithProviders(
1044+
<PayrollEditEmployeePresentation {...defaultProps} hasDirectDepositSetup={true} />,
1045+
)
1046+
1047+
expect(screen.getByText('Payment method')).toBeInTheDocument()
1048+
expect(screen.getByLabelText('Direct deposit')).toBeInTheDocument()
1049+
expect(screen.getByLabelText('Check')).toBeInTheDocument()
1050+
})
1051+
1052+
it('hides payment method control when employee does not have direct deposit set up', () => {
1053+
renderWithProviders(
1054+
<PayrollEditEmployeePresentation {...defaultProps} hasDirectDepositSetup={false} />,
1055+
)
1056+
1057+
expect(screen.queryByText('Payment method')).not.toBeInTheDocument()
1058+
expect(screen.queryByLabelText('Direct deposit')).not.toBeInTheDocument()
1059+
expect(screen.queryByLabelText('Check')).not.toBeInTheDocument()
1060+
})
1061+
1062+
it('shows payment method control by default when hasDirectDepositSetup is not provided', () => {
1063+
const propsWithoutDirectDepositFlag = {
1064+
...defaultProps,
1065+
hasDirectDepositSetup: undefined,
1066+
}
1067+
1068+
renderWithProviders(<PayrollEditEmployeePresentation {...propsWithoutDirectDepositFlag} />)
1069+
1070+
expect(screen.getByText('Payment method')).toBeInTheDocument()
1071+
expect(screen.getByLabelText('Direct deposit')).toBeInTheDocument()
1072+
expect(screen.getByLabelText('Check')).toBeInTheDocument()
1073+
})
1074+
1075+
it('allows form submission without payment method when employee has no direct deposit', async () => {
1076+
const compensationWithCheckPayment = {
1077+
...mockEmployeeCompensation,
1078+
paymentMethod: PaymentMethods.Check,
1079+
}
1080+
1081+
renderWithProviders(
1082+
<PayrollEditEmployeePresentation
1083+
{...defaultProps}
1084+
hasDirectDepositSetup={false}
1085+
employeeCompensation={compensationWithCheckPayment}
1086+
/>,
1087+
)
1088+
1089+
const user = userEvent.setup()
1090+
const saveButton = screen.getByRole('button', { name: 'Save' })
1091+
await user.click(saveButton)
1092+
1093+
await waitFor(() => {
1094+
expect(defaultProps.onSave).toHaveBeenCalled()
1095+
})
1096+
1097+
expect(defaultProps.onSave).toHaveBeenCalledWith(
1098+
expect.objectContaining({
1099+
paymentMethod: PaymentMethods.Check,
1100+
}),
1101+
)
1102+
})
1103+
})
10401104
})

src/components/Payroll/PayrollEditEmployee/PayrollEditEmployeePresentation.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ interface PayrollEditEmployeeProps {
4949
paySchedule?: PayScheduleObject
5050
isOffCycle?: boolean
5151
withReimbursements?: boolean
52+
hasDirectDepositSetup?: boolean
5253
}
5354

5455
export const PayrollEditEmployeeFormSchema = z.object({
@@ -134,6 +135,7 @@ export const PayrollEditEmployeePresentation = ({
134135
paySchedule,
135136
isOffCycle = false,
136137
withReimbursements = true,
138+
hasDirectDepositSetup = true,
137139
}: PayrollEditEmployeeProps) => {
138140
const { Button, Heading, Text } = useComponentContext()
139141

@@ -475,25 +477,27 @@ export const PayrollEditEmployeePresentation = ({
475477
</Grid>
476478
</div>
477479
)}
478-
<div className={styles.fieldGroup}>
479-
<Heading as="h4">{t('paymentMethodTitle')}</Heading>
480-
<RadioGroupField
481-
name="paymentMethod"
482-
isRequired
483-
label={t('paymentMethodLabel')}
484-
description={t('paymentMethodDescription')}
485-
options={[
486-
{
487-
value: PayrollEmployeeCompensationsTypePaymentMethod.DirectDeposit,
488-
label: t('paymentMethodOptions.directDeposit'),
489-
},
490-
{
491-
value: PayrollEmployeeCompensationsTypePaymentMethod.Check,
492-
label: t('paymentMethodOptions.check'),
493-
},
494-
]}
495-
/>
496-
</div>
480+
{hasDirectDepositSetup && (
481+
<div className={styles.fieldGroup}>
482+
<Heading as="h4">{t('paymentMethodTitle')}</Heading>
483+
<RadioGroupField
484+
name="paymentMethod"
485+
isRequired
486+
label={t('paymentMethodLabel')}
487+
description={t('paymentMethodDescription')}
488+
options={[
489+
{
490+
value: PayrollEmployeeCompensationsTypePaymentMethod.DirectDeposit,
491+
label: t('paymentMethodOptions.directDeposit'),
492+
},
493+
{
494+
value: PayrollEmployeeCompensationsTypePaymentMethod.Check,
495+
label: t('paymentMethodOptions.check'),
496+
},
497+
]}
498+
/>
499+
</div>
500+
)}
497501
</Form>
498502
{!isSmallOrGreater && actions}
499503
</FormProvider>

0 commit comments

Comments
 (0)