-
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 expenses per category component
- Loading branch information
Showing
9 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
app/(authenticated)/dashboard/_components/expenses-per-category.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,35 @@ | ||
import { CardContent, CardHeader, CardTitle } from "@/app/_components/ui/card"; | ||
import { Progress } from "@/app/_components/ui/progress"; | ||
import { ScrollArea } from "@/app/_components/ui/scroll-area"; | ||
import { TRANSACTION_CATEGORY_MAP } from "@/app/_constants/transaction"; | ||
import type { TotalExpensePerCategory } from "@/app/_data/get-dashboard/types"; | ||
|
||
interface ExpensesPerCategoryProps { | ||
expensesPerCategory: TotalExpensePerCategory[]; | ||
} | ||
const ExpensesPerCategory = ({ | ||
expensesPerCategory, | ||
}: ExpensesPerCategoryProps) => { | ||
return ( | ||
<ScrollArea className="col-span-2 h-full rounded-md border pb-6"> | ||
<CardHeader> | ||
<CardTitle className="font-bold">Gastos por categoría</CardTitle> | ||
</CardHeader> | ||
<CardContent className="space-y-6"> | ||
{expensesPerCategory.map((category) => ( | ||
<div className="space-y-2" key={category.category}> | ||
<div className="flex w-full justify-between"> | ||
<p className="text-sm font-bold"> | ||
{TRANSACTION_CATEGORY_MAP[category.category]} | ||
</p> | ||
<p className="text-sm font-bold">{category.percentageOfTotal}%</p> | ||
</div> | ||
<Progress value={category.percentageOfTotal} /> | ||
</div> | ||
))} | ||
</CardContent> | ||
</ScrollArea> | ||
); | ||
}; | ||
|
||
export default ExpensesPerCategory; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import * as ProgressPrimitive from "@radix-ui/react-progress"; | ||
|
||
import { cn } from "@/app/_lib/utils"; | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> | ||
>(({ className, value, ...props }, ref) => ( | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative h-4 w-full overflow-hidden rounded-full bg-white bg-opacity-[3%]", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className="h-full w-full flex-1 bg-[#71717A] transition-all" | ||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
)); | ||
Progress.displayName = ProgressPrimitive.Root.displayName; | ||
|
||
export { Progress }; |
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,48 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"; | ||
|
||
import { cn } from "@/app/_lib/utils"; | ||
|
||
const ScrollArea = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> | ||
>(({ className, children, ...props }, ref) => ( | ||
<ScrollAreaPrimitive.Root | ||
ref={ref} | ||
className={cn("relative overflow-hidden", className)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]"> | ||
{children} | ||
</ScrollAreaPrimitive.Viewport> | ||
<ScrollBar /> | ||
<ScrollAreaPrimitive.Corner /> | ||
</ScrollAreaPrimitive.Root> | ||
)); | ||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName; | ||
|
||
const ScrollBar = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
>(({ className, orientation = "vertical", ...props }, ref) => ( | ||
<ScrollAreaPrimitive.ScrollAreaScrollbar | ||
ref={ref} | ||
orientation={orientation} | ||
className={cn( | ||
"flex touch-none select-none transition-colors", | ||
orientation === "vertical" && | ||
"h-full w-2.5 border-l border-l-transparent p-[1px]", | ||
orientation === "horizontal" && | ||
"h-2.5 flex-col border-t border-t-transparent p-[1px]", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" /> | ||
</ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
)); | ||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName; | ||
|
||
export { ScrollArea, ScrollBar }; |
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
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import type { TransactionType } from "@prisma/client"; | ||
import type { TransactionCategory, TransactionType } from "@prisma/client"; | ||
|
||
export type TransactionPercentagesPerType = { | ||
[key in TransactionType]: number; | ||
}; | ||
|
||
export interface TotalExpensePerCategory { | ||
category: TransactionCategory; | ||
totalAmount: number; | ||
percentageOfTotal: number; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.