SpendCapDisabledSection.tsx69 lines · main
1import { AnimatePresence, motion } from 'framer-motion'
2import Link from 'next/link'
3import { AlertDescription, AlertTitle, buttonVariants, cn } from 'ui'
4import { Admonition } from 'ui-patterns/admonition'
5
6import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
7import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
8
9interface SpendCapDisabledSectionProps {
10 currentDiskSizeGb?: number
11}
12
13export function SpendCapDisabledSection({ currentDiskSizeGb }: SpendCapDisabledSectionProps) {
14 const { data: org, isPending: isOrgPending } = useSelectedOrganizationQuery()
15 const { data: project, isPending: isProjectPending } = useSelectedProjectQuery()
16
17 const isSpendCapEnabled =
18 !isOrgPending &&
19 !isProjectPending &&
20 org?.plan.id !== 'free' &&
21 !org?.usage_billing_enabled &&
22 project?.cloud_provider !== 'FLY'
23
24 const showAutoExpandNotice =
25 isSpendCapEnabled &&
26 currentDiskSizeGb !== undefined &&
27 currentDiskSizeGb > 0 &&
28 currentDiskSizeGb < 8
29
30 return (
31 <AnimatePresence>
32 {isSpendCapEnabled && (
33 <motion.div
34 initial={{ opacity: 0, height: 0 }}
35 animate={{ opacity: 1, height: 'auto' }}
36 exit={{ opacity: 0, height: 0 }}
37 transition={{ duration: 0.2 }}
38 className="flex flex-col gap-3"
39 >
40 {showAutoExpandNotice && (
41 <Admonition type="default">
42 <AlertTitle>Your disk will auto-expand to 8 GB</AlertTitle>
43 <AlertDescription>
44 The first time your database usage triggers a resize, your disk will automatically
45 expand to at least 8 GB. You don&apos;t need to disable spend cap or do anything
46 manually for this to happen.
47 </AlertDescription>
48 </Admonition>
49 )}
50 <Admonition type="default">
51 <AlertTitle>Spend cap limits disk size to 8 GB</AlertTitle>
52 <AlertDescription>
53 You can resize your disk up to 8 GB with spend cap enabled. To expand beyond 8 GB or
54 configure IOPS, throughput, and storage type, disable your spend cap.
55 </AlertDescription>
56 <div className="mt-3">
57 <Link
58 href={`/org/${org?.slug}/billing?panel=costControl`}
59 className={cn(buttonVariants({ type: 'default', size: 'tiny' }))}
60 >
61 Disable spend cap
62 </Link>
63 </div>
64 </Admonition>
65 </motion.div>
66 )}
67 </AnimatePresence>
68 )
69}