import { ChevronRight } from 'lucide-react' import { UseFormReturn } from 'react-hook-form' import { ButtonTooltip } from 'components/ui/ButtonTooltip' import { Badge, Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogSectionSeparator, DialogTitle, DialogTrigger, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from 'ui' import BillingChangeBadge from './BillingChangeBadge' import { DiskStorageSchemaType } from './DiskManagementPanelSchema' import { DiskMangementCoolDownSection } from './DiskManagementCoolDownSection' import { calculateDiskSizePrice, calculateIOPSPrice, calculateThroughputPrice, } from './DiskManagement.utils' import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query' import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization' import { DiskType } from './DiskManagement.constants' import { formatCurrency } from 'lib/helpers' const TableHeaderRow = () => ( Disk attribute - Unit Price Change ) interface TableDataRowProps { attribute: string defaultValue: string | number newValue: string | number unit: string beforePrice: number afterPrice: number hidePrice?: boolean priceTooltip?: string } const TableDataRow = ({ attribute, defaultValue, newValue, unit, beforePrice, afterPrice, hidePrice = false, priceTooltip, }: TableDataRowProps) => ( {attribute} {defaultValue !== newValue ? ( {defaultValue} {newValue} ) : ( {defaultValue} )} {unit} {hidePrice ? ( - ) : beforePrice !== afterPrice ? ( ) : ( {formatCurrency(beforePrice)} )} ) interface DiskSizeMeterProps { loading: boolean form: UseFormReturn numReplicas: number isDialogOpen: boolean isWithinCooldown: boolean setIsDialogOpen: (isOpen: boolean) => void onSubmit: (values: DiskStorageSchemaType) => Promise } export const DiskManagementReviewAndSubmitDialog = ({ isDialogOpen, setIsDialogOpen, isWithinCooldown, form, numReplicas, loading, onSubmit, }: DiskSizeMeterProps) => { const org = useSelectedOrganization() const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug }) const planId = subscription?.plan.id ?? '' const isDirty = Object.keys(form.formState.dirtyFields).length > 0 const replicaTooltipText = `Price change includes primary database and ${numReplicas} replica${numReplicas > 1 ? 's' : ''}` const diskSizePrice = calculateDiskSizePrice({ planId, oldSize: form.formState.defaultValues?.totalSize || 0, oldStorageType: form.formState.defaultValues?.storageType as DiskType, newSize: form.getValues('totalSize'), newStorageType: form.getValues('storageType') as DiskType, numReplicas, }) const iopsPrice = calculateIOPSPrice({ oldStorageType: form.formState.defaultValues?.storageType as DiskType, oldProvisionedIOPS: form.formState.defaultValues?.provisionedIOPS || 0, newStorageType: form.getValues('storageType') as DiskType, newProvisionedIOPS: form.getValues('provisionedIOPS'), numReplicas, }) const throughputPrice = calculateThroughputPrice({ storageType: form.getValues('storageType') as DiskType, newThroughput: form.getValues('throughput') || 0, oldThroughput: form.formState.defaultValues?.throughput || 0, numReplicas, }) return ( { e.preventDefault() const isValid = await form.trigger() if (isValid) setIsDialogOpen(true) }} disabled={isWithinCooldown || !isDirty} tooltip={{ content: { side: 'bottom', text: isWithinCooldown ? 'Currently within cooldown period from previous disk change' : undefined, }, }} > Review changes Review changes Disk configuration changes will be applied shortly once confirmed. 0 ? replicaTooltipText : undefined} /> {form.getValues('storageType') === 'gp3' ? ( 0 ? replicaTooltipText : undefined} /> ) : ( Throughput Throughput is not configurable for io2 storage type )} 0 ? replicaTooltipText : undefined} /> setIsDialogOpen(false)}> Cancel { await onSubmit(form.getValues()) }} > Confirm changes ) }
Throughput is not configurable for io2 storage type