Selaa lähdekoodia

Fix total cost resetting (#4613)

Mauricio Araujo 2 vuotta sitten
vanhempi
sitoutus
8c119e7bf4
1 muutettua tiedostoa jossa 7 lisäystä ja 3 poistoa
  1. 7 3
      dashboard/src/main/home/project-settings/UsagePage.tsx

+ 7 - 3
dashboard/src/main/home/project-settings/UsagePage.tsx

@@ -7,6 +7,7 @@ import Fieldset from "components/porter/Fieldset";
 import Select from "components/porter/Select";
 import Select from "components/porter/Select";
 import Spacer from "components/porter/Spacer";
 import Spacer from "components/porter/Spacer";
 import Text from "components/porter/Text";
 import Text from "components/porter/Text";
+import { type CostList } from "lib/billing/types";
 import {
 import {
   useCustomerCosts,
   useCustomerCosts,
   useCustomerPlan,
   useCustomerPlan,
@@ -41,7 +42,11 @@ function UsagePage(): JSX.Element {
     currentPeriodEnd,
     currentPeriodEnd,
     currentPeriodDuration
     currentPeriodDuration
   );
   );
-  let totalCost = 0;
+
+  const computeTotalCost = (costs: CostList): number => {
+    const total = costs.reduce((acc, curr) => acc + curr.cost, 0);
+    return parseFloat(total.toFixed(2));
+  };
 
 
   const processedUsage = useMemo(() => {
   const processedUsage = useMemo(() => {
     const before = usage;
     const before = usage;
@@ -84,7 +89,6 @@ function UsagePage(): JSX.Element {
           day: "numeric",
           day: "numeric",
         });
         });
         dailyCost.cost = parseFloat((dailyCost.cost / 100).toFixed(4));
         dailyCost.cost = parseFloat((dailyCost.cost / 100).toFixed(4));
-        totalCost += dailyCost.cost;
         return dailyCost;
         return dailyCost;
       })
       })
       .filter((dailyCost) => dailyCost.cost > 0);
       .filter((dailyCost) => dailyCost.cost > 0);
@@ -131,7 +135,7 @@ function UsagePage(): JSX.Element {
       usage[0].usage_metrics.length > 0 ? (
       usage[0].usage_metrics.length > 0 ? (
         <>
         <>
           <BarWrapper>
           <BarWrapper>
-            <Total>Total cost: ${totalCost.toFixed(2)}</Total>
+            <Total>Total cost: ${computeTotalCost(costs)}</Total>
             <Bars
             <Bars
               fill="#8784D2"
               fill="#8784D2"
               yKey="cost"
               yKey="cost"