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:
@@ -21,6 +21,11 @@ export const saveTransactionsToStorage = (transactions: Transaction[]): void =>
|
|||||||
localStorage.setItem('transactions', JSON.stringify(transactions));
|
localStorage.setItem('transactions', JSON.stringify(transactions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 모든 트랜잭션 삭제
|
||||||
|
export const clearAllTransactions = (): void => {
|
||||||
|
localStorage.removeItem('transactions');
|
||||||
|
};
|
||||||
|
|
||||||
// 카테고리 예산 불러오기
|
// 카테고리 예산 불러오기
|
||||||
export const loadCategoryBudgetsFromStorage = (): Record<string, number> => {
|
export const loadCategoryBudgetsFromStorage = (): Record<string, number> => {
|
||||||
const storedCategoryBudgets = localStorage.getItem('categoryBudgets');
|
const storedCategoryBudgets = localStorage.getItem('categoryBudgets');
|
||||||
@@ -43,6 +48,13 @@ export const saveCategoryBudgetsToStorage = (categoryBudgets: Record<string, num
|
|||||||
localStorage.setItem('categoryBudgets', JSON.stringify(categoryBudgets));
|
localStorage.setItem('categoryBudgets', JSON.stringify(categoryBudgets));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 모든 카테고리 예산 삭제
|
||||||
|
export const clearAllCategoryBudgets = (): void => {
|
||||||
|
localStorage.removeItem('categoryBudgets');
|
||||||
|
// 기본값으로 재설정
|
||||||
|
saveCategoryBudgetsToStorage(DEFAULT_CATEGORY_BUDGETS);
|
||||||
|
};
|
||||||
|
|
||||||
// 예산 데이터 불러오기
|
// 예산 데이터 불러오기
|
||||||
export const loadBudgetDataFromStorage = (): BudgetData => {
|
export const loadBudgetDataFromStorage = (): BudgetData => {
|
||||||
const storedBudgetData = localStorage.getItem('budgetData');
|
const storedBudgetData = localStorage.getItem('budgetData');
|
||||||
@@ -67,3 +79,19 @@ export const loadBudgetDataFromStorage = (): BudgetData => {
|
|||||||
export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
export const saveBudgetDataToStorage = (budgetData: BudgetData): void => {
|
||||||
localStorage.setItem('budgetData', JSON.stringify(budgetData));
|
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');
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
loadCategoryBudgetsFromStorage,
|
loadCategoryBudgetsFromStorage,
|
||||||
saveCategoryBudgetsToStorage,
|
saveCategoryBudgetsToStorage,
|
||||||
loadBudgetDataFromStorage,
|
loadBudgetDataFromStorage,
|
||||||
saveBudgetDataToStorage
|
saveBudgetDataToStorage
|
||||||
} from './storageUtils';
|
} from './storageUtils';
|
||||||
import {
|
import {
|
||||||
calculateCategorySpending,
|
calculateCategorySpending,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import WelcomeDialog from '@/components/onboarding/WelcomeDialog';
|
|||||||
import { formatCurrency, calculatePercentage } from '@/utils/formatters';
|
import { formatCurrency, calculatePercentage } from '@/utils/formatters';
|
||||||
import { useBudget } from '@/contexts/BudgetContext';
|
import { useBudget } from '@/contexts/BudgetContext';
|
||||||
import { useAuth } from '@/contexts/auth';
|
import { useAuth } from '@/contexts/auth';
|
||||||
|
import { resetAllData } from '@/contexts/budget/storageUtils';
|
||||||
|
|
||||||
// 메인 컴포넌트
|
// 메인 컴포넌트
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
@@ -26,11 +27,13 @@ const Index = () => {
|
|||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const [showWelcome, setShowWelcome] = useState(false);
|
const [showWelcome, setShowWelcome] = useState(false);
|
||||||
|
|
||||||
// 첫 방문 여부 확인
|
// 첫 방문 여부 확인 및 데이터 초기화
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const hasVisitedBefore = localStorage.getItem('hasVisitedBefore');
|
const hasVisitedBefore = localStorage.getItem('hasVisitedBefore');
|
||||||
|
|
||||||
if (!hasVisitedBefore) {
|
if (!hasVisitedBefore) {
|
||||||
|
// 첫 로그인으로 가정하고 모든 데이터 초기화
|
||||||
|
resetAllData();
|
||||||
setShowWelcome(true);
|
setShowWelcome(true);
|
||||||
// 방문 기록 저장
|
// 방문 기록 저장
|
||||||
localStorage.setItem('hasVisitedBefore', 'true');
|
localStorage.setItem('hasVisitedBefore', 'true');
|
||||||
|
|||||||
Reference in New Issue
Block a user