The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Implement upgrade to pro flow
Joshen Lim0f80f7102f89
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.constant.ts b/studio/components/interfaces/Billing/AddOns/AddOns.constant.tsnew file mode 100644index 00000000000..b847bfe806f--- /dev/null+++ b/studio/components/interfaces/Billing/AddOns/AddOns.constant.ts@@ -0,0 +1,38 @@+// Temp hard-code+export const COMPUTE_SIZES = [+ {+ id: 1,+ name: 'Small',+ description: 'Great for personal projects and experiments',+ specs: '2 CPUs • 1GB memory • 2,085Mbps Disk IO',+ price: 0,+ },+ {+ id: 2,+ name: 'Medium',+ description: 'Great for projects that are starting to gain traction',+ specs: '2 CPUs • 4GB memory • 2,085Mbps Disk IO',+ price: 50,+ },+ {+ id: 3,+ name: 'Large',+ description: 'For a large project that receives a decent amount of traffic',+ specs: '2 CPUs • 8GB memory • 4,750Mbps Disk IO',+ price: 100,+ },+ {+ id: 4,+ name: 'X-Large',+ description: 'For a large project that receives a sizeable amount of traffic',+ specs: '4 CPUs • 16GB memory • 4,750Mbps Disk IO',+ price: 200,+ },+ {+ id: 5,+ name: 'XX-Large',+ description: 'For a huge project that receives heavy amount of traffic',+ specs: '8 CPUs • 32GB memory • 4,750Mbps Disk IO',+ price: 400,+ },+]diff --git a/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsxnew file mode 100644index 00000000000..709beeb7e37--- /dev/null+++ b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx@@ -0,0 +1,46 @@+import { FC } from 'react'+import { Radio } from '@supabase/ui'+import { COMPUTE_SIZES } from './AddOns.constant'++// [TODO] please type the vairables properly++interface Props {+ selectedComputeSize: any+ onSelectOption: (option: any) => void+}++const ComputeSizeSelection: FC<Props> = ({ selectedComputeSize, onSelectOption }) => {+ return (+ <div className="space-y-4">+ <div>+ <p>Compute size</p>+ <p className="text-sm text-scale-1100">+ Choose the database instance size that best fits your needs+ </p>+ </div>+ <Radio.Group type="cards" className="billing-compute-radio">+ {COMPUTE_SIZES.map((option: any) => (+ <Radio+ hidden+ key={option.id}+ align="vertical"+ label={option.name}+ // @ts-ignore+ description={+ <div>+ <p>{option.description}</p>+ <p>{option.specs}</p>+ </div>+ }+ value={option.id}+ optionalLabel={<div>${option.price} / month</div>}+ checked={selectedComputeSize?.id === option.id}+ onChange={() => onSelectOption(option)}+ />+ ))}+ </Radio.Group>+ </div>+ )+}++export default ComputeSizeSelectiondiff --git a/studio/components/interfaces/Billing/ComputeSizeSelection/ComputeSizeSelection.tsx b/studio/components/interfaces/Billing/ComputeSizeSelection/ComputeSizeSelection.tsxdeleted file mode 100644index eb6c1f98f5d..00000000000--- a/studio/components/interfaces/Billing/ComputeSizeSelection/ComputeSizeSelection.tsx+++ /dev/null@@ -1,9 +0,0 @@-import { FC } from 'react'--interface Props {}--const ComputeSizeSelection: FC<Props> = ({}) => {- return <div />-}--export default ComputeSizeSelectiondiff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel.tsxindex 87327b3f853..a70ccf46a4d 100644--- a/studio/components/interfaces/Billing/PaymentSummaryPanel.tsx+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel.tsx@@ -1,27 +1,83 @@-import Divider from 'components/ui/Divider'import { FC } from 'react'+import { StripeSubscription } from '.'+import { BillingPlan } from './PlanSelection/Plans/Plans.types'-interface Props {}+interface Props {+ currentPlan: StripeSubscription+ selectedPlan?: BillingPlan+ currentComputeSize?: any+ selectedComputeSize: any+ isOverageEnabled: boolean+}++// Use case of this panel is actually only for upgrading from Free to Pro+// OR managing Pro configuration. For simplicity, we code this component+// within this boundary++// [Joshen] Eventually if we do support more addons, it'll be better to generalize+// the selectedComputeSize to an addOns array. But for now, we keep it simple++const PaymentSummaryPanel: FC<Props> = ({+ currentPlan,+ selectedPlan,+ isOverageEnabled,+ currentComputeSize,+ selectedComputeSize,+}) => {+ const isChangingPlan = selectedPlan !== undefined+ const totalMonthlyCost = (selectedPlan?.price ?? 0) + selectedComputeSize.price-const PaymentSummaryPanel: FC<Props> = ({}) => {return (<divclassName="bg-scale-300 w-full px-20 py-10 space-y-8"style={{ height: 'calc(100vh - 49.5px)' }}><p>Payment Summary</p>++ {/* Subscription details */}<div className="space-y-1"><p className="text-sm">Selected subscription</p>+ <div className="flex items-center justify-between">+ <p className={`${isChangingPlan ? 'text-scale-1100 line-through' : ''} text-sm`}>+ {currentPlan.tier.name}+ </p>+ <p className={`${isChangingPlan ? 'text-scale-1100 line-through' : ''} text-sm`}>+ ${currentPlan.tier.unit_amount}+ </p>+ </div>+ {isChangingPlan && (+ <div className="flex items-center justify-between">+ <p className="text-sm">+ {selectedPlan?.name} {isOverageEnabled ? '(Overages enabled)' : ''}+ </p>+ <p className="text-sm">${selectedPlan?.price}</p>+ </div>+ )}</div>++ {/* Add on details */}<div className="space-y-1"><p className="text-sm">Selected add-ons</p>+ {currentComputeSize === undefined && selectedComputeSize === undefined && (+ <p className="text-scale-1100 text-sm">No add-ons selected</p>+ )}+ {selectedComputeSize !== undefined && (+ <div className="flex items-center justify-between">+ <p className="text-sm">Optimized database instance ({selectedComputeSize.name})</p>+ <p className="text-sm">${selectedComputeSize.price}</p>+ </div>+ )}</div>+<div className="h-px w-full bg-scale-600"></div>++ {/* Payment total */}<div className="flex items-start justify-between space-x-16"><div className="space-y-1"><p>Amount due immediately</p><p className="text-sm text-scale-1100">- Your next invoice of $25 + usage fees will be charged on the 1st February 2022+ Your next invoice of ${totalMonthlyCost} {isOverageEnabled && '+ usage fees '}will be+ charged on the 1st February 2022</p></div><div className="flex justify-end items-end">diff --git a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsxindex 512ce2bd760..932a5bfc329 100644--- a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx+++ b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx@@ -1,6 +1,5 @@import Link from 'next/link'import { FC } from 'react'-import { Loading } from '@supabase/ui'import { Transition } from '@headlessui/react'import Plans from './Plans/Plans'@@ -28,9 +27,7 @@ const PlanSelection: FC<Props> = ({ visible, billingPlans, currentPlan, onSelect<div className="space-y-8"><h4 className="text-lg">Change your project's subscription</h4>{/* FE will make a call to fetch all plans first at the page level */}- <Loading active={!currentPlan}>- <Plans plans={billingPlans} currentPlan={currentPlan} onSelectPlan={onSelectPlan} />- </Loading>+ <Plans plans={billingPlans} currentPlan={currentPlan} onSelectPlan={onSelectPlan} /><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">diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsxindex b57644ec21b..75de767aeca 100644--- a/studio/components/interfaces/Billing/ProUpgrade.tsx+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx@@ -1,16 +1,27 @@-import { FC } from 'react'+import { FC, useState } from 'react'import { Transition } from '@headlessui/react'import { Badge, Button, IconArrowLeft, IconHelpCircle, Toggle } from '@supabase/ui'-import { PaymentSummaryPanel } from '.'import Divider from 'components/ui/Divider'+import { PaymentSummaryPanel, ComputeSizeSelection, StripeSubscription } from '.'+import { BillingPlan } from './PlanSelection/Plans/Plans.types'+import { COMPUTE_SIZES } from './AddOns/AddOns.constant'interface Props {visible: boolean+ currentPlan: StripeSubscription+ selectedPlan?: BillingPlanonSelectBack: () => void}-const ProUpgrade: FC<Props> = ({ visible, onSelectBack }) => {+const ProUpgrade: FC<Props> = ({ visible, currentPlan, selectedPlan, onSelectBack }) => {+ const [isOverageEnabled, setIsOverageEnabled] = useState(false)+ const [selectedComputeSize, setSelectedComputeSize] = useState<any>(COMPUTE_SIZES[0])++ const onSelectComputeSizeOption = (option: any) => {+ setSelectedComputeSize(option)+ }+return (<Transitionshow={visible}@@ -22,7 +33,7 @@ const ProUpgrade: FC<Props> = ({ visible, onSelectBack }) => {{visible && (<><div className="space-y-8 w-3/5">- <div className="relative ml-64 mr-20">+ <div className="relative ml-64"><div className="absolute top-[2px] -left-24"><Button type="text" icon={<IconArrowLeft />} onClick={onSelectBack}>Back@@ -30,41 +41,58 @@ const ProUpgrade: FC<Props> = ({ visible, onSelectBack }) => {</div><div className="space-y-8"><h4 className="text-lg">Change your project's subscription</h4>- <div className="space-y-1">- <h3 className="text-xl">- Welcome to <span className="text-green-1100">Pro</span>- <p className="text-sm text-scale-1100">- Your new subscription will begin immediately after payment- </p>- </h3>- </div>- <div className="flex items-start justify-between">- <div>- <div className="flex items-center space-x-2">- <p>Enable overages</p>- <IconHelpCircle- size={16}- strokeWidth={1.5}- className="cursor-pointer opacity-50 hover:opacity-100 transition"- onClick={() => {}}- />+ <div+ className="space-y-8 overflow-scroll pb-8 pr-20"+ style={{ height: 'calc(100vh - 6.3rem - 49.5px)' }}+ >+ <div className="space-y-1">+ <h3 className="text-xl">+ Welcome to <span className="text-green-1100">Pro</span>+ <p className="text-sm text-scale-1100">+ Your new subscription will begin immediately after payment+ </p>+ </h3>+ </div>+ <div className="flex items-start justify-between">+ <div>+ <div className="flex items-center space-x-2">+ <p>Enable overages</p>+ <IconHelpCircle+ size={16}+ strokeWidth={1.5}+ className="cursor-pointer opacity-50 hover:opacity-100 transition"+ onClick={() => {}}+ />+ </div>+ <p className="text-sm text-scale-1100">+ Additional resources will be charged on a usage basis+ </p></div>- <p className="text-sm text-scale-1100">- Additional resources will be charged on a usage basis- </p>+ <Toggle+ checked={isOverageEnabled}+ onChange={() => setIsOverageEnabled(!isOverageEnabled)}+ /></div>- <Toggle />- </div>- <Divider light />- <div className="flex items-center space-x-2">- <h4 className="text-lg">Extend your project with add-ons</h4>- <Badge color="green">Optional</Badge>+ <Divider light />+ <div className="flex items-center space-x-2">+ <h4 className="text-lg">Extend your project with add-ons</h4>+ <Badge color="green">Optional</Badge>+ </div>+ <ComputeSizeSelection+ selectedComputeSize={selectedComputeSize}+ onSelectOption={onSelectComputeSizeOption}+ /></div></div></div></div><div className="w-2/5 -mt-10">- <PaymentSummaryPanel />+ <PaymentSummaryPanel+ currentPlan={currentPlan}+ selectedPlan={selectedPlan}+ isOverageEnabled={isOverageEnabled}+ selectedComputeSize={selectedComputeSize}+ /></div></>)}diff --git a/studio/components/interfaces/Billing/index.ts b/studio/components/interfaces/Billing/index.tsindex c5d4148b731..08a91524fbd 100644--- a/studio/components/interfaces/Billing/index.ts+++ b/studio/components/interfaces/Billing/index.ts@@ -1,10 +1,12 @@import PAYGUsage from './PAYGUsage/PAYGUsage'import Subscription from './Subscription/Subscription'+import PlanSelection from './PlanSelection/PlanSelection'import ProUpgrade from './ProUpgrade'import EnterpriseRequest from './EnterpriseRequest'import ExitSurvey from './ExitSurvey'import PaymentSummaryPanel from './PaymentSummaryPanel'+import ComputeSizeSelection from './AddOns/ComputeSizeSelection'export * from './Subscription/Subscription.types'export * from './PAYGUsage/PAYGUsage.constants'@@ -16,4 +18,5 @@ export {EnterpriseRequest,ExitSurvey,PaymentSummaryPanel,+ ComputeSizeSelection,}diff --git a/studio/pages/project/[ref]/settings/billing/update.tsx b/studio/pages/project/[ref]/settings/billing/update.tsxindex 4861a03b20a..7ceb7444b84 100644--- a/studio/pages/project/[ref]/settings/billing/update.tsx+++ b/studio/pages/project/[ref]/settings/billing/update.tsx@@ -102,7 +102,14 @@ const BillingUpdate: NextPage = () => {/></div>- <ProUpgrade visible={showProPlanPage} onSelectBack={() => setSelectedPlan(undefined)} />+ {subscription !== undefined && (+ <ProUpgrade+ visible={showProPlanPage}+ currentPlan={subscription}+ selectedPlan={selectedPlan}+ onSelectBack={() => setSelectedPlan(undefined)}+ />+ )}<ConfirmModaldanger@@ -118,6 +125,7 @@ const BillingUpdate: NextPage = () => {}}onSelectConfirm={onConfirmDowngrade}/>+<Modalvisible={showDowngradeError}size="small"diff --git a/studio/styles/main.scss b/studio/styles/main.scssindex 61c8b616732..e9c89b1380e 100644--- a/studio/styles/main.scss+++ b/studio/styles/main.scss@@ -178,3 +178,9 @@ code {div[data-radix-portal]:not(.portal--toast) {z-index: 2147483646 !important;}++.billing-compute-radio {+ label {+ @apply items-center justify-between;+ }+}