Rename categories

Rename "식비" to "음식" and "생활비" to "쇼핑".
This commit is contained in:
gpt-engineer-app[bot]
2025-03-21 10:02:05 +00:00
parent 00d8d7f923
commit d6e6c00ea9
6 changed files with 37 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
import React from 'react'; import React from 'react';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { EXPENSE_CATEGORIES, categoryIcons } from '@/constants/categoryIcons'; import { EXPENSE_CATEGORIES, categoryIcons } from '@/constants/categoryIcons';

View File

@@ -10,7 +10,7 @@ import { categoryIcons, EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
export const transactionFormSchema = z.object({ export const transactionFormSchema = z.object({
title: z.string().min(1, '제목을 입력해주세요'), title: z.string().min(1, '제목을 입력해주세요'),
amount: z.string().min(1, '금액을 입력해주세요'), amount: z.string().min(1, '금액을 입력해주세요'),
category: z.enum(['식', '생활비', '교통비']), category: z.enum(['식', '쇼핑', '교통비']),
}); });
export type TransactionFormValues = z.infer<typeof transactionFormSchema>; export type TransactionFormValues = z.infer<typeof transactionFormSchema>;

View File

@@ -4,19 +4,19 @@ import { Coffee, Home, Car, Banknote } from 'lucide-react';
// 카테고리와 아이콘 매핑 정의 // 카테고리와 아이콘 매핑 정의
export const categoryIcons: Record<string, React.ReactNode> = { export const categoryIcons: Record<string, React.ReactNode> = {
: <Coffee size={18} />, : <Coffee size={18} />,
: <Home size={18} />, : <Home size={18} />,
: <Car size={18} />, : <Car size={18} />,
: <Banknote size={18} />, : <Banknote size={18} />,
}; };
// 지출 카테고리 목록 - 3개로 제한 // 지출 카테고리 목록 - 3개로 제한
export const EXPENSE_CATEGORIES = ['식', '생활비', '교통비']; export const EXPENSE_CATEGORIES = ['식', '쇼핑', '교통비'];
// 기본 카테고리 예산 설정 // 기본 카테고리 예산 설정
export const DEFAULT_CATEGORY_BUDGETS = { export const DEFAULT_CATEGORY_BUDGETS = {
: 400000, : 400000,
생활비: 600000, 쇼핑: 600000,
교통비: 200000 교통비: 200000
}; };

View File

@@ -4,8 +4,8 @@ import { EXPENSE_CATEGORIES } from '@/constants/categoryIcons';
// 기본 데이터 상수 (기본값을 0으로 설정) // 기본 데이터 상수 (기본값을 0으로 설정)
export const DEFAULT_CATEGORY_BUDGETS: Record<string, number> = { export const DEFAULT_CATEGORY_BUDGETS: Record<string, number> = {
: 0, : 0,
생활비: 0, 쇼핑: 0,
교통비: 0 교통비: 0
}; };
@@ -41,8 +41,8 @@ export const calculateCategorySpending = (
// 지원되는 카테고리이지만 초기화되지 않은 경우 // 지원되는 카테고리이지만 초기화되지 않은 경우
categorySpending[t.category] = t.amount; categorySpending[t.category] = t.amount;
} else { } else {
// 지원되지 않는 카테고리는 '생활비'로 집계 // 지원되지 않는 카테고리는 '쇼핑'으로 집계
categorySpending['생활비'] = (categorySpending['생활비'] || 0) + t.amount; categorySpending['쇼핑'] = (categorySpending['쇼핑'] || 0) + t.amount;
} }
}); });

View File

@@ -17,7 +17,14 @@ export const loadCategoryBudgetsFromStorage = (): Record<string, number> => {
// 3개 카테고리만 유지 // 3개 카테고리만 유지
const filteredBudgets: Record<string, number> = {}; const filteredBudgets: Record<string, number> = {};
EXPENSE_CATEGORIES.forEach(category => { EXPENSE_CATEGORIES.forEach(category => {
filteredBudgets[category] = parsed[category] || 0; // 이전 카테고리명이 있을 경우 새 카테고리명으로 값 이전
if (category === '음식' && parsed['식비'] !== undefined) {
filteredBudgets[category] = parsed['식비'];
} else if (category === '쇼핑' && parsed['생활비'] !== undefined) {
filteredBudgets[category] = parsed['생활비'];
} else {
filteredBudgets[category] = parsed[category] || 0;
}
}); });
return filteredBudgets; return filteredBudgets;
@@ -32,7 +39,14 @@ export const loadCategoryBudgetsFromStorage = (): Record<string, number> => {
// 3개 카테고리만 유지 // 3개 카테고리만 유지
const filteredBudgets: Record<string, number> = {}; const filteredBudgets: Record<string, number> = {};
EXPENSE_CATEGORIES.forEach(category => { EXPENSE_CATEGORIES.forEach(category => {
filteredBudgets[category] = parsedBackup[category] || 0; // 이전 카테고리명이 있을 경우 새 카테고리명으로 값 이전
if (category === '음식' && parsedBackup['식비'] !== undefined) {
filteredBudgets[category] = parsedBackup['식비'];
} else if (category === '쇼핑' && parsedBackup['생활비'] !== undefined) {
filteredBudgets[category] = parsedBackup['생활비'];
} else {
filteredBudgets[category] = parsedBackup[category] || 0;
}
}); });
// 메인 스토리지도 복구 // 메인 스토리지도 복구

View File

@@ -14,14 +14,17 @@ export const loadTransactionsFromStorage = (): Transaction[] => {
try { try {
const localData = JSON.parse(localDataStr); const localData = JSON.parse(localDataStr);
// 지원되는 카테고리로 필터링 // 지원되는 카테고리로 필터링 및 카테고리명 변환
const filteredData = localData.map((transaction: Transaction) => { const filteredData = localData.map((transaction: Transaction) => {
// 트랜잭션의 카테고리가 현재 지원되는 카테고리가 아니면 '생활비'로 변경 if (transaction.type === 'expense') {
if (transaction.type === 'expense' && !EXPENSE_CATEGORIES.includes(transaction.category)) { // 기존 카테고리명 변환
return { if (transaction.category === '식비') {
...transaction, return { ...transaction, category: '음식' };
category: '생활비' // 기본값으로 '생활비' 사용 } else if (transaction.category === '생활비') {
}; return { ...transaction, category: '쇼핑' };
} else if (!EXPENSE_CATEGORIES.includes(transaction.category)) {
return { ...transaction, category: '쇼핑' }; // 지원되지 않는 카테고리는 '쇼핑'으로
}
} }
return transaction; return transaction;
}); });