Skip to content

Commit efad44f

Browse files
authored
Fix bank account not found error (#366)
* docs: propose updated theming approach * fix: resolve error for no bank account found in company onboarding
1 parent 4363532 commit efad44f

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/components/Company/BankAccount/BankAccount.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import { BankAccountList } from './BankAccountList/BankAccountList'
1010
import { BankAccountForm } from './BankAccountForm/BankAccountForm'
1111
import { BankAccountVerify } from './BankAccountVerify/BankAccountVerify'
1212
import { Flow } from '@/components/Flow/Flow'
13-
import type { BaseComponentInterface } from '@/components/Base'
13+
import { BaseComponent, type BaseComponentInterface } from '@/components/Base'
1414
import { useComponentDictionary } from '@/i18n/I18n'
1515

16-
export interface LocationsProps extends BaseComponentInterface<'Company.BankAccount'> {
16+
export interface BankAccountProps extends BaseComponentInterface<'Company.BankAccount'> {
1717
companyId: string
1818
}
1919

20-
export function BankAccount({ companyId, onEvent, dictionary }: LocationsProps) {
20+
function BankAccountFlow({ companyId, onEvent, dictionary }: BankAccountProps) {
2121
useComponentDictionary('Company.BankAccount', dictionary)
2222
const { data } = useBankAccountsGetSuspense({ companyId })
2323
const companyBankAccountList = data.companyBankAccountList!
2424
//Currently, we only support a single default bank account per company.
2525
const bankAccount = companyBankAccountList.length > 0 ? companyBankAccountList[0]! : null
2626

27-
const manageLocations = createMachine(
27+
const manageBankAccount = createMachine(
2828
bankAccount ? 'viewBankAccount' : 'addBankAccount',
2929
bankAccountStateMachine,
3030
(initialContext: BankAccountContextInterface) => ({
@@ -35,7 +35,15 @@ export function BankAccount({ companyId, onEvent, dictionary }: LocationsProps)
3535
showVerifiedMessage: false,
3636
}),
3737
)
38-
return <Flow machine={manageLocations} onEvent={onEvent} />
38+
return <Flow machine={manageBankAccount} onEvent={onEvent} />
39+
}
40+
41+
export function BankAccount(props: BankAccountProps) {
42+
return (
43+
<BaseComponent {...props}>
44+
<BankAccountFlow {...props} />
45+
</BaseComponent>
46+
)
3947
}
4048

4149
BankAccount.BankAccountList = BankAccountList

src/components/Company/BankAccount/BankAccountForm/BankAccountForm.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useBankAccountsCreateMutation } from '@gusto/embedded-api/react-query/bankAccountsCreate'
22
import { FormProvider, useForm } from 'react-hook-form'
33
import { zodResolver } from '@hookform/resolvers/zod'
4+
import { invalidateAllBankAccountsGet } from '@gusto/embedded-api/react-query/bankAccountsGet'
5+
import { useQueryClient } from '@tanstack/react-query'
46
import { Head } from './Head'
57
import type { BankAccountFormInputs } from './Form'
68
import { BankAccountFormSchema, Form } from './Form'
@@ -28,6 +30,7 @@ export function BankAccountForm(props: BankAccountFormProps & BaseComponentInter
2830
function Root({ companyId, className, children }: BankAccountFormProps) {
2931
useI18n('Company.BankAccount')
3032
const { onEvent, baseSubmitHandler } = useBase()
33+
const queryClient = useQueryClient()
3134

3235
const { mutateAsync: createBankAccount, isPending: isPendingCreate } =
3336
useBankAccountsCreateMutation()
@@ -43,6 +46,9 @@ function Root({ companyId, className, children }: BankAccountFormProps) {
4346
//Account type is always checking for company bank accounts
4447
request: { companyId, requestBody: { ...payload, accountType: 'Checking' } },
4548
})
49+
50+
await invalidateAllBankAccountsGet(queryClient)
51+
4652
onEvent(componentEvents.COMPANY_BANK_ACCOUNT_CREATED, companyBankAccount)
4753
})
4854
}

src/components/Company/DocumentSigner/DocumentSigner.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ import { documentSignerMachine } from './stateMachine'
66
import type { DocumentSignerContextInterface } from './useDocumentSigner'
77
import { SignatureForm } from './SignatureForm'
88
import { Flow } from '@/components/Flow/Flow'
9-
import type { BaseComponentInterface } from '@/components/Base'
9+
import { BaseComponent, type BaseComponentInterface } from '@/components/Base'
1010
import { useComponentDictionary } from '@/i18n/I18n'
1111

1212
export interface DocumentSignerProps extends BaseComponentInterface<'Company.DocumentList'> {
1313
companyId: string
1414
signatoryId?: string
1515
}
1616

17-
export const DocumentSigner = ({
18-
companyId,
19-
signatoryId,
20-
onEvent,
21-
dictionary,
22-
}: DocumentSignerProps) => {
17+
function DocumentSignerFlow({ companyId, signatoryId, onEvent, dictionary }: DocumentSignerProps) {
2318
useComponentDictionary('Company.DocumentList', dictionary)
2419
const {
2520
data: { signatoryList },
@@ -46,5 +41,13 @@ export const DocumentSigner = ({
4641
return <Flow machine={documentSigner} onEvent={onEvent} />
4742
}
4843

44+
export function DocumentSigner(props: DocumentSignerProps) {
45+
return (
46+
<BaseComponent {...props}>
47+
<DocumentSignerFlow {...props} />
48+
</BaseComponent>
49+
)
50+
}
51+
4952
DocumentSigner.DocumentList = DocumentList
5053
DocumentSigner.SignatureForm = SignatureForm

0 commit comments

Comments
 (0)