Skip to content

Commit 162b8ca

Browse files
feat: Add ACH related hooks (#3662)
1 parent a910857 commit 162b8ca

File tree

22 files changed

+540
-23
lines changed

22 files changed

+540
-23
lines changed

src/pages/PlanPage/subRoutes/CancelPlanPage/CancelPlanPage.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useAvailablePlans,
1010
usePlanData,
1111
} from 'services/account'
12+
import { Provider } from 'shared/api/helpers'
1213
import { BillingRate, shouldDisplayTeamCard } from 'shared/utils/billing'
1314
import Spinner from 'ui/Spinner'
1415

@@ -25,7 +26,7 @@ const Loader = () => (
2526

2627
function CancelPlanPage() {
2728
const { provider, owner } = useParams<{
28-
provider: string
29+
provider: Provider
2930
owner: string
3031
}>()
3132
const { data: accountDetailsData } = useAccountDetails({ provider, owner })

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/BillingDetails.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useParams } from 'react-router-dom'
22

33
import { useAccountDetails } from 'services/account'
4+
import { Provider } from 'shared/api/helpers'
45

56
import AddressCard from './Address/AddressCard'
67
import EmailAddress from './EmailAddress'
78
import PaymentCard from './PaymentCard'
89

910
interface URLParams {
10-
provider: string
11+
provider: Provider
1112
owner: string
1213
}
1314

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/EmailAddress/EmailAddress.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useParams } from 'react-router-dom'
55
import { z } from 'zod'
66

77
import { useAccountDetails, useUpdateBillingEmail } from 'services/account'
8+
import { Provider } from 'shared/api/helpers'
89
import A from 'ui/A'
910
import Button from 'ui/Button'
1011
import Icon from 'ui/Icon'
@@ -18,7 +19,7 @@ const emailSchema = z.object({
1819
})
1920

2021
interface URLParams {
21-
provider: string
22+
provider: Provider
2223
owner: string
2324
}
2425

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom'
33

44
import { usePlanUpdatedNotification } from 'pages/PlanPage/context'
55
import { useAccountDetails, usePlanData } from 'services/account'
6+
import { Provider } from 'shared/api/helpers'
67
import { getScheduleStart } from 'shared/plan/ScheduledPlanDetails/ScheduledPlanDetails'
78
import A from 'ui/A'
89
import { Alert } from 'ui/Alert'
@@ -16,7 +17,7 @@ import LatestInvoiceCard from './LatestInvoiceCard'
1617
import { EnterpriseAccountDetailsQueryOpts } from './queries/EnterpriseAccountDetailsQueryOpts'
1718

1819
interface URLParams {
19-
provider: string
20+
provider: Provider
2021
owner: string
2122
}
2223

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentPlanCard/CurrentPlanCard.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { useParams } from 'react-router-dom'
22

33
import { useAccountDetails, usePlanData } from 'services/account'
4+
import { Provider } from 'shared/api/helpers'
45
import { CollectionMethods } from 'shared/utils/billing'
56

67
import EnterprisePlanCard from './EnterprisePlanCard'
78
import FreePlanCard from './FreePlanCard'
89
import PaidPlanCard from './PaidPlanCard'
910

1011
interface URLParams {
11-
provider: string
12+
provider: Provider
1213
owner: string
1314
}
1415

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentPlanCard/PaidPlanCard/PaidPlanCard.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { useParams } from 'react-router-dom'
44

55
import { PlanPageDataQueryOpts } from 'pages/PlanPage/queries/PlanPageDataQueryOpts'
66
import { useAccountDetails, usePlanData } from 'services/account'
7+
import { Provider } from 'shared/api/helpers'
78
import BenefitList from 'shared/plan/BenefitList'
89
import ScheduledPlanDetails from 'shared/plan/ScheduledPlanDetails'
910

1011
import ActionsBilling from '../shared/ActionsBilling/ActionsBilling'
1112
import PlanPricing from '../shared/PlanPricing'
1213

