Reset budget and transactions

Resets budget data and transaction history as if the user is logging in for the first time.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 22:50:28 +00:00
parent dbac52d5dd
commit 6553a3afc9
3 changed files with 33 additions and 2 deletions

View File

@@ -21,6 +21,11 @@ export const saveTransactionsToStorage = (transactions: Transaction[]): void =>
localStorage.setItem('transactions', JSON.stringify(transactions));
};
// 모든 트랜잭션 삭제
export const clearAllTransactions = (): void => {
localStorage.removeItem('transactions');
};
// 카테고리 예산 불러오기
export const loadCategoryBudgetsFromStorage = (): Record<string, number> => {
const storedCategoryBudgets = localStorage.getItem('categoryBudgets');
@@ -43,6 +48,13 @@ export const saveCategoryBudgetsToStorage = (categoryBudgets: Record<string, num
localStorage.setItem('categoryBudgets', JSON.stringify(categoryBudgets));
};
// 모든 카테고리 예산 삭제
export const clearAllCategoryBudgets = (): void => {
localStorage.removeItem('categoryBudgets');
// 기본값으로 재설정
saveCategoryBudgetsToStorage(DEFAULT_CATEGORY_BUDGETS);
};
// 예산 데이터 불러오기
export const loadBudgetDataFromStorage = (): BudgetData => {
const storedBudgetData = localStorage.getItem('budgetData');
@@ -67,3 +79,19 @@ export const loadBudgetDataFromStorage = (): BudgetData => {
export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
localStorage.setItem('budgetData', JSON.stringify(budgetData));
};
// 모든 예산 데이터 삭제
export const clearAllBudgetData = (): void => {
localStorage.removeItem('budgetData');
// 기본값으로 재설정
const initialData = getInitialBudgetData();
saveBudgetDataToStorage(initialData);
};
// 모든 데이터 초기화 (첫 로그인 상태)
export const resetAllData = (): void => {
clearAllTransactions();
clearAllCategoryBudgets();
clearAllBudgetData();
localStorage.removeItem('hasVisitedBefore');
};

View File

@@ -8,7 +8,7 @@ import {
loadCategoryBudgetsFromStorage,
saveCategoryBudgetsToStorage,
loadBudgetDataFromStorage,
saveBudgetDataToStorage
saveBudgetDataToStorage
} from './storageUtils';
import {
calculateCategorySpending,

View File

@@ -10,6 +10,7 @@ import WelcomeDialog from '@/components/onboarding/WelcomeDialog';
import { formatCurrency, calculatePercentage } from '@/utils/formatters';
import { useBudget } from '@/contexts/BudgetContext';
import { useAuth } from '@/contexts/auth';
import { resetAllData } from '@/contexts/budget/storageUtils';
// 메인 컴포넌트
const Index = () => {
@@ -26,11 +27,13 @@ const Index = () => {
const { user } = useAuth();
const [showWelcome, setShowWelcome] = useState(false);
// 첫 방문 여부 확인
// 첫 방문 여부 확인 및 데이터 초기화
useEffect(() => {
const hasVisitedBefore = localStorage.getItem('hasVisitedBefore');
if (!hasVisitedBefore) {
// 첫 로그인으로 가정하고 모든 데이터 초기화
resetAllData();
setShowWelcome(true);
// 방문 기록 저장
localStorage.setItem('hasVisitedBefore', 'true');