Skip to content

Commit 6c42961

Browse files
handle upgrade flow
1 parent 9c51adb commit 6c42961

File tree

3 files changed

+67
-33
lines changed

3 files changed

+67
-33
lines changed

src/pages/PlanPage/PlanPage.jsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import config from 'config'
88

99
import { SentryRoute } from 'sentry'
1010

11+
import { useAccountDetails } from 'services/account'
1112
import { Theme, useThemeContext } from 'shared/ThemeContext'
13+
import A from 'ui/A'
14+
import { Alert } from 'ui/Alert'
1215
import LoadingLogo from 'ui/LoadingLogo'
1316

1417
import { PlanProvider } from './context'
1518
import PlanBreadcrumb from './PlanBreadcrumb'
1619
import { PlanPageDataQueryOpts } from './queries/PlanPageDataQueryOpts'
1720
import Tabs from './Tabs'
1821

22+
1923
import { StripeAppearance } from '../../stripe'
2024

25+
2126
const CancelPlanPage = lazy(() => import('./subRoutes/CancelPlanPage'))
2227
const CurrentOrgPlan = lazy(() => import('./subRoutes/CurrentOrgPlan'))
2328
const InvoicesPage = lazy(() => import('./subRoutes/InvoicesPage'))
@@ -40,13 +45,27 @@ function PlanPage() {
4045
const { data: ownerData } = useSuspenseQueryV5(
4146
PlanPageDataQueryOpts({ owner, provider })
4247
)
48+
const { data: accountDetails } = useAccountDetails({
49+
provider,
50+
owner,
51+
})
52+
4353
const { theme } = useThemeContext()
4454
const isDarkMode = theme !== Theme.LIGHT
4555

4656
if (config.IS_SELF_HOSTED || !ownerData?.isCurrentUserPartOfOrg) {
4757
return <Redirect to={`/${provider}/${owner}`} />
4858
}
4959

60+
const isAwaitingVerification =
61+
accountDetails?.unverifiedPaymentMethods?.length
62+
// const isAwaitingFirstPaymentMethodVerification =
63+
// !accountDetails?.subscriptionDetail?.defaultPaymentMethod &&
64+
// isAwaitingVerification
65+
66+
// const hasSuccessfulDefaultPaymentMethod =
67+
// accountDetails?.subscriptionDetail?.defaultPaymentMethod
68+
5069
return (
5170
<div className="flex flex-col gap-4">
5271
<Tabs />
@@ -61,6 +80,14 @@ function PlanPage() {
6180
>
6281
<PlanProvider>
6382
<PlanBreadcrumb />
83+
{isAwaitingVerification ? (
84+
<UnverifiedPaymentMethodAlert
85+
url={
86+
accountDetails?.unverifiedPaymentMethods?.[0]
87+
?.hostedVerificationLink
88+
}
89+
/>
90+
) : null}
6491
<Suspense fallback={<Loader />}>
6592
<Switch>
6693
<SentryRoute path={path} exact>
@@ -91,3 +118,27 @@ function PlanPage() {
91118
}
92119

93120
export default PlanPage
121+
122+
// eslint-disable-next-line react/prop-types
123+
const UnverifiedPaymentMethodAlert = ({ url }) => {
124+
return (
125+
<>
126+
<Alert variant={'warning'}>
127+
<Alert.Title>New Payment Method Awaiting Verification</Alert.Title>
128+
<Alert.Description>
129+
Your new payment method requires verification.{' '}
130+
<A
131+
href={url}
132+
isExternal={true}
133+
hook="stripe-payment-method-verification"
134+
to={undefined}
135+
>
136+
Click here
137+
</A>{' '}
138+
to complete the verification process.
139+
</Alert.Description>
140+
</Alert>
141+
<br />
142+
</>
143+
)
144+
}

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ function CurrentOrgPlan() {
4040
})
4141
)
4242

43-
const isAwaitingFirstPaymentMethodVerification = false
4443
const isAwaitingVerification =
4544
accountDetails?.unverifiedPaymentMethods?.length
45+
const isAwaitingFirstPaymentMethodVerification =
46+
!accountDetails?.subscriptionDetail?.defaultPaymentMethod &&
47+
isAwaitingVerification
4648

4749
const scheduledPhase = accountDetails?.scheduleDetail?.scheduledPhase
4850
// customer is delinquent until their first payment method is verified
@@ -71,14 +73,6 @@ function CurrentOrgPlan() {
7173

7274
return (
7375
<div className="w-full lg:w-4/5">
74-
{isAwaitingVerification ? (
75-
<UnverifiedPaymentMethodAlert
76-
url={
77-
accountDetails?.unverifiedPaymentMethods?.[0]
78-
?.hostedVerificationLink
79-
}
80-
/>
81-
) : null}
8276
{planUpdatedNotification.isCancellation ? (
8377
<InfoAlertCancellation
8478
subscriptionDetail={accountDetails?.subscriptionDetail}
@@ -178,27 +172,4 @@ const DelinquentAlert = () => {
178172
)
179173
}
180174

181-
const UnverifiedPaymentMethodAlert = ({ url }: { url: string | undefined }) => {
182-
return (
183-
<>
184-
<Alert variant={'warning'}>
185-
<Alert.Title>New Payment Method Awaiting Verification</Alert.Title>
186-
<Alert.Description>
187-
Your new payment method requires verification. Click{' '}
188-
<A
189-
href={url}
190-
isExternal={true}
191-
hook="stripe-payment-method-verification"
192-
to={undefined}
193-
>
194-
here
195-
</A>{' '}
196-
to complete the verification process.
197-
</Alert.Description>
198-
</Alert>
199-
<br />
200-
</>
201-
)
202-
}
203-
204175
export default CurrentOrgPlan

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ function UpgradeForm({ selectedPlan, setSelectedPlan }: UpgradeFormProps) {
9393
return (
9494
<form
9595
className="flex flex-col gap-6 border p-4 text-ds-gray-default md:w-2/3"
96-
onSubmit={handleSubmit(upgradePlan)}
96+
onSubmit={handleSubmit((data) => {
97+
if (accountDetails?.unverifiedPaymentMethods?.length) {
98+
if (
99+
window.confirm(
100+
'You have a payment method awaiting verification. Are you sure you want to proceed with upgrading your plan? This will cancel the existing action.'
101+
)
102+
) {
103+
upgradePlan(data)
104+
}
105+
} else {
106+
upgradePlan(data)
107+
}
108+
})}
97109
>
98110
<div className="flex flex-col gap-1">
99111
<h3 className="font-semibold">Organization</h3>

0 commit comments

Comments
 (0)