Implement transaction history page

This commit implements the transaction history page.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 07:41:09 +00:00
parent 67f763eefa
commit fbd9924004
3 changed files with 447 additions and 107 deletions

View File

@@ -15,7 +15,9 @@ import {
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
import { Coffee, Home, Car } from 'lucide-react';
import { Coffee, Home, Car, Trash2 } from 'lucide-react';
import { toast } from '@/components/ui/use-toast';
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
// Form schema for validation
const formSchema = z.object({
@@ -35,13 +37,15 @@ interface TransactionEditDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onSave: (updatedTransaction: Transaction) => void;
onDelete?: (id: string) => void;
}
const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
transaction,
open,
onOpenChange,
onSave
onSave,
onDelete
}) => {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@@ -66,6 +70,18 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
onOpenChange(false);
};
const handleDelete = () => {
if (onDelete) {
onDelete(transaction.id);
onOpenChange(false);
toast({
title: "지출이 삭제되었습니다",
description: `${transaction.title} 항목이 삭제되었습니다.`,
});
}
};
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const formattedValue = formatWithCommas(e.target.value);
form.setValue('amount', formattedValue);
@@ -147,11 +163,49 @@ const TransactionEditDialog: React.FC<TransactionEditDialogProps> = ({
)}
/>
<DialogFooter className="sm:justify-between">
<DialogClose asChild>
<Button type="button" variant="outline"></Button>
</DialogClose>
<Button type="submit"></Button>
<DialogFooter className="flex justify-between gap-2 mt-6">
{onDelete && (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
type="button"
variant="outline"
className="border-red-200 text-red-500 hover:bg-red-50"
>
<Trash2 size={16} />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle> </AlertDialogTitle>
<AlertDialogDescription>
? .
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction
className="bg-red-500 hover:bg-red-600"
onClick={handleDelete}
>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
<div className="flex gap-2">
<DialogClose asChild>
<Button type="button" variant="outline"></Button>
</DialogClose>
<Button
type="submit"
className="bg-neuro-income text-white hover:bg-neuro-income/90"
>
</Button>
</div>
</DialogFooter>
</form>
</Form>