Splits the `useTransactions` hook into smaller, more manageable files for improved code organization and maintainability. No functional changes are included.
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
|
|
import { Transaction } from '@/components/TransactionCard';
|
|
|
|
// 트랜잭션 데이터 불러오기
|
|
export const loadTransactionsFromStorage = (): Transaction[] => {
|
|
const localData = localStorage.getItem('transactions');
|
|
if (localData) {
|
|
return JSON.parse(localData) as Transaction[];
|
|
}
|
|
return [];
|
|
};
|
|
|
|
// 기본 샘플 데이터 생성
|
|
export const createSampleTransactions = (selectedMonth: string): Transaction[] => {
|
|
return [{
|
|
id: '1',
|
|
title: '식료품 구매',
|
|
amount: 25000,
|
|
date: `${selectedMonth} 25일, 12:30 PM`,
|
|
category: '식비',
|
|
type: 'expense'
|
|
}, {
|
|
id: '2',
|
|
title: '주유소',
|
|
amount: 50000,
|
|
date: `${selectedMonth} 24일, 3:45 PM`,
|
|
category: '교통비',
|
|
type: 'expense'
|
|
}, {
|
|
id: '4',
|
|
title: '생필품 구매',
|
|
amount: 35000,
|
|
date: `${selectedMonth} 18일, 6:00 AM`,
|
|
category: '생활비',
|
|
type: 'expense'
|
|
}, {
|
|
id: '5',
|
|
title: '월세',
|
|
amount: 650000,
|
|
date: `${selectedMonth} 15일, 10:00 AM`,
|
|
category: '생활비',
|
|
type: 'expense'
|
|
}, {
|
|
id: '6',
|
|
title: '식당',
|
|
amount: 15500,
|
|
date: `${selectedMonth} 12일, 2:15 PM`,
|
|
category: '식비',
|
|
type: 'expense'
|
|
}];
|
|
};
|
|
|
|
// 트랜잭션 데이터 저장하기
|
|
export const saveTransactionsToStorage = (transactions: Transaction[]): void => {
|
|
localStorage.setItem('transactions', JSON.stringify(transactions));
|
|
};
|
|
|
|
// 예산 불러오기
|
|
export const loadBudgetFromStorage = (): number => {
|
|
const budgetData = localStorage.getItem('budget');
|
|
if (budgetData) {
|
|
const parsedBudget = JSON.parse(budgetData);
|
|
return parsedBudget.total || 1000000;
|
|
}
|
|
return 1000000; // 기본 예산
|
|
};
|