From 6d8ff0c45fe825cfca72ae9c3ba45a07f306064b Mon Sep 17 00:00:00 2001 From: Suejung Shin Date: Fri, 24 Jan 2025 13:48:13 -0800 Subject: [PATCH] cleanup --- .../PlanPage/{PlanPage.jsx => PlanPage.tsx} | 32 ++++---- .../PaymentCard/PaymentCard.jsx | 1 - .../PaymentCard/PaymentMethodForm.tsx | 6 +- .../CurrentOrgPlan/CurrentOrgPlan.tsx | 23 ++---- .../InfoMessageStripeCallback.tsx | 12 ++- .../UpgradeForm/UpgradeForm.tsx | 45 ++++++++---- .../UpgradeForm/UpgradeFormModal.tsx | 73 +++++++++++++++++++ 7 files changed, 142 insertions(+), 50 deletions(-) rename src/pages/PlanPage/{PlanPage.jsx => PlanPage.tsx} (87%) create mode 100644 src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/UpgradeFormModal.tsx diff --git a/src/pages/PlanPage/PlanPage.jsx b/src/pages/PlanPage/PlanPage.tsx similarity index 87% rename from src/pages/PlanPage/PlanPage.jsx rename to src/pages/PlanPage/PlanPage.tsx index f64ba71b92..55a9b8d377 100644 --- a/src/pages/PlanPage/PlanPage.jsx +++ b/src/pages/PlanPage/PlanPage.tsx @@ -9,6 +9,7 @@ import config from 'config' import { SentryRoute } from 'sentry' import { useAccountDetails } from 'services/account' +import { Provider } from 'shared/api/helpers' import { Theme, useThemeContext } from 'shared/ThemeContext' import A from 'ui/A' import { Alert } from 'ui/Alert' @@ -19,10 +20,8 @@ import PlanBreadcrumb from './PlanBreadcrumb' import { PlanPageDataQueryOpts } from './queries/PlanPageDataQueryOpts' import Tabs from './Tabs' - import { StripeAppearance } from '../../stripe' - const CancelPlanPage = lazy(() => import('./subRoutes/CancelPlanPage')) const CurrentOrgPlan = lazy(() => import('./subRoutes/CurrentOrgPlan')) const InvoicesPage = lazy(() => import('./subRoutes/InvoicesPage')) @@ -40,8 +39,13 @@ const Loader = () => ( ) +interface URLParams { + owner: string + provider: Provider +} + function PlanPage() { - const { owner, provider } = useParams() + const { owner, provider } = useParams() const { data: ownerData } = useSuspenseQueryV5( PlanPageDataQueryOpts({ owner, provider }) ) @@ -56,15 +60,10 @@ function PlanPage() { if (config.IS_SELF_HOSTED || !ownerData?.isCurrentUserPartOfOrg) { return } - - const isAwaitingVerification = - accountDetails?.unverifiedPaymentMethods?.length - // const isAwaitingFirstPaymentMethodVerification = - // !accountDetails?.subscriptionDetail?.defaultPaymentMethod && - // isAwaitingVerification - - // const hasSuccessfulDefaultPaymentMethod = - // accountDetails?.subscriptionDetail?.defaultPaymentMethod + const hasUnverifiedPaymentMethods = Boolean( + accountDetails?.unverifiedPaymentMethods && + accountDetails.unverifiedPaymentMethods.length >= 1 + ) return (
@@ -80,7 +79,7 @@ function PlanPage() { > - {isAwaitingVerification ? ( + {hasUnverifiedPaymentMethods ? ( { +const UnverifiedPaymentMethodAlert = ({ url }: { url?: string }) => { return ( <> @@ -142,3 +138,5 @@ const UnverifiedPaymentMethodAlert = ({ url }) => { ) } + +export default PlanPage diff --git a/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx b/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx index 9a66405e0b..51bddbedfe 100644 --- a/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx +++ b/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx @@ -15,7 +15,6 @@ function PaymentCard({ accountDetails, provider, owner }) { const subscriptionDetail = accountDetails?.subscriptionDetail const card = subscriptionDetail?.defaultPaymentMethod?.card const usBankAccount = subscriptionDetail?.defaultPaymentMethod?.usBankAccount - // const isAwaitingDelayedPaymentMethodVerification = true let nextBillingDisplayDate = null if (!subscriptionDetail?.cancelAtPeriodEnd) { diff --git a/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx b/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx index 2b92534f4e..c69af50d96 100644 --- a/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx +++ b/src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx @@ -40,6 +40,7 @@ const PaymentMethodForm = ({ mutate: updatePaymentMethod, isLoading, error, + reset, } = useUpdatePaymentMethod({ provider, owner, @@ -47,6 +48,7 @@ const PaymentMethodForm = ({ email, address: stripeAddress(billingDetails) || undefined, }) + async function submit(e: React.FormEvent) { e.preventDefault() @@ -67,6 +69,8 @@ const PaymentMethodForm = ({ }) } + const showError = error && !reset + return (
@@ -83,7 +87,7 @@ const PaymentMethodForm = ({ }} />

- {error ? getErrorMessage(error) : null} + {showError ? getErrorMessage(error) : null}

+ +
+ } + /> +) + +export default UpgradeFormModal