Reset budget and transaction data

Resets all budget data and transaction history to provide a clean slate.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-15 22:56:49 +00:00
parent 78475eb990
commit 829b7af80d
2 changed files with 25 additions and 12 deletions

View File

@@ -24,6 +24,8 @@ export const saveTransactionsToStorage = (transactions: Transaction[]): void =>
// 모든 트랜잭션 삭제
export const clearAllTransactions = (): void => {
localStorage.removeItem('transactions');
// 빈 배열을 저장하여 확실히 초기화
localStorage.setItem('transactions', JSON.stringify([]));
};
// 카테고리 예산 불러오기
@@ -90,8 +92,21 @@ export const clearAllBudgetData = (): void => {
// 모든 데이터 초기화 (첫 로그인 상태)
export const resetAllData = (): void => {
// 모든 관련 데이터 키 목록
const dataKeys = [
'transactions',
'categoryBudgets',
'budgetData',
'budget',
'hasVisitedBefore'
];
// 모든 관련 데이터 키 삭제
dataKeys.forEach(key => localStorage.removeItem(key));
// 기본 데이터로 초기화
clearAllTransactions();
clearAllCategoryBudgets();
clearAllBudgetData();
localStorage.removeItem('hasVisitedBefore');
};

View File

@@ -27,21 +27,19 @@ const Index = () => {
const { user } = useAuth();
const [showWelcome, setShowWelcome] = useState(false);
// 첫 방문 여부 확인 및 데이터 초기화
// 화면이 처음 로드될 때 데이터 초기화
useEffect(() => {
const hasVisitedBefore = localStorage.getItem('hasVisitedBefore');
const dontShowWelcome = localStorage.getItem('dontShowWelcome') === 'true';
// 데이터를 완전히 초기화
resetAllData();
if (!hasVisitedBefore) {
// 첫 로그인으로 가정하고 모든 데이터 초기화
resetAllData();
setShowWelcome(true);
// 방문 기록 저장
localStorage.setItem('hasVisitedBefore', 'true');
} else if (!dontShowWelcome) {
// '더 이상 보지 않기'를 선택하지 않았다면 계속 환영 팝업 표시
// 환영 다이얼로그 표시 여부 결정
const dontShowWelcome = localStorage.getItem('dontShowWelcome') === 'true';
if (!dontShowWelcome) {
setShowWelcome(true);
}
// 방문 기록 저장 (초기화 후에 저장)
localStorage.setItem('hasVisitedBefore', 'true');
}, []);
// 환영 팝업 닫기