From 0d5430edb1a224bec07aee3f9d2d241088ef2d64 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Tue, 4 Jul 2023 15:21:42 +0800 Subject: [PATCH] Fixes --- .../ChangePaymentMethodModal.tsx | 2 +- .../Subscription/Subscription.tsx | 5 - .../SubscriptionPaymentMethod.tsx | 216 ------------------ 3 files changed, 1 insertion(+), 222 deletions(-) delete mode 100644 studio/components/interfaces/Organization/BillingSettingsV2/Subscription/SubscriptionPaymentMethod.tsx diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/ChangePaymentMethodModal.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/ChangePaymentMethodModal.tsx index 3ad2afd3d22..8abb06b9d87 100644 --- a/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/ChangePaymentMethodModal.tsx +++ b/studio/components/interfaces/Organization/BillingSettingsV2/PaymentMethods/ChangePaymentMethodModal.tsx @@ -47,7 +47,7 @@ const ChangePaymentMethodModal = ({ } catch (error: any) { ui.setNotification({ category: 'error', - message: `Failed to delete payment method: ${error.message}`, + message: `Failed to change payment method: ${error.message}`, }) } } diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsx index 7f46a9482c3..8051efb8697 100644 --- a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsx +++ b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/Subscription.tsx @@ -15,7 +15,6 @@ import { useOrgSettingsPageStateSnapshot } from 'state/organization-settings' import { Alert, Button, IconExternalLink } from 'ui' import ProjectUpdateDisabledTooltip from '../../BillingSettings/ProjectUpdateDisabledTooltip' import PlanUpdateSidePanel from './PlanUpdateSidePanel' -import SubscriptionPaymentMethod from './SubscriptionPaymentMethod' import ShimmeringLoader from 'components/ui/ShimmeringLoader' const Subscription = () => { @@ -172,10 +171,6 @@ const Subscription = () => { labelBottomClass="!text-scale-1000 pb-1" labelTop={`${daysToCycleEnd} Days left`} /> - - {subscription !== undefined && ( - - )} )} diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/SubscriptionPaymentMethod.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/SubscriptionPaymentMethod.tsx deleted file mode 100644 index ef1d67e8d25..00000000000 --- a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/SubscriptionPaymentMethod.tsx +++ /dev/null @@ -1,216 +0,0 @@ -import * as Tooltip from '@radix-ui/react-tooltip' -import { PermissionAction } from '@supabase/shared-types/out/constants' -import { useState } from 'react' - -import { useParams } from 'common' -import Panel from 'components/ui/Panel' -import { - SubscriptionTier, - updateSubscriptionTier, -} from 'data/subscriptions/project-subscription-update-mutation' -import { ProjectSubscriptionResponse } from 'data/subscriptions/project-subscription-v2-query' -import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks' -import { BASE_PATH } from 'lib/constants' -import Link from 'next/link' -import { Button, IconCreditCard, Modal } from 'ui' -import PaymentMethodSelection from './PaymentMethodSelection' -import { useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation' - -export interface SubscriptionTierProps { - subscription: ProjectSubscriptionResponse -} - -const SubscriptionPaymentMethod = ({ subscription }: SubscriptionTierProps) => { - const { ui } = useStore() - const { slug } = useParams() - - const selectedOrganization = useSelectedOrganization() - const currentOrgSlug = selectedOrganization?.slug - - const { mutateAsync: updateOrgSubscription } = useOrgSubscriptionUpdateMutation() - - const canUpdatePaymentMethod = useCheckPermissions( - PermissionAction.BILLING_WRITE, - 'stripe.subscriptions' - ) - - const [isSubmitting, setIsSubmitting] = useState(false) - const [showPaymentEditModal, setShowPaymentEditModal] = useState(false) - const [selectedPaymentMethod, setSelectedPaymentMethod] = useState( - subscription.payment_method_id || '' - ) - - const onConfirmPaymentMethod = async () => { - setIsSubmitting(true) - - if (selectedPaymentMethod) { - if (!slug) return console.error('Slug is required') - if (!selectedPaymentMethod) { - return ui.setNotification({ category: 'error', message: 'Please select a payment method' }) - } - - const selectedTier = - subscription.plan.id === 'pro' && subscription.usage_billing_enabled - ? 'tier_payg' - : `tier_${subscription.plan.id}` - - try { - setIsSubmitting(true) - await updateOrgSubscription({ - slug, - tier: selectedTier as SubscriptionTier, - paymentMethod: selectedPaymentMethod, - }) - setShowPaymentEditModal(false) - ui.setNotification({ category: 'success', message: `Successfully updated payment method!` }) - } catch (error: any) { - ui.setNotification({ - error, - category: 'error', - message: `Unable to update subscription: ${error.message}`, - }) - } finally { - setIsSubmitting(false) - } - } - - setIsSubmitting(false) - } - - if (subscription.payment_method_type === 'none') return null - - return ( - <> - - - {subscription.payment_method_type === 'card' && ( - <> -
- {subscription.payment_method_card_details?.brand ? ( - Credit card brand - ) : ( - - )} - - **** **** ****{' '} - {subscription?.payment_method_card_details?.last_4_digits || '****'} - -
-
- - Expires {subscription?.payment_method_card_details?.expiry_month || '-'}/ - {subscription?.payment_method_card_details?.expiry_year?.toString()?.slice(-2) || - '-'} - -
- - )} - - {subscription?.payment_method_type === 'invoice' && ( - <> -
-
-

Payment via invoice

-

- You get a monthly invoice and payment link via email. -

-
-
- - )} - - - -
- -
-
- {subscription?.payment_method_type !== 'card' ? ( - - - -
- - Please email support@supbase.io to change your payment method. - -
-
-
- ) : !canUpdatePaymentMethod ? ( - - - -
- - You do not have permission to change the payment method - -
-
-
- ) : null} -
-
-
- - setShowPaymentEditModal(false)} - onConfirm={onConfirmPaymentMethod} - overlayClassName="pointer-events-none" - header={`Change payment method`} - > - -
-

- Upon clicking confirm, all future charges will be deducted from the selected payment - method. There are no immediate charges. Changing the payment method for this project - does not affect the payment method for other projects. -

-

- To remove unused or expired payment methods, head to your{' '} - - - organization's billing settings - - - . -

-
- -
-
-
-
- - ) -} - -export default SubscriptionPaymentMethod