-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add transactions pie charts component
- Loading branch information
Showing
10 changed files
with
875 additions
and
50 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/(authenticated)/dashboard/_components/percentage-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
interface PercentageItemProps { | ||
icon: React.ReactNode; | ||
title: string; | ||
value: number; | ||
} | ||
|
||
const PercentageItem = ({ icon, title, value }: PercentageItemProps) => { | ||
return ( | ||
<div className="flex items-center justify-between"> | ||
{/* Icone */} | ||
<div className="flex items-center gap-2"> | ||
{icon} | ||
<p>{title}</p> | ||
</div> | ||
<p className="text-sm font-bold">{value}%</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PercentageItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/(authenticated)/dashboard/_components/transactions-pie-chart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { Pie, PieChart } from "recharts"; | ||
|
||
import { | ||
ChartConfig, | ||
ChartContainer, | ||
ChartTooltip, | ||
ChartTooltipContent, | ||
} from "@/app/_components/ui/chart"; | ||
import { TransactionType } from "@prisma/client"; | ||
import { Card, CardContent } from "@/app/_components/ui/card"; | ||
import { PiggyBankIcon, TrendingDownIcon, TrendingUpIcon } from "lucide-react"; | ||
import type { TransactionPercentagesPerType } from "@/app/_data/get-dashboard/types"; | ||
import PercentageItem from "./percentage-item"; | ||
|
||
interface TransactionsPieChartProps { | ||
depositsTotal: number; | ||
investmentsTotal: number; | ||
expensesTotal: number; | ||
typesPercentages: TransactionPercentagesPerType; | ||
} | ||
|
||
const chartConfig = { | ||
[TransactionType.INVESTMENT]: { | ||
label: "Investido", | ||
color: "#FFF", | ||
}, | ||
[TransactionType.DEPOSIT]: { | ||
label: "Receita", | ||
color: "#55B02E", | ||
}, | ||
[TransactionType.EXPENSE]: { | ||
label: "Despesa", | ||
color: "#E93030", | ||
}, | ||
} satisfies ChartConfig; | ||
|
||
const TransactionsPieChart = ({ | ||
depositsTotal, | ||
investmentsTotal, | ||
expensesTotal, | ||
typesPercentages, | ||
}: TransactionsPieChartProps) => { | ||
const chartData = [ | ||
{ | ||
type: TransactionType.DEPOSIT, | ||
amount: depositsTotal, | ||
fill: "#55B02E", | ||
}, | ||
{ | ||
type: TransactionType.INVESTMENT, | ||
amount: investmentsTotal, | ||
fill: "#FFF", | ||
}, | ||
{ | ||
type: TransactionType.EXPENSE, | ||
amount: expensesTotal, | ||
fill: "#E93030", | ||
}, | ||
]; | ||
|
||
return ( | ||
<Card className="flex flex-col py-12"> | ||
<CardContent className="flex-1 pb-0"> | ||
<ChartContainer | ||
config={chartConfig} | ||
className="mx-auto aspect-square max-h-[250px]" | ||
> | ||
<PieChart> | ||
<ChartTooltip | ||
cursor={false} | ||
content={<ChartTooltipContent hideLabel />} | ||
/> | ||
<Pie | ||
data={chartData} | ||
dataKey="amount" | ||
nameKey="type" | ||
innerRadius={60} | ||
strokeWidth={5} | ||
></Pie> | ||
</PieChart> | ||
</ChartContainer> | ||
<div className="space-y-2"> | ||
<PercentageItem | ||
icon={<TrendingUpIcon size={16} className="text-primary" />} | ||
title="Receita" | ||
value={typesPercentages[TransactionType.DEPOSIT]} | ||
/> | ||
<PercentageItem | ||
icon={<TrendingDownIcon size={16} className="text-danger" />} | ||
title="Gastos" | ||
value={typesPercentages[TransactionType.EXPENSE]} | ||
/> | ||
<PercentageItem | ||
icon={<PiggyBankIcon size={16} className="text-white" />} | ||
title="Investido" | ||
value={typesPercentages[TransactionType.INVESTMENT]} | ||
/> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default TransactionsPieChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.