1314
type URLParams = {
14-
provider: string
15+
provider: Provider
1516
owner: string
1617
}
1718

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/ProPlanController/PriceCallout/PriceCallout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useAccountDetails,
88
useAvailablePlans,
99
} from 'services/account'
10+
import { Provider } from 'shared/api/helpers'
1011
import {
1112
BillingRate,
1213
findProPlans,
@@ -32,7 +33,7 @@ const PriceCallout: React.FC<PriceCalloutProps> = ({
3233
seats,
3334
setFormValue,
3435
}) => {
35-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
36+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
3637
const { data: plans } = useAvailablePlans({ provider, owner })
3738
const { proPlanMonth, proPlanYear } = findProPlans({ plans })
3839
const perMonthPrice = calculatePriceProPlan({

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/ProPlanController/UserCount/UserCount.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import isNumber from 'lodash/isNumber'
22
import { useParams } from 'react-router-dom'
33

44
import { useAccountDetails } from 'services/account'
5+
import { Provider } from 'shared/api/helpers'
56

67
interface StudentTextProps {
78
activatedStudents?: number
@@ -41,7 +42,7 @@ const UserText: React.FC<UserTextProps> = ({
4142
}
4243

4344
const UserCount: React.FC = () => {
44-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
45+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
4546
const { data: accountDetails } = useAccountDetails({ provider, owner })
4647

4748
const activatedStudentCount = accountDetails?.activatedStudentCount

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/SentryPlanController/PriceCallout/PriceCallout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useAccountDetails,
88
useAvailablePlans,
99
} from 'services/account'
10+
import { Provider } from 'shared/api/helpers'
1011
import {
1112
BillingRate,
1213
findSentryPlans,
@@ -33,7 +34,7 @@ const PriceCallout: React.FC<PriceCalloutProps> = ({
3334
seats,
3435
setFormValue,
3536
}) => {
36-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
37+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
3738
const { data: plans } = useAvailablePlans({ provider, owner })
3839
const { sentryPlanMonth, sentryPlanYear } = findSentryPlans({ plans })
3940
const perMonthPrice = calculatePriceSentryPlan({

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/SentryPlanController/UserCount/UserCount.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import isNumber from 'lodash/isNumber'
22
import { useParams } from 'react-router-dom'
33

44
import { useAccountDetails } from 'services/account'
5+
import { Provider } from 'shared/api/helpers'
56

67
interface StudentTextProps {
78
activatedStudents?: number
@@ -30,7 +31,7 @@ const UserText: React.FC = () => {
3031
}
3132

3233
const UserCount: React.FC = () => {
33-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
34+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
3435
const { data: accountDetails } = useAccountDetails({ provider, owner })
3536

3637
const activatedStudentCount = accountDetails?.activatedStudentCount

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/TeamPlanController/PriceCallout/PriceCallout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useAccountDetails,
99
useAvailablePlans,
1010
} from 'services/account'
11+
import { Provider } from 'shared/api/helpers'
1112
import {
1213
BillingRate,
1314
findTeamPlans,
@@ -34,7 +35,7 @@ const PriceCallout: React.FC<PriceCalloutProps> = ({
3435
seats,
3536
setFormValue,
3637
}) => {
37-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
38+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
3839
const { data: plans } = useAvailablePlans({ provider, owner })
3940
const { teamPlanMonth, teamPlanYear } = findTeamPlans({ plans })
4041
const perMonthPrice = calculatePriceTeamPlan({

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/Controllers/TeamPlanController/UserCount/UserCount.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import isNumber from 'lodash/isNumber'
22
import { useParams } from 'react-router-dom'
33

44
import { useAccountDetails } from 'services/account'
5+
import { Provider } from 'shared/api/helpers'
56

67
interface StudentTextProps {
78
activatedStudents?: number
@@ -42,7 +43,7 @@ const UserText: React.FC<UserTextProps> = ({
4243
}
4344

4445
const UserCount: React.FC = () => {
45-
const { provider, owner } = useParams<{ provider: string; owner: string }>()
46+
const { provider, owner } = useParams<{ provider: Provider; owner: string }>()
4647
const { data: accountDetails } = useAccountDetails({ provider, owner })
4748

4849
const activatedStudentCount = accountDetails?.activatedStudentCount

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/UpgradeForm.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useAvailablePlans,
1010
usePlanData,
1111
} from 'services/account'
12+
import { Provider } from 'shared/api/helpers'
1213
import { canApplySentryUpgrade, getNextBillingDate } from 'shared/utils/billing'
1314
import {
1415
getDefaultValuesUpgradeForm,
@@ -24,7 +25,7 @@ import UpdateBlurb from './UpdateBlurb/UpdateBlurb'
2425
import UpdateButton from './UpdateButton'
2526

2627
type URLParams = {
27-
provider: string
28+
provider: Provider
2829
owner: string
2930
}
3031

src/services/account/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export * from './usePlanData'
99
export * from './useAvailablePlans'
1010
export * from './useSentryToken'
1111
export * from './useUpdateCard'
12+
export * from './useUpdatePaymentMethod'
1213
export * from './useUpgradePlan'
1314
export * from './useUpdateBillingEmail'

src/services/account/useAccountDetails.test.tsx

+44-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { http, HttpResponse } from 'msw'
44
import { setupServer } from 'msw/node'
55
import React from 'react'
66
import { MemoryRouter, Route } from 'react-router-dom'
7+
import { z } from 'zod'
78

8-
import { accountDetailsObject, accountDetailsParsedObj } from './mocks'
9-
import { useAccountDetails } from './useAccountDetails'
9+
import { accountDetailsParsedObj } from './mocks'
10+
import { AccountDetailsSchema, useAccountDetails } from './useAccountDetails'
1011

1112
vi.mock('js-cookie')
1213

@@ -45,17 +46,17 @@ afterAll(() => {
4546
})
4647

4748
describe('useAccountDetails', () => {
48-
function setup() {
49+
function setup(accountDetails: z.infer<typeof AccountDetailsSchema>) {
4950
server.use(
5051
http.get(`/internal/${provider}/${owner}/account-details/`, () => {
51-
return HttpResponse.json(accountDetailsObject)
52+
return HttpResponse.json(accountDetails)
5253
})
5354
)
5455
}
5556

5657
describe('when called', () => {
5758
it('returns the data', async () => {
58-
setup()
59+
setup(accountDetailsParsedObj)
5960
const { result } = renderHook(
6061
() => useAccountDetails({ provider, owner }),
6162
{ wrapper: wrapper() }
@@ -65,5 +66,43 @@ describe('useAccountDetails', () => {
6566
expect(result.current.data).toEqual(accountDetailsParsedObj)
6667
)
6768
})
69+
70+
it('returns data with usBankAccount when enabled', async () => {
71+
const withUSBankAccount = {
72+
...accountDetailsParsedObj,
73+
subscriptionDetail: {
74+
...accountDetailsParsedObj.subscriptionDetail,
75+
defaultPaymentMethod: {
76+
billingDetails: null,
77+
usBankAccount: {
78+
bankName: 'Bank of America',
79+
last4: '1234',
80+
},
81+
},
82+
},
83+
}
84+
setup(withUSBankAccount)
85+
86+
const { result } = renderHook(
87+
() => useAccountDetails({ provider, owner }),
88+
{ wrapper: wrapper() }
89+
)
90+
91+
await waitFor(() =>
92+
expect(result.current.data).toEqual({
93+
...accountDetailsParsedObj,
94+
subscriptionDetail: {
95+
...accountDetailsParsedObj.subscriptionDetail,
96+
defaultPaymentMethod: {
97+
billingDetails: null,
98+
usBankAccount: {
99+
bankName: 'Bank of America',
100+
last4: '1234',
101+
},
102+
},
103+
},
104+
})
105+
)
106+
})
68107
})
69108
})

src/services/account/useAccountDetails.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'
22
import { z } from 'zod'
33

44
import Api from 'shared/api'
5-
import { NetworkErrorObject } from 'shared/api/helpers'
5+
import { NetworkErrorObject, Provider } from 'shared/api/helpers'
66

77
const InvoiceSchema = z
88
.object({
@@ -75,6 +75,12 @@ export const PaymentMethodSchema = z
7575
last4: z.string(),
7676
})
7777
.nullish(),
78+
usBankAccount: z
79+
.object({
80+
bankName: z.string(),
81+
last4: z.string(),
82+
})
83+
.nullish(),
7884
billingDetails: BillingDetailsSchema.nullable(),
7985
})
8086
.nullable()
@@ -147,7 +153,7 @@ export const AccountDetailsSchema = z.object({
147153
})
148154

149155
export interface UseAccountDetailsArgs {
150-
provider: string
156+
provider: Provider
151157
owner: string
152158
opts?: {
153159
enabled?: boolean
@@ -158,7 +164,7 @@ function getPathAccountDetails({
158164
provider,
159165
owner,
160166
}: {
161-
provider: string
167+
provider: Provider
162168
owner: string
163169
}) {
164170
return `/${provider}/${owner}/account-details/`
@@ -169,7 +175,7 @@ function fetchAccountDetails({
169175
owner,
170176
signal,
171177
}: {
172-
provider: string
178+
provider: Provider
173179
owner: string
174180
signal?: AbortSignal
175181
}) {

0 commit comments

Comments
 (0)