Skip to content

Commit 93b92f1

Browse files
authored
Refactor to share HOURLY_RATES between components (#23)
1 parent df2f166 commit 93b92f1

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/components/react/BillingCalculator.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@/components/ui/select';
1919
import { Switch } from '@/components/ui/switch';
2020
import { cn } from '@/lib/utils';
21+
import { HOURLY_RATES } from './PricingRates';
2122

2223
// Fixed Sprite resources per active hour
2324
const VCPUS = 8;
@@ -43,13 +44,6 @@ const PAYG = {
4344
storageGB: 0,
4445
};
4546

46-
// Usage pricing (same for overage and PAYG)
47-
const RATES = {
48-
cpuHour: 0.07,
49-
ramGBHour: 0.04375,
50-
storageGB: 0.5,
51-
};
52-
5347
type BillingMode = 'plan' | 'payg';
5448

5549
export function BillingCalculator() {
@@ -90,11 +84,11 @@ export function BillingCalculator() {
9084

9185
// Calculate usage costs (overage for plan, full cost for PAYG)
9286
const cpuCost =
93-
Math.max(0, cpuHoursUsed - currentPlan.cpuHours) * RATES.cpuHour;
87+
Math.max(0, cpuHoursUsed - currentPlan.cpuHours) * HOURLY_RATES.cpu;
9488
const ramCost =
95-
Math.max(0, ramGBHoursUsed - currentPlan.ramGBHours) * RATES.ramGBHour;
89+
Math.max(0, ramGBHoursUsed - currentPlan.ramGBHours) * HOURLY_RATES.ram;
9690
const storageCost =
97-
Math.max(0, storageGBUsed - currentPlan.storageGB) * RATES.storageGB;
91+
Math.max(0, storageGBUsed - currentPlan.storageGB) * HOURLY_RATES.storage;
9892
const usageCost = cpuCost + ramCost + storageCost;
9993

10094
const totalCost = currentPlan.price + usageCost;

src/components/react/PricingRates.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
import { Switch } from '@/components/ui/switch';
33

4-
const HOURLY_RATES = {
4+
export const HOURLY_RATES = {
55
cpu: 0.07,
66
ram: 0.04375,
77
storage: 0.5,

0 commit comments

Comments
 (0)