-
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 last transaction component
- Loading branch information
Showing
12 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/(authenticated)/dashboard/_components/last-transactions.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,31 @@ | ||
import { Button } from "@/app/_components/ui/button"; | ||
import { CardContent, CardHeader, CardTitle } from "@/app/_components/ui/card"; | ||
import { ScrollArea } from "@/app/_components/ui/scroll-area"; | ||
import Link from "next/link"; | ||
import { Transactions } from "@prisma/client"; | ||
import TransactionCard from "./transaction-card"; | ||
interface LastTransactionsProps { | ||
lastTransactions: Transactions[]; | ||
} | ||
|
||
const LastTransactions = ({ lastTransactions }: LastTransactionsProps) => { | ||
return ( | ||
<ScrollArea className="max-h-[calc(100vh)] rounded-md border"> | ||
<CardHeader className="flex-row items-center justify-between"> | ||
<CardTitle className="font-bold">Últimas transações</CardTitle> | ||
<Link href="/transactions"> | ||
<Button variant="outline" className="rounded-full font-bold"> | ||
Ver mais | ||
</Button> | ||
</Link> | ||
</CardHeader> | ||
<CardContent className="w-full space-y-6"> | ||
{lastTransactions.map((transaction) => ( | ||
<TransactionCard key={transaction.id} transaction={transaction} /> | ||
))} | ||
</CardContent> | ||
</ScrollArea> | ||
); | ||
}; | ||
|
||
export default LastTransactions; |
69 changes: 69 additions & 0 deletions
69
app/(authenticated)/dashboard/_components/transaction-card.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,69 @@ | ||
import { TRANSACTION_PAYMENT_METHOD_ICON_MAP } from "@/app/_constants/transaction"; | ||
import { cn } from "@/app/_lib/utils"; | ||
import formatCurrency from "@/app/_utils/currency"; | ||
import type { Transactions } from "@prisma/client"; | ||
import Image from "next/image"; | ||
|
||
interface TransactionCardProps { | ||
transaction: Transactions; | ||
} | ||
|
||
const TransactionCard = ({ transaction }: TransactionCardProps) => { | ||
const getAmountColor = ({ transaction }: { transaction: Transactions }) => { | ||
if (transaction.type === "EXPENSE") { | ||
return "text-danger"; | ||
} | ||
if (transaction.type === "DEPOSIT") { | ||
return "text-primary"; | ||
} | ||
return "text-white"; | ||
}; | ||
|
||
const getAmountPrefix = ({ transaction }: { transaction: Transactions }) => { | ||
if (transaction.type === "EXPENSE") { | ||
return "-"; | ||
} | ||
return "+"; | ||
}; | ||
|
||
return ( | ||
<div className="flex w-full items-center justify-between gap-4"> | ||
{/* Lado esquerdo - Ícone e informações */} | ||
<div className="flex items-center gap-3"> | ||
<div className="rounded-md bg-white bg-opacity-[3%] p-2"> | ||
<Image | ||
src={TRANSACTION_PAYMENT_METHOD_ICON_MAP[transaction.paymentMethod]} | ||
alt={transaction.paymentMethod} | ||
width={24} | ||
height={24} | ||
/> | ||
</div> | ||
<div className="flex flex-col"> | ||
<p className="max-w-[100px] truncate text-sm font-bold"> | ||
{transaction.name} | ||
</p> | ||
<p className="text-sm text-muted-foreground"> | ||
{new Date(transaction.date).toLocaleDateString("pt-BR", { | ||
day: "2-digit", | ||
month: "short", | ||
year: "numeric", | ||
})} | ||
</p> | ||
</div> | ||
</div> | ||
|
||
{/* Lado direito - Valor */} | ||
<p | ||
className={cn( | ||
"ml-auto text-sm font-bold", | ||
getAmountColor({ transaction }), | ||
)} | ||
> | ||
{getAmountPrefix({ transaction })} | ||
{formatCurrency(Number(transaction.amount))} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TransactionCard; |
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
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,8 @@ | ||
const formatCurrency = (value: number) => { | ||
return new Intl.NumberFormat("pt-BR", { | ||
style: "currency", | ||
currency: "BRL", | ||
}).format(value); | ||
}; | ||
|
||
export default formatCurrency; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.