Rename "Add Transaction" to "Add Expense"
The prompt requests to rename "Add Transaction" to "Add Expense".
This commit is contained in:
@@ -9,6 +9,7 @@ import { Input } from './ui/input';
|
||||
import { Button } from './ui/button';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { ToggleGroup, ToggleGroupItem } from './ui/toggle-group';
|
||||
import { toast } from '@/components/ui/use-toast';
|
||||
|
||||
interface ExpenseFormValues {
|
||||
title: string;
|
||||
@@ -52,14 +53,37 @@ const AddTransactionButton = () => {
|
||||
const onSubmit = (data: ExpenseFormValues) => {
|
||||
// Remove commas before processing the amount
|
||||
const numericAmount = data.amount.replace(/,/g, '');
|
||||
const processedData = {
|
||||
...data,
|
||||
amount: numericAmount
|
||||
|
||||
// 현재 날짜와 시간을 가져옵니다
|
||||
const now = new Date();
|
||||
const formattedDate = `오늘, ${now.getHours()}:${now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes()} ${now.getHours() >= 12 ? 'PM' : 'AM'}`;
|
||||
|
||||
const newExpense = {
|
||||
id: Date.now().toString(),
|
||||
title: data.title,
|
||||
amount: parseInt(numericAmount),
|
||||
date: formattedDate,
|
||||
category: data.category,
|
||||
type: 'expense'
|
||||
};
|
||||
|
||||
console.log('Expense data:', processedData);
|
||||
// 로컬 스토리지에서 기존 지출 내역을 가져옵니다
|
||||
const existingTransactionsJSON = localStorage.getItem('transactions');
|
||||
let existingTransactions = existingTransactionsJSON ? JSON.parse(existingTransactionsJSON) : [];
|
||||
|
||||
// 새 지출을 추가하고 다시 저장합니다
|
||||
existingTransactions = [newExpense, ...existingTransactions];
|
||||
localStorage.setItem('transactions', JSON.stringify(existingTransactions));
|
||||
|
||||
// 폼을 초기화하고 다이얼로그를 닫습니다
|
||||
form.reset();
|
||||
setShowExpenseDialog(false);
|
||||
// 여기에서 실제 데이터 처리 로직을 구현할 수 있습니다
|
||||
|
||||
// 사용자에게 알림을 표시합니다
|
||||
toast({
|
||||
title: "지출이 추가되었습니다",
|
||||
description: `${data.title} 항목이 ${formatWithCommas(numericAmount)}원으로 등록되었습니다.`,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user