Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Payment summary to include details about available balance

Joshen Limc6fbee39bd14
diff --git a/studio/components/interfaces/Billing/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey.tsx
deleted file mode 100644
index f589a395941..00000000000
--- a/studio/components/interfaces/Billing/ExitSurvey.tsx
+++ /dev/null
@@ -1,131 +0,0 @@
-import { FC, useEffect, useReducer } from 'react'
-import { includes, without } from 'lodash'
-import { Transition } from '@headlessui/react'
-import { Button, Form, Input, IconArrowLeft } from '@supabase/ui'
-
-import { timeout } from 'lib/helpers'
-import { CANCELLATION_REASONS } from './Billing.constants'
-
-interface Props {
- visible: boolean
- onSelectBack: () => void
-}
-
-const ExitSurvey: FC<Props> = ({ visible, onSelectBack }) => {
- const initialValues = { message: '' }
- const [selectedCancellationReasons, dispatchSelectedCancellationReasons] = useReducer(reducer, [])
-
- useEffect(() => {
- if (visible) {
- dispatchSelectedCancellationReasons('reset')
- }
- }, [visible])
-
- function reducer(state: any, action: any) {
- if (action === 'reset') {
- return []
- } else if (includes(state, action.target.value)) {
- return without(state, action.target.value)
- } else {
- return [...state, action.target.value]
- }
- }
-
- const onValidate = (values: any) => {
- console.log('onValidate', values, selectedCancellationReasons)
- }
-
- const onSubmit = async (values: any, { setSubmitting }: any) => {
- setSubmitting(true)
- await timeout(1000)
- console.log('onSubmit', values, selectedCancellationReasons)
- setSubmitting(false)
- }
-
- return (
- <Transition
- show={visible}
- enter="transition ease-out duration-300"
- enterFrom="transform opacity-0 translate-x-10"
- enterTo="transform opacity-100 translate-x-0"
- >
- {visible && (
- <div className="space-y-8 w-4/5">
- <div className="relative">
- <div className="absolute top-[2px] -left-24">
- <Button type="text" icon={<IconArrowLeft />} onClick={onSelectBack}>
- Back
- </Button>
- </div>
- <div className="space-y-1">
- <h4 className="text-lg">We're sad that you're leaving.</h4>
- <p className="text-scale-1100">
- We always strive to improve Supabase as much as we can. Please let us know the
- reasons you are cancelling your subscription so that we can improve in the future.
- </p>
- </div>
- <Form
- validateOnBlur
- initialValues={initialValues}
- validate={onValidate}
- onSubmit={onSubmit}
- >
- {({ isSubmitting }: { isSubmitting: boolean }) => (
- <div className="space-y-8 py-8">
- <div className="flex flex-wrap gap-2" data-toggle="buttons">
- {CANCELLATION_REASONS.map((option) => {
- const active = selectedCancellationReasons.find((x) => x === option)
- return (
- <label
- key={option}
- className={`
- text-center rounded-md py-1 pl-2 pr-3 shadow-sm
- transition-all flex items-center space-x-2
- duration-100 cursor-pointer text-sm
- ${
- active
- ? ` opacity-100 bg-scale-1200 text-scale-100 hover:bg-opacity-75`
- : ` bg-scale-700 opacity-25 hover:opacity-50 text-scale-1200`
- }
- `}
- >
- <input
- type="checkbox"
- name="options"
- value={option}
- className="hidden"
- onClick={dispatchSelectedCancellationReasons}
- />
- <div>{option}</div>
- </label>
- )
- })}
- </div>
- <Input.TextArea
- id="message"
- name="message"
- label="Anything else that we can improve on?"
- />
- <div className="flex items-center space-x-2">
- <Button htmlType="button" type="default">
- Cancel
- </Button>
- <Button htmlType="submit" type="danger" loading={isSubmitting}>
- Confirm downgrade
- </Button>
- <p className="text-xs text-scale-900">
- The unused amount for the remaining of your billing cycle will be refunded as
- credits
- </p>
- </div>
- </div>
- )}
- </Form>
- </div>
- </div>
- )}
- </Transition>
- )
-}
-
-export default ExitSurvey
diff --git a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx
new file mode 100644
index 00000000000..6d984e449c3
--- /dev/null
+++ b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.tsx
@@ -0,0 +1,155 @@
+import { FC, useReducer } from 'react'
+import { includes, without } from 'lodash'
+import { Transition } from '@headlessui/react'
+import { Button, Form, Input, IconArrowLeft } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { post, patch } from 'lib/common/fetch'
+import { API_URL, STRIPE_TIER_PRICE_IDS } from 'lib/constants'
+import { CANCELLATION_REASONS } from '../Billing.constants'
+import { generateFeedbackMessage } from './ExitSurvey.utils'
+
+interface Props {
+ onSelectBack: () => void
+}
+
+const ExitSurvey: FC<Props> = ({ onSelectBack }) => {
+ const { ui } = useStore()
+ const projectRef = ui.selectedProject?.ref
+
+ const initialValues = { message: '' }
+ const [selectedReasons, dispatchSelectedReasons] = useReducer(reducer, [])
+
+ function reducer(state: any, action: any) {
+ if (includes(state, action.target.value)) {
+ return without(state, action.target.value)
+ } else {
+ return [...state, action.target.value]
+ }
+ }
+
+ const onSubmit = async (values: any, { setSubmitting }: any) => {
+ try {
+ setSubmitting(true)
+ if (selectedReasons.length === 0) {
+ return ui.setNotification({
+ category: 'error',
+ message: 'Please select at least one reason for cancelling your subscription',
+ })
+ }
+
+ // Submit feedback to Freshdesk (Disabled for local tetsing)
+ // await post(`${API_URL}/feedback/send`, {
+ // projectRef,
+ // subject: 'Subscription cancellation - Exit survey',
+ // tags: ['dashboard-exitsurvey'],
+ // category: 'Billing',
+ // message: generateFeedbackMessage(selectedReasons, values.message),
+ // })
+
+ // Trigger subscription downgrade
+ const tier = STRIPE_TIER_PRICE_IDS.FREE
+ const addons: string[] = []
+ const proration_date = Math.floor(Date.now() / 1000)
+ const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, {
+ tier,
+ addons,
+ proration_date,
+ })
+
+ if (res?.error) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to cancel subscription: ${res?.error?.message}`,
+ })
+ } else {
+ console.log('Succesfully updated subscription')
+ }
+ } catch (error: any) {
+ ui.setNotification({ category: 'error', message: `Failed to cancel subscription: ${error}` })
+ } finally {
+ setSubmitting(false)
+ }
+ }
+
+ return (
+ <Transition
+ show
+ appear
+ enter="transition ease-out duration-300"
+ enterFrom="transform opacity-0 translate-x-10"
+ enterTo="transform opacity-100 translate-x-0"
+ >
+ <div className="space-y-8 w-4/5">
+ <div className="relative">
+ <div className="absolute top-[2px] -left-24">
+ <Button type="text" icon={<IconArrowLeft />} onClick={onSelectBack}>
+ Back
+ </Button>
+ </div>
+ <div className="space-y-1">
+ <h4 className="text-lg">We're sad that you're leaving.</h4>
+ <p className="text-scale-1100">
+ We always strive to improve Supabase as much as we can. Please let us know the reasons
+ you are cancelling your subscription so that we can improve in the future.
+ </p>
+ </div>
+ <Form validateOnBlur initialValues={initialValues} onSubmit={onSubmit}>
+ {({ isSubmitting }: { isSubmitting: boolean }) => (
+ <div className="space-y-8 py-8">
+ <div className="flex flex-wrap gap-2" data-toggle="buttons">
+ {CANCELLATION_REASONS.map((option) => {
+ const active = selectedReasons.find((x) => x === option)
+ return (
+ <label
+ key={option}
+ className={`
+ text-center rounded-md py-1 pl-2 pr-3 shadow-sm
+ transition-all flex items-center space-x-2
+ duration-100 cursor-pointer text-sm
+ ${
+ active
+ ? ` opacity-100 bg-scale-1200 text-scale-100 hover:bg-opacity-75`
+ : ` bg-scale-700 opacity-25 hover:opacity-50 text-scale-1200`
+ }
+ `}
+ >
+ <input
+ type="checkbox"
+ name="options"
+ value={option}
+ className="hidden"
+ onClick={dispatchSelectedReasons}
+ />
+ <div>{option}</div>
+ </label>
+ )
+ })}
+ </div>
+ <Input.TextArea
+ id="message"
+ name="message"
+ label="Anything else that we can improve on?"
+ />
+ <div className="flex items-center space-x-2">
+ <Button htmlType="button" type="default">
+ Cancel
+ </Button>
+ <Button htmlType="submit" type="danger" loading={isSubmitting}>
+ Confirm downgrade
+ </Button>
+ <p className="text-xs text-scale-900">
+ The unused amount for the remaining of your billing cycle will be refunded as
+ credits
+ </p>
+ </div>
+ </div>
+ )}
+ </Form>
+ </div>
+ </div>
+ </Transition>
+ )
+}
+
+export default ExitSurvey
diff --git a/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.utils.ts b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.utils.ts
new file mode 100644
index 00000000000..c98250007a3
--- /dev/null
+++ b/studio/components/interfaces/Billing/ExitSurvey/ExitSurvey.utils.ts
@@ -0,0 +1,11 @@
+export const generateFeedbackMessage = (reasons: string[], message: string) => {
+ return `
+Exit survey \n
+
+Reasons for leaving:
+${reasons.reduce((a, b) => `${a}- ${b}\n`, '')}
+
+Additional feedback:
+${message}
+ `
+}
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx
new file mode 100644
index 00000000000..987f13cc044
--- /dev/null
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentTotal.tsx
@@ -0,0 +1,90 @@
+import { FC } from 'react'
+import { Loading } from '@supabase/ui'
+import { SubscriptionPreview } from '../Billing.types'
+
+interface Props {
+ subscriptionPreview?: SubscriptionPreview
+ isRefreshingPreview: boolean
+ hasChangesToPlan: boolean
+ isSpendCapEnabled: boolean
+}
+
+const PaymentTotal: FC<Props> = ({
+ subscriptionPreview,
+ isRefreshingPreview,
+ hasChangesToPlan,
+ isSpendCapEnabled,
+}) => {
+ const hasCreditsBalance = (subscriptionPreview?.available_credit_balance ?? 0) > 0
+ const availableCreditBalance = (subscriptionPreview?.available_credit_balance ?? 0) / 100
+ const remainingCreditBalance = (subscriptionPreview?.remaining_credit_balance ?? 0) / 100
+
+ const totalMonthlyCost = (subscriptionPreview?.base_amount_due_next_billing_cycle ?? 0) / 100
+ const amountDueImmediately = (subscriptionPreview?.amount_due_immediately ?? 0) / 100
+ const nextInvoiceDate = new Date((subscriptionPreview?.next_billing_cycle ?? 0) * 1000)
+
+ return (
+ <>
+ {/* Credit balance details (If available) */}
+ {hasCreditsBalance && (
+ <>
+ <Loading active={isRefreshingPreview}>
+ <div className="space-y-1">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">Total amount due</p>
+ <p className="text-sm">
+ $
+ {((subscriptionPreview?.base_amount_due_next_billing_cycle ?? 0) / 100).toFixed(
+ 2
+ )}
+ </p>
+ </div>
+ <div className="flex items-center justify-between">
+ <p className="text-sm">Available credit balance</p>
+ <p className="text-sm">${availableCreditBalance.toFixed(2)}</p>
+ </div>
+ </div>
+ </Loading>
+ <div className="h-px w-full bg-scale-600" />
+ </>
+ )}
+
+ {/* Payment total */}
+ <Loading active={isRefreshingPreview}>
+ <div className="mb-2">
+ <div className="flex items-start justify-between">
+ <p>Amount due today</p>
+ <div className="flex justify-end items-end relative -top-[5px]">
+ <p className="text-scale-1100 relative -top-[1px]">$</p>
+ <p className="text-2xl">{amountDueImmediately.toFixed(2)}</p>
+ </div>
+ </div>
+ {hasCreditsBalance && (
+ <div className="flex items-start justify-between">
+ <p className="text-sm">Remaining credit balance</p>
+ <p className="text-sm">${remainingCreditBalance.toFixed(2)}</p>
+ </div>
+ )}
+ </div>
+ {hasChangesToPlan && (
+ <div className="w-2/3">
+ <p className="text-sm text-scale-1100">
+ You'll pay a monthly total of{' '}
+ <span className="text-scale-1200">
+ ${totalMonthlyCost} {!isSpendCapEnabled && '+ usage fees '}
+ </span>
+ starting on{' '}
+ {nextInvoiceDate.toLocaleDateString('en-US', {
+ day: 'numeric',
+ month: 'long',
+ year: 'numeric',
+ })}
+ </p>
+ </div>
+ )}
+ </Loading>
+ </>
+ )
+}
+
+export default PaymentTotal
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
similarity index 82%
rename from studio/components/interfaces/Billing/PaymentSummaryPanel.tsx
rename to studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
index 6aaa43a108b..c73131be329 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/index.tsx
@@ -2,9 +2,10 @@ import { FC } from 'react'
import { Listbox, IconLoader, Button, Loading, IconPlus } from '@supabase/ui'
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
-import { StripeProduct } from '.'
-import { BillingPlan } from './PlanSelection/Plans/Plans.types'
-import { SubscriptionPreview } from './Billing.types'
+import { StripeProduct } from '..'
+import { BillingPlan } from '../PlanSelection/Plans/Plans.types'
+import { SubscriptionPreview } from '../Billing.types'
+import PaymentTotal from './PaymentTotal'
interface Props {
isRefreshingPreview: boolean
@@ -52,7 +53,6 @@ const PaymentSummaryPanel: FC<Props> = ({
(currentPlan.prod_id === STRIPE_PRODUCT_IDS.PAYG && isSpendCapEnabled)
const isChangingComputeSize = currentComputeSize.id !== selectedComputeSize.id
const hasChangesToPlan = isChangingPlan || isChangingComputeSize
- const totalMonthlyCost = (selectedPlan?.price ?? 0) + selectedComputeSize.price
const getCurrentPlanName = () => {
if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.PAYG) return 'Pro tier (No spend caps)'
@@ -74,15 +74,15 @@ const PaymentSummaryPanel: FC<Props> = ({
{getCurrentPlanName()}
</p>
<p className={`${isChangingPlan ? 'text-scale-1100 line-through' : ''} text-sm`}>
- ${currentPlan.unit_amount / 100}
+ ${(currentPlan.unit_amount / 100).toFixed(2)}
</p>
</div>
{isChangingPlan && (
<div className="flex items-center justify-between">
<p className="text-sm">
- {selectedPlan?.name} tier {!isSpendCapEnabled ? '(No spend caps)' : ''}
+ {selectedPlan?.name} tier {!isSpendCapEnabled ? '(Spend cap disabled)' : ''}
</p>
- <p className="text-sm">${selectedPlan?.price}</p>
+ <p className="text-sm">${selectedPlan?.price?.toFixed(2)}</p>
</div>
)}
</div>
@@ -99,7 +99,7 @@ const PaymentSummaryPanel: FC<Props> = ({
Optimized database instance ({currentComputeSize.name})
</p>
<p className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}>
- ${currentComputeSize.price}
+ ${currentComputeSize.price.toFixed(2)}
</p>
</div>
)}
@@ -111,29 +111,14 @@ const PaymentSummaryPanel: FC<Props> = ({
)}
</div>
- <div className="h-px w-full bg-scale-600"></div>
+ <div className="h-px w-full bg-scale-600" />
- {/* Payment total */}
- <Loading active={isRefreshingPreview}>
- <div className="flex items-start justify-between space-x-32">
- <div className="space-y-1">
- <p>Amount due today</p>
- {hasChangesToPlan && (
- <p className="text-sm text-scale-1100">
- You'll pay a monthly total of{' '}
- <span className="text-scale-1200">
- ${totalMonthlyCost} {!isSpendCapEnabled && '+ usage fees '}
- </span>
- starting on 1st February 2022
- </p>
- )}
- </div>
- <div className="flex justify-end items-end relative -top-[5px]">
- <p className="text-scale-1100 relative -top-[1px]">$</p>
- <p className="text-2xl">{(subscriptionPreview?.amount_due_immediately ?? 0) / 100}</p>
- </div>
- </div>
- </Loading>
+ <PaymentTotal
+ subscriptionPreview={subscriptionPreview}
+ isRefreshingPreview={isRefreshingPreview}
+ hasChangesToPlan={hasChangesToPlan}
+ isSpendCapEnabled={isSpendCapEnabled}
+ />
{/* Payment method selection */}
<div className="space-y-2">
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index 48a429d1459..f4d790ecb0d 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -58,8 +58,9 @@ const ProUpgrade: FC<Props> = ({
const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] = useState(false)
const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)
- const [selectedComputeSize, setSelectedComputeSize] = useState<any>(currentComputeSize)
+ // Ignore for first iteration, just use default payment method
const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<any>()
+ const [selectedComputeSize, setSelectedComputeSize] = useState<any>(currentComputeSize)
const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>()
useEffect(() => {
@@ -70,7 +71,7 @@ const ProUpgrade: FC<Props> = ({
}, [isLoadingPaymentMethods, paymentMethods])
useEffect(() => {
- if (selectedPlan !== undefined) {
+ if (selectedPlan !== undefined && selectedPlan.id !== STRIPE_PRODUCT_IDS.FREE) {
getSubscriptionPreview()
}
}, [selectedPlan, selectedComputeSize, isSpendCapEnabled])
@@ -102,7 +103,7 @@ const ProUpgrade: FC<Props> = ({
const getSubscriptionPreview = async () => {
const tier = !isSpendCapEnabled ? STRIPE_TIER_PRICE_IDS.PAYG : selectedPlan?.priceId
- // Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
+ // [TODO] Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
const addons = selectedComputeSize.name === 'Small' ? [] : [selectedComputeSize.id]
const proration_date = Math.floor(Date.now() / 1000)
@@ -112,28 +113,34 @@ const ProUpgrade: FC<Props> = ({
addons,
proration_date,
})
+ setSubscriptionPreview(preview)
setIsRefreshingPreview(false)
console.log('Preview retrieved', preview)
- setSubscriptionPreview(preview)
}
const onConfirmPayment = async () => {
const tier = !isSpendCapEnabled ? STRIPE_TIER_PRICE_IDS.PAYG : selectedPlan?.priceId
- // Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
+ // [TODO] Small currently has no stripe product attached, so FE has a hardcoded ID just for that product
const addons = selectedComputeSize.name === 'Small' ? [] : [selectedComputeSize.id]
- const paymentMethod = selectedPaymentMethod.id
const proration_date = Math.floor(Date.now() / 1000)
setIsSubmitting(true)
await timeout(1000)
- setIsSubmitting(false)
-
- console.log('Confirm payment', {
- tier,
+ const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, {
+ tier: 'asd',
addons,
- paymentMethod,
proration_date,
})
+ if (res?.error) {
+ // [TODO] probably better error handling here to guide the users
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to update subscription: ${res?.error?.message}`,
+ })
+ } else {
+ console.log('Succesfully updated subscription')
+ }
+ setIsSubmitting(false)
}
return (
@@ -182,7 +189,7 @@ const ProUpgrade: FC<Props> = ({
<div className="flex items-start justify-between">
<div>
<div className="flex items-center space-x-2">
- <p>Enable spend caps</p>
+ <p>Enable spend cap</p>
<IconHelpCircle
size={16}
strokeWidth={1.5}
@@ -248,7 +255,7 @@ const ProUpgrade: FC<Props> = ({
hideFooter
visible={showSpendCapHelperModal}
size="large"
- header="Enabling spend caps"
+ header="Enabling spend cap"
onCancel={() => setShowSpendCapHelperModal(false)}
>
<div className="py-4 space-y-4">
@@ -256,14 +263,17 @@ const ProUpgrade: FC<Props> = ({
{/* [TODO] revise wording for "enabling spend caps" instead of overages */}
<div className="space-y-4">
<p className="text-sm">
- This removes any resource limits for your project which the Pro tier has in place.
- Any resources consumed after the Pro tier limits will be charged on a per-usage
- basis.
+ A spend cap allows you to restrict your project's resource usage within the limits
+ of the Pro tier. Disabling the spend cap will then remove those limits and any
+ additional resources consumed beyond the Pro tier limits will be charged on a
+ per-usage basis
</p>
<p className="text-sm">
The table below shows an overview of which resources are chargeable, and how they
are charged:
</p>
+ {/* Maybe instead of a table, show something more interactive like a spend cap playground */}
+ {/* Maybe ideate this in Figma first but this is good enough for now */}
<div className="border border-scale-600 bg-scale-500 rounded">
<div className="flex items-center px-4 pt-2 pb-1">
<p className="w-[50%] text-sm text-scale-1100">Item</p>
diff --git a/studio/components/interfaces/Billing/index.ts b/studio/components/interfaces/Billing/index.ts
index 86dda2e2315..47754061f5d 100644
--- a/studio/components/interfaces/Billing/index.ts
+++ b/studio/components/interfaces/Billing/index.ts
@@ -4,7 +4,7 @@ import Subscription from './Subscription/Subscription'
import PlanSelection from './PlanSelection/PlanSelection'
import ProUpgrade from './ProUpgrade'
import EnterpriseRequest from './EnterpriseRequest'
-import ExitSurvey from './ExitSurvey'
+import ExitSurvey from './ExitSurvey/ExitSurvey'
import PaymentSummaryPanel from './PaymentSummaryPanel'
import ComputeSizeSelection from './AddOns/ComputeSizeSelection'
import AddNewPaymentMethodModal from './AddNewPaymentMethodModal'
diff --git a/studio/pages/project/[ref]/settings/billing/enterprise.tsx b/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx
similarity index 85%
rename from studio/pages/project/[ref]/settings/billing/enterprise.tsx
rename to studio/pages/project/[ref]/settings/billing/update/enterprise.tsx
index 3d168ef0627..53b15beff8e 100644
--- a/studio/pages/project/[ref]/settings/billing/enterprise.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update/enterprise.tsx
@@ -7,7 +7,7 @@ import { withAuth, useStore } from 'hooks'
import { BillingLayout } from 'components/layouts'
import { EnterpriseRequest } from 'components/interfaces/Billing'
-const BillingUpdate: NextPage = () => {
+const BillingUpdateEnterprise: NextPage = () => {
const { ui } = useStore()
const router = useRouter()
const projectRef = ui.selectedProject?.ref
@@ -23,4 +23,4 @@ const BillingUpdate: NextPage = () => {
)
}
-export default withAuth(observer(BillingUpdate))
+export default withAuth(observer(BillingUpdateEnterprise))
diff --git a/studio/pages/project/[ref]/settings/billing/update/free.tsx b/studio/pages/project/[ref]/settings/billing/update/free.tsx
new file mode 100644
index 00000000000..3c4feea7389
--- /dev/null
+++ b/studio/pages/project/[ref]/settings/billing/update/free.tsx
@@ -0,0 +1,29 @@
+import { NextPage } from 'next'
+import { observer } from 'mobx-react-lite'
+import { useRouter } from 'next/router'
+
+import { withAuth, useStore } from 'hooks'
+
+import { BillingLayout } from 'components/layouts'
+import { ExitSurvey } from 'components/interfaces/Billing'
+import { useEffect } from 'react'
+
+const BillingUpdateFree: NextPage = () => {
+ const { ui } = useStore()
+ const router = useRouter()
+ const projectRef = ui.selectedProject?.ref
+
+ // [TODO] If project is already free, redirect back to plan selection and show push notification
+
+ return (
+ <BillingLayout>
+ <div className="mx-auto max-w-5xl my-10">
+ <ExitSurvey
+ onSelectBack={() => router.push(`/project/${projectRef}/settings/billing/update`)}
+ />
+ </div>
+ </BillingLayout>
+ )
+}
+
+export default withAuth(observer(BillingUpdateFree))
diff --git a/studio/pages/project/[ref]/settings/billing/update.tsx b/studio/pages/project/[ref]/settings/billing/update/index.tsx
similarity index 94%
rename from studio/pages/project/[ref]/settings/billing/update.tsx
rename to studio/pages/project/[ref]/settings/billing/update/index.tsx
index be7dcbf888a..d6c0d5e59a5 100644
--- a/studio/pages/project/[ref]/settings/billing/update.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update/index.tsx
@@ -10,12 +10,7 @@ import { API_URL, DEFAULT_FREE_PROJECTS_LIMIT, STRIPE_PRODUCT_IDS } from 'lib/co
import { BillingLayout } from 'components/layouts'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
-import {
- PlanSelection,
- ProUpgrade,
- ExitSurvey,
- StripeSubscription,
-} from 'components/interfaces/Billing'
+import { PlanSelection, ProUpgrade, StripeSubscription } from 'components/interfaces/Billing'
import { BillingPlan } from 'components/interfaces/Billing/PlanSelection/Plans/Plans.types'
import { BILLING_PLANS } from 'components/interfaces/Billing/PlanSelection/Plans/Plans.constants'
@@ -93,7 +88,7 @@ const BillingUpdate: NextPage = () => {
const onSelectPlan = (plan: BillingPlan) => {
if (plan.name === 'Enterprise') {
- return router.push(`/project/${projectRef}/settings/billing/enterprise`)
+ return router.push(`/project/${projectRef}/settings/billing/update/enterprise`)
}
setSelectedPlan(plan)
@@ -106,8 +101,9 @@ const BillingUpdate: NextPage = () => {
if (freeProjectsOwned >= freeProjectsLimit) {
setShowDowngradeError(true)
setSelectedPlan(undefined)
+ } else {
+ router.push(`/project/${projectRef}/settings/billing/update/free`)
}
- setShowConfirmDowngrade(false)
}
return (
@@ -119,10 +115,6 @@ const BillingUpdate: NextPage = () => {
currentPlan={subscription?.tier}
onSelectPlan={onSelectPlan}
/>
- <ExitSurvey
- visible={selectedPlan?.name === 'Free' && !showConfirmDowngrade}
- onSelectBack={() => setSelectedPlan(undefined)}
- />
</div>
{subscription !== undefined && (