Skip to content

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

Scaffold downgrade to free flow and exit survey page

Joshen Lim95bcca33575e
diff --git a/studio/components/interfaces/Billing/Billing.constants.ts b/studio/components/interfaces/Billing/Billing.constants.ts
new file mode 100644
index 00000000000..5b7c75c7d2d
--- /dev/null
+++ b/studio/components/interfaces/Billing/Billing.constants.ts
@@ -0,0 +1,14 @@
+export const CANCELLATION_REASONS = [
+ `Pricing`,
+ `My project isn't getting traction`,
+ `Poor customer service`,
+ `Missing feature`,
+ `I didn't see the value`,
+ `I couldn't achieve my project goals`,
+ `Dashboard is too complicated`,
+ `Postgres is too complicated`,
+ `Problem not solved`,
+ `Bug issues`,
+ `I decided to use something else`,
+ `None of the above`,
+]
diff --git a/studio/components/interfaces/Billing/ExitSurvey.tsx b/studio/components/interfaces/Billing/ExitSurvey.tsx
new file mode 100644
index 00000000000..1e7485fe8e9
--- /dev/null
+++ b/studio/components/interfaces/Billing/ExitSurvey.tsx
@@ -0,0 +1,123 @@
+import { FC, 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, [])
+
+ 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 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-xl">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/PlanSelection/Plans/Plans.tsx b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
index d6e5376a58f..ab3ca84e31c 100644
--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx
@@ -38,6 +38,7 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {
{plans.map((plan) => {
return (
<div
+ key={plan.name}
className={[
'flex flex-col justify-between w-1/3 px-6 py-8',
'bg-gray-300 border border-gray-500 rounded-md relative',
@@ -50,7 +51,7 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {
{/* Label to show current subscription */}
{plan.id && plan.id === currentPlan?.tier.prod_id && <CurrentSubscriptionBanner />}
- <div className="z-10 mb-8">
+ <div className="mb-8">
<div className="flex items-center space-x-4">
<h3 className="text-xl">{plan.name}</h3>
{plan.isPopular && <Badge>Popular</Badge>}
diff --git a/studio/components/interfaces/Billing/index.ts b/studio/components/interfaces/Billing/index.ts
index 942a0ddf5e4..d87abd8fad1 100644
--- a/studio/components/interfaces/Billing/index.ts
+++ b/studio/components/interfaces/Billing/index.ts
@@ -2,7 +2,8 @@ import PAYGUsage from './PAYGUsage/PAYGUsage'
import Subscription from './Subscription/Subscription'
import PlanSelection from './PlanSelection/PlanSelection'
import EnterpriseRequest from './EnterpriseRequest'
+import ExitSurvey from './ExitSurvey'
export * from './Subscription/Subscription.types'
export * from './PAYGUsage/PAYGUsage.constants'
-export { PAYGUsage, Subscription, PlanSelection, EnterpriseRequest }
+export { PAYGUsage, Subscription, PlanSelection, EnterpriseRequest, ExitSurvey }
diff --git a/studio/pages/project/[ref]/settings/billing/update.tsx b/studio/pages/project/[ref]/settings/billing/update.tsx
index 8de5023517f..ad1edc42380 100644
--- a/studio/pages/project/[ref]/settings/billing/update.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update.tsx
@@ -1,13 +1,20 @@
import { NextPage } from 'next'
import { useEffect, useState } from 'react'
import { observer } from 'mobx-react-lite'
+import { Button, Modal } from '@supabase/ui'
-import { withAuth, useStore } from 'hooks'
+import { withAuth, useStore, useSubscriptionStats } from 'hooks'
import { post } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
-import { BillingLayout } from 'components/layouts'
-import { PlanSelection, EnterpriseRequest, StripeSubscription } from 'components/interfaces/Billing'
+import { API_URL, DEFAULT_FREE_PROJECTS_LIMIT, STRIPE_PRODUCT_IDS } from 'lib/constants'
+import { BillingLayout } from 'components/layouts'
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
+import {
+ PlanSelection,
+ EnterpriseRequest,
+ ExitSurvey,
+ 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'
@@ -15,7 +22,14 @@ const BillingUpdate: NextPage = () => {
const { ui } = useStore()
const projectRef = ui.selectedProject?.ref
+ const subscriptionStats = useSubscriptionStats()
+ const freeProjectsLimit = ui?.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
+ const freeProjectsOwned = subscriptionStats.total_free_projects ?? 0
+
const [loading, setLoading] = useState(false)
+ const [showConfirmDowngrade, setShowConfirmDowngrade] = useState(false)
+ const [showDowngradeError, setShowDowngradeError] = useState(false)
+
const [subscription, setSubscription] = useState<StripeSubscription>()
const [selectedPlan, setSelectedPlan] = useState<BillingPlan>()
@@ -49,18 +63,82 @@ const BillingUpdate: NextPage = () => {
}
}
+ const onSelectPlan = (plan: BillingPlan) => {
+ setSelectedPlan(plan)
+ if (plan.id === STRIPE_PRODUCT_IDS.FREE) {
+ setShowConfirmDowngrade(true)
+ }
+ }
+
+ const onConfirmDowngrade = () => {
+ if (freeProjectsOwned >= freeProjectsLimit) {
+ setShowDowngradeError(true)
+ setSelectedPlan(undefined)
+ }
+ setShowConfirmDowngrade(false)
+ }
+
return (
<BillingLayout>
<PlanSelection
- visible={!selectedPlan}
+ visible={!selectedPlan || (selectedPlan && showConfirmDowngrade)}
billingPlans={BILLING_PLANS}
currentPlan={subscription}
- onSelectPlan={setSelectedPlan}
+ onSelectPlan={onSelectPlan}
/>
<EnterpriseRequest
visible={selectedPlan?.name === 'Enterprise'}
onSelectBack={() => setSelectedPlan(undefined)}
/>
+ <ExitSurvey
+ visible={selectedPlan?.name === 'Free' && !showConfirmDowngrade}
+ onSelectBack={() => setSelectedPlan(undefined)}
+ />
+
+ <ConfirmModal
+ danger
+ visible={showConfirmDowngrade}
+ title="Are you sure?"
+ description="Downgrading to the free tier will lead to reductions in your project’s capacity.
+ If you're already past the limits of the free tier, your project will be throttled greatly."
+ buttonLabel="Confirm"
+ buttonLoadingLabel="Confirm"
+ onSelectCancel={() => {
+ setShowConfirmDowngrade(false)
+ setSelectedPlan(undefined)
+ }}
+ onSelectConfirm={onConfirmDowngrade}
+ />
+ <Modal
+ visible={showDowngradeError}
+ size="small"
+ header="Free tier limit exceeded"
+ hideFooter
+ onCancel={() => setShowDowngradeError(false)}
+ >
+ <div className="py-4 space-y-4">
+ <Modal.Content>
+ <p className="text-sm text-scale-1100">
+ Your account is entitled up to {freeProjectsLimit} free projects across all
+ organizations you own. You will need to delete or upgrade an existing free project
+ first, before being able to downgrade this project.
+ </p>
+ </Modal.Content>
+ <Modal.Seperator />
+ <Modal.Content>
+ <div className="flex items-center gap-2">
+ <Button
+ htmlType="button"
+ type="default"
+ onClick={() => setShowDowngradeError(false)}
+ block
+ >
+ Understood
+ </Button>
+ </div>
+ </Modal.Content>
+ </div>
+ </Modal>
</BillingLayout>
)
}