Files
supabase/apps/studio/components/ui/UpgradeToPro.tsx
Danny WhiteandJoshen Lim bd57a73521 feat: clearer upload limits (#38272)
* feat: basic clarity improvements

* feat: all switches

* feat: basic errors

* fix: simplify

* fix: properly separate sections

* fix: remove smart toggle closure

* fix: remember file size unit

* fix: validation

* fix: UpgradeToPro styles

* fix: UpgradeToPro styles for full-width

* feat: create modal match

* fix: tests

* Small fix for error message and desc for file size limit in create and edit bucket modals

* Prettify error message handling for storage settings

* Nit

* set default unit as MB

* dotted underline and default cursor for tooltip

* fix: default MB tests

* minor form style and copy improvements

* remove extraneous divs

* fix mime check on bucket creation

* Clean up + minor refactors including improving perms loading state in storage settings

* EditBucketModal ensure that file size limit unit defaults to MB if bucket doesnt have a file size limit

* Refactor EditBucketModal to use react query mutation

* Refactor

* Fix unit tests for edit bucket modal

* last round of clean up

* last fix

* Tiny unrelated fix

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-09-03 12:05:34 +10:00

102 lines
3.3 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import Link from 'next/link'
import { ReactNode } from 'react'
import { useFlag } from 'common'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { Button, cn } from 'ui'
import { ButtonTooltip } from './ButtonTooltip'
interface UpgradeToProProps {
icon?: ReactNode
primaryText: string
secondaryText: string
addon?: 'pitr' | 'customDomain'
buttonText?: string
source?: string
disabled?: boolean
fullWidth?: boolean
}
const UpgradeToPro = ({
icon,
primaryText,
secondaryText,
addon,
buttonText,
source = 'upgrade',
disabled = false,
fullWidth = false,
}: UpgradeToProProps) => {
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
const plan = organization?.plan?.id
const canUpdateSubscription = useCheckPermissions(
PermissionAction.BILLING_WRITE,
'stripe.subscriptions'
)
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
return (
<div
className={cn(
'block w-full py-4 px-6 bg-surface-200',
fullWidth ? 'border-b' : 'border border-opacity-20 border-overlay rounded'
)}
>
<div className="flex gap-x-3">
{icon && <div className="mt-1">{icon}</div>}
<div className="flex flex-col md:flex-row w-full md:items-center justify-between gap-4 md:gap-x-8">
<div className="space-y-1 flex-1 max-w-2xl">
<p className="text-sm">{primaryText}</p>
<div>
<p className="text-sm text-foreground-light">{secondaryText}</p>
</div>
</div>
{!canUpdateSubscription || projectUpdateDisabled ? (
<ButtonTooltip
disabled
type="primary"
tooltip={{
content: {
side: 'bottom',
text: projectUpdateDisabled
? 'Subscription changes are currently disabled, our engineers are working on a fix'
: !canUpdateSubscription
? 'You need additional permissions to amend subscriptions'
: undefined,
},
}}
>
{buttonText || (plan === 'free' ? 'Upgrade to Pro' : 'Enable add on')}
</ButtonTooltip>
) : (
<Button
asChild
type="primary"
disabled={!canUpdateSubscription || projectUpdateDisabled || disabled}
>
<Link
href={
plan === 'free'
? `/org/${organization?.slug ?? '_'}/billing?panel=subscriptionPlan&source=${source}`
: addon == null
? `/org/${organization?.slug ?? '_'}/billing?panel=costControl&source=${source}`
: `/project/${project?.ref ?? '_'}/settings/addons?panel=${addon}&source=${source}`
}
>
{buttonText || (plan === 'free' ? 'Upgrade to Pro' : 'Enable add on')}
</Link>
</Button>
)}
</div>
</div>
</div>
)
}
export default UpgradeToPro