Skip to content

Commit 8ce3db1

Browse files
committed
chore(5795): seperate out function for pdf download
1 parent 199e4cd commit 8ce3db1

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

app/app/private-cloud/products/(product)/[licencePlate]/costs/page.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ export default privateCloudProductCosts(({ getPathParams, session }) => {
167167
}
168168
};
169169

170+
async function handleDownloadCostPdf() {
171+
if (!costData) return;
172+
setDownloading(true);
173+
const downloadPDF =
174+
{
175+
[TimeView.Monthly]: () => downloadPrivateCloudMonthlyCosts(licencePlate, format(selectedDate, 'yyyy-MM')),
176+
[TimeView.Quarterly]: () => downloadPrivateCloudQuarterlyCosts(licencePlate, formatAsYearQuarter(selectedDate)),
177+
}[viewMode] || (() => downloadPrivateCloudYearlyCosts(licencePlate, selectedDate.getFullYear().toString()));
178+
await downloadPDF();
179+
setDownloading(false);
180+
}
181+
170182
return (
171183
<div className="space-y-5">
172184
<Box pos="relative">
@@ -183,18 +195,7 @@ export default privateCloudProductCosts(({ getPathParams, session }) => {
183195
<Button
184196
loading={downloading}
185197
onClick={async () => {
186-
if (!costData) return;
187-
setDownloading(true);
188-
const downloadPDF =
189-
{
190-
[TimeView.Monthly]: () =>
191-
downloadPrivateCloudMonthlyCosts(licencePlate, format(selectedDate, 'yyyy-MM')),
192-
[TimeView.Quarterly]: () =>
193-
downloadPrivateCloudQuarterlyCosts(licencePlate, formatAsYearQuarter(selectedDate)),
194-
}[viewMode] ||
195-
(() => downloadPrivateCloudYearlyCosts(licencePlate, selectedDate.getFullYear().toString()));
196-
await downloadPDF();
197-
setDownloading(false);
198+
handleDownloadCostPdf();
198199
}}
199200
className="absolute right-0 top-[10px]"
200201
>

app/components/private-cloud/monthly-cost/MonthlyCostTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { formatDate } from '@/utils/js/date';
44
import { formatCurrency } from '@/utils/js/number';
55

66
export default function MonthlyCostTable({ data }: { data: MonthlyCost }) {
7+
const dailyCost = getDailyCostData(data);
8+
const currenTotalCost = calculateTotalCost(dailyCost);
79
return (
810
<>
911
<table className="w-full text-sm border-collapse">
@@ -92,7 +94,7 @@ export default function MonthlyCostTable({ data }: { data: MonthlyCost }) {
9294
<strong>Current total cost for {data.billingPeriod}</strong>
9395
</td>
9496
<td colSpan={1} className="p-2 border-b text-center">
95-
<strong>{formatCurrency(calculateTotalCost(getDailyCostData(data)))}</strong>
97+
<strong>{formatCurrency(currenTotalCost)}</strong>
9698
</td>
9799
</tr>
98100
</tfoot>

app/components/private-cloud/quarterly-cost/QuarterlyCostTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { formatDate, getMonthNameFromNumber } from '@/utils/js/date';
44
import { formatCurrency } from '@/utils/js/number';
55

66
export default function QuarterlyCostTable({ data }: { data: QuarterlyCost }) {
7+
const monthlyCost = getMonthlyCostData(data);
8+
const currenTotalCost = calculateTotalCost(monthlyCost);
79
return (
810
<>
911
<table className="w-full text-sm border-collapse">
@@ -92,7 +94,7 @@ export default function QuarterlyCostTable({ data }: { data: QuarterlyCost }) {
9294
<strong>Current total cost for {data.billingPeriod}</strong>
9395
</td>
9496
<td colSpan={1} className="p-2 border-b text-center">
95-
<strong>{formatCurrency(calculateTotalCost(getMonthlyCostData(data)))}</strong>
97+
<strong>{formatCurrency(currenTotalCost)}</strong>
9698
</td>
9799
</tr>
98100
</tfoot>

app/components/private-cloud/yearly-cost/YearlyCostTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { formatDate, getMonthNameFromNumber } from '@/utils/js/date';
44
import { formatCurrency } from '@/utils/js/number';
55

66
export default function YearlyCostTable({ data }: { data: YearlyCost }) {
7+
const monthlyCost = getMonthlyCostData(data);
8+
const currenTotalCost = calculateTotalCost(monthlyCost);
79
return (
810
<>
911
<table className="w-full text-sm border-collapse">
@@ -92,7 +94,7 @@ export default function YearlyCostTable({ data }: { data: YearlyCost }) {
9294
<strong>Current total cost for {data.billingPeriod}</strong>
9395
</td>
9496
<td colSpan={1} className="p-2 border-b text-center">
95-
<strong>{formatCurrency(calculateTotalCost(getMonthlyCostData(data)))}</strong>
97+
<strong>{formatCurrency(currenTotalCost)}</strong>
9698
</td>
9799
</tr>
98100
</tfoot>

0 commit comments

Comments
 (0)