Skip to content

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

Scaffold up pricing cards

Joshen Limc995e31aab08
diff --git a/studio/components/interfaces/Billing/Plans/PlanCTAButton.tsx b/studio/components/interfaces/Billing/Plans/PlanCTAButton.tsx
new file mode 100644
index 00000000000..d51c82428f3
--- /dev/null
+++ b/studio/components/interfaces/Billing/Plans/PlanCTAButton.tsx
@@ -0,0 +1,67 @@
+import { FC } from 'react'
+import { Button, IconLoader } from '@supabase/ui'
+
+import { STRIPE_PRODUCT_IDS } from 'lib/constants'
+import { BillingPlan } from './Plans.types'
+import { StripeSubscription } from '../index'
+
+interface Props {
+ plan: BillingPlan
+ currentPlan?: StripeSubscription
+ onSelectPlan: (plan: BillingPlan) => void
+}
+
+const PlanCTAButton: FC<Props> = ({ plan, currentPlan, onSelectPlan }) => {
+ const getButtonType = (plan: any) => {
+ if (plan.name === 'Enterprise' || plan.id === STRIPE_PRODUCT_IDS.FREE) {
+ return 'default'
+ }
+ return 'primary'
+ }
+
+ const getButtonText = (plan: any, currentPlan: any) => {
+ if (plan.name === 'Enterprise') {
+ return 'Contact sales'
+ }
+ if (plan.id === STRIPE_PRODUCT_IDS.FREE) {
+ if (currentPlan.tier.prod_id === STRIPE_PRODUCT_IDS.FREE) {
+ return 'Current plan'
+ } else {
+ return 'Downgrade to Free'
+ }
+ }
+ if (plan.id === STRIPE_PRODUCT_IDS.PRO) {
+ if (currentPlan.tier.prod_id === STRIPE_PRODUCT_IDS.FREE) {
+ return 'Upgrade to Pro'
+ } else if (currentPlan.tier.prod_id === STRIPE_PRODUCT_IDS.PRO) {
+ return 'Edit plan configuration'
+ } else {
+ return 'Contact sales'
+ }
+ }
+ }
+
+ if (!currentPlan)
+ return (
+ <div className="flex items-center justify-center">
+ <Button type="text">
+ <IconLoader size={18} className="animate-spin" />
+ </Button>
+ </div>
+ )
+
+ const type = getButtonType(plan)
+ const ctaText = getButtonText(plan, currentPlan)
+ const disabled =
+ plan.id === STRIPE_PRODUCT_IDS.FREE && currentPlan.tier.prod_id === STRIPE_PRODUCT_IDS.FREE
+
+ return (
+ <div className="flex items-center justify-center">
+ <Button disabled={disabled} type={type} onClick={() => onSelectPlan(plan)}>
+ {ctaText}
+ </Button>
+ </div>
+ )
+}
+
+export default PlanCTAButton
diff --git a/studio/components/interfaces/Billing/Plans/Plans.constants.ts b/studio/components/interfaces/Billing/Plans/Plans.constants.ts
index 8c08a917087..8bb522a9b3b 100644
--- a/studio/components/interfaces/Billing/Plans/Plans.constants.ts
+++ b/studio/components/interfaces/Billing/Plans/Plans.constants.ts
@@ -1,7 +1,9 @@
+import { STRIPE_PRODUCT_IDS } from 'lib/constants'
import { BillingPlan } from './Plans.types'
export const BILLING_PLANS: BillingPlan[] = [
{
+ id: STRIPE_PRODUCT_IDS.FREE,
name: 'Free',
price: 0,
description: 'Zero commitment, perfect for hobby projects and experiments',
@@ -13,6 +15,7 @@ export const BILLING_PLANS: BillingPlan[] = [
],
},
{
+ id: STRIPE_PRODUCT_IDS.PRO,
name: 'Pro',
price: 25,
description: 'Designated support team, account manager and technical specialist',
@@ -26,6 +29,7 @@ export const BILLING_PLANS: BillingPlan[] = [
],
},
{
+ id: undefined,
name: 'Enterprise',
price: null,
description: 'Custom tailored services to suit your specific business needs',
diff --git a/studio/components/interfaces/Billing/Plans/Plans.tsx b/studio/components/interfaces/Billing/Plans/Plans.tsx
index fad15a08bdd..1aa7957505e 100644
--- a/studio/components/interfaces/Billing/Plans/Plans.tsx
+++ b/studio/components/interfaces/Billing/Plans/Plans.tsx
@@ -1,30 +1,96 @@
-import { Badge } from '@supabase/ui'
import { FC } from 'react'
-import { BILLING_PLANS } from './Plans.constants'
+import { Badge } from '@supabase/ui'
+
+import { STRIPE_PRODUCT_IDS } from 'lib/constants'
+import { StripeSubscription } from '../index'
+import { BillingPlan } from './Plans.types'
+import PlanCTAButton from './PlanCTAButton'
+
+interface Props {
+ plans: BillingPlan[]
+ currentPlan?: StripeSubscription
+ onSelectPlan: (plan: BillingPlan) => void
+}
-interface Props {}
+const AnimatedGradientBackground = () => (
+ <div
+ className={[
+ 'absolute top-0 left-0 w-full h-full animate-sway',
+ 'bg-gradient-to-b from-transparent to-green-800 via-transparent',
+ ].join(' ')}
+ />
+)
-const Plans: FC<Props> = ({}) => {
+const CurrentSubscriptionBanner = () => (
+ <div
+ className={[
+ 'absolute top-0 right-0 flex items-center justify-center',
+ 'bg-green-900 px-4 py-1 rounded-bl-md',
+ ].join(' ')}
+ >
+ <p className="text-xs">Current plan</p>
+ </div>
+)
+
+const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {
return (
<div className="flex justify-between space-x-4">
- {BILLING_PLANS.map((plan) => {
+ {plans.map((plan) => {
return (
- <div className="w-1/3 bg-gray-300 border border-gray-500 rounded-md px-6 py-7">
- <div className="flex items-center space-x-4">
- <p className="text-lg">{plan.name}</p>
- {plan.isPopular && <Badge>Popular</Badge>}
- </div>
- <p className="text-scale-1100 text-sm mt-2">{plan.description}</p>
- <div className="py-4">
- {plan.price === null ? (
- <p className="text-2xl text-center">Contact us</p>
- ) : (
- <div className="flex items-end justify-center">
- <p className="text-3xl">${plan.price}</p>
- <p className="text-sm text-scale-1100 relative -top-[2px]"> /month</p>
- </div>
- )}
+ <div
+ className={[
+ 'flex flex-col justify-between w-1/3 px-6 py-8',
+ 'bg-gray-300 border border-gray-500 rounded-md relative',
+ 'overflow-hidden',
+ ].join(' ')}
+ >
+ {/* [Joshen] Trying some animations here to make Pro pop, on the fence tbh */}
+ {plan.id === STRIPE_PRODUCT_IDS.PRO && <AnimatedGradientBackground />}
+
+ {/* Label to show current subscription */}
+ {plan.id === currentPlan?.tier.prod_id && <CurrentSubscriptionBanner />}
+
+ <div className="z-10 mb-8">
+ <div className="flex items-center space-x-4">
+ <h3 className="text-xl">{plan.name}</h3>
+ {plan.isPopular && <Badge>Popular</Badge>}
+ </div>
+ <p className="text-scale-1100 text-sm mt-2">{plan.description}</p>
+ <div className="py-8">
+ {plan.price === null ? (
+ <p className="text-2xl text-center">Contact us</p>
+ ) : (
+ <div className="flex items-end justify-center">
+ <p className="text-3xl">${plan.price}</p>
+ <p className="text-sm text-scale-1100 relative -top-[2px]"> /month</p>
+ </div>
+ )}
+ </div>
+ <ul className="space-y-4">
+ {plan.pointers.map((pointer: string) => (
+ <li className="text-sm flex">
+ <div className="w-[15%]">
+ <svg
+ className={`h-5 w-5 text-green-900`}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ >
+ <path
+ fillRule="evenodd"
+ d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
+ clipRule="evenodd"
+ />
+ </svg>
+ </div>
+ <div className="w-[85%]">
+ <span>{pointer}</span>
+ </div>
+ </li>
+ ))}
+ </ul>
</div>
+ <PlanCTAButton plan={plan} currentPlan={currentPlan} onSelectPlan={onSelectPlan} />
</div>
)
})}
diff --git a/studio/components/interfaces/Billing/Plans/Plans.types.ts b/studio/components/interfaces/Billing/Plans/Plans.types.ts
index a5d2519dced..158f30e0d6f 100644
--- a/studio/components/interfaces/Billing/Plans/Plans.types.ts
+++ b/studio/components/interfaces/Billing/Plans/Plans.types.ts
@@ -1,4 +1,5 @@
export interface BillingPlan {
+ id?: string
name: string
price: number | null
description: string
diff --git a/studio/pages/project/[ref]/settings/billing/update.tsx b/studio/pages/project/[ref]/settings/billing/update.tsx
index d6a53234e00..2a87a7f3c59 100644
--- a/studio/pages/project/[ref]/settings/billing/update.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update.tsx
@@ -1,20 +1,74 @@
+import Link from 'next/link'
import { NextPage } from 'next'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import { observer } from 'mobx-react-lite'
+import { Loading } from '@supabase/ui'
import { withAuth, useStore } from 'hooks'
+import { post } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
import { BillingLayout } from 'components/layouts'
-import { Plans } from 'components/interfaces/Billing'
+import { Plans, StripeSubscription } from 'components/interfaces/Billing'
+
+import { BillingPlan } from 'components/interfaces/Billing/Plans/Plans.types'
+import { BILLING_PLANS } from 'components/interfaces/Billing/Plans/Plans.constants'
const BillingUpdate: NextPage = () => {
- const { app, ui } = useStore()
- console.log(ui.selectedProject)
+ const { ui } = useStore()
+ const projectRef = ui.selectedProject?.ref
+
+ const [loading, setLoading] = useState(false)
+ const [subscription, setSubscription] = useState<StripeSubscription>()
+
+ useEffect(() => {
+ if (projectRef) getSubscription()
+ }, [projectRef])
+
+ const getSubscription = async () => {
+ try {
+ setLoading(true)
+
+ if (!ui.selectedProject?.subscription_id) {
+ throw new Error('Unable to get subscription ID of project')
+ }
+
+ const { data: subscription, error }: { data: StripeSubscription; error: any } = await post(
+ `${API_URL}/stripe/subscription`,
+ { subscription_id: ui.selectedProject.subscription_id }
+ )
+
+ if (error) throw error
+ setSubscription(subscription)
+ } catch (error: any) {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Failed to get subscription: ${error.message}`,
+ })
+ } finally {
+ setLoading(false)
+ }
+ }
+
+ const onSelectPlan = (plan: BillingPlan) => {
+ console.log('Selected plan', plan)
+ }
return (
<BillingLayout>
- <div className="space-y-4">
+ <div className="space-y-8">
<h4 className="text-xl">Change your project's subscription</h4>
- <Plans />
+ {/* FE will make a call to fetch all plans first at the page level */}
+ <Loading active={loading}>
+ <Plans plans={BILLING_PLANS} currentPlan={subscription} onSelectPlan={onSelectPlan} />
+ </Loading>
+ <div className="flex justify-center items-center">
+ <Link href="https://supabase.com/pricing">
+ <a target="_blank" className="text-sm text-scale-1100 hover:text-scale-1200 transition">
+ See detailed comparisons across plans
+ </a>
+ </Link>
+ </div>
</div>
</BillingLayout>
)
diff --git a/studio/tailwind.config.js b/studio/tailwind.config.js
index 04cc7542c92..86cea8a290b 100644
--- a/studio/tailwind.config.js
+++ b/studio/tailwind.config.js
@@ -280,6 +280,28 @@ module.exports = ui({
// dark: green[300],
// },
},
+ animation: {
+ shimmer: 'shimmer 2s infinite linear',
+ sway: 'sway 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
+ },
+ keyframes: {
+ shimmer: {
+ '0%': {
+ 'background-position': '-1000px 0',
+ },
+ '100%': {
+ 'background-position': '1000px 0',
+ },
+ },
+ sway: {
+ '0%, 100%': {
+ transform: 'rotate(-10deg) scale(1.5) translateY(4rem)',
+ },
+ '50%': {
+ transform: 'rotate(10deg) scale(1.5) translateY(2rem)',
+ },
+ },
+ },
},
fontFamily: {
sans: ['circular', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif'],
diff --git a/studio/types/base.ts b/studio/types/base.ts
index cb08f2e82d9..0542c000520 100644
--- a/studio/types/base.ts
+++ b/studio/types/base.ts
@@ -23,8 +23,11 @@ export interface Project {
region: string
connectionString: string
inserted_at: string
- subscription_tier: string
- subscription_tier_prod_id: string
+ subscription_id: string
+
+ // Possibly deprecated, just double check
+ subscription_tier?: string
+ subscription_tier_prod_id?: string
}
export interface User {