Fix budget display and button

- Fix the budget display issue where monthly budgets were showing four amounts instead of one.
- Resolve the functionality of the "Edit Budget" button.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 11:08:04 +00:00
parent e900fa77a1
commit ef239e6126
5 changed files with 64 additions and 39 deletions

View File

@@ -14,12 +14,20 @@ const BudgetInputButton: React.FC<BudgetInputButtonProps> = ({
budgetButtonText, budgetButtonText,
toggleBudgetInput toggleBudgetInput
}) => { }) => {
const handleButtonClick = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
console.log('예산 수정 버튼 클릭됨');
toggleBudgetInput();
};
if (isBudgetSet) { if (isBudgetSet) {
return ( return (
<div className="mt-6"> <div className="mt-6">
<button <button
onClick={toggleBudgetInput} onClick={handleButtonClick}
className="text-neuro-income hover:underline flex items-center text-base font-semibold group" className="text-neuro-income hover:underline flex items-center text-base font-semibold group"
type="button"
> >
<CirclePlus size={26} className="mr-2 text-neuro-income transition-transform group-hover:scale-110" /> <CirclePlus size={26} className="mr-2 text-neuro-income transition-transform group-hover:scale-110" />
<span className="text-base font-semibold">{budgetButtonText}</span> <span className="text-base font-semibold">{budgetButtonText}</span>
@@ -31,7 +39,12 @@ const BudgetInputButton: React.FC<BudgetInputButtonProps> = ({
return ( return (
<div className="py-4 text-center"> <div className="py-4 text-center">
<div className="text-gray-400 mb-4"> </div> <div className="text-gray-400 mb-4"> </div>
<Button onClick={toggleBudgetInput} variant="default" className="bg-neuro-income hover:bg-neuro-income/90 animate-pulse shadow-lg"> <Button
onClick={handleButtonClick}
variant="default"
className="bg-neuro-income hover:bg-neuro-income/90 animate-pulse shadow-lg"
type="button"
>
<CirclePlus className="mr-2" size={24} /> <CirclePlus className="mr-2" size={24} />
<span className="animate-pulse">{budgetButtonText}</span> <span className="animate-pulse">{budgetButtonText}</span>
</Button> </Button>

View File

@@ -23,9 +23,16 @@ const BudgetInputForm: React.FC<BudgetInputFormProps> = ({
}) => { }) => {
if (!showBudgetInput) return null; if (!showBudgetInput) return null;
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
e.stopPropagation();
handleSaveCategoryBudgets();
};
return ( return (
<div className="mt-4"> <div className="mt-4">
<div className="neuro-card p-4"> <div className="neuro-card p-4">
<form onSubmit={handleSubmit}>
<div> <div>
<h3 className="text-base font-medium mb-3"> </h3> <h3 className="text-base font-medium mb-3"> </h3>
<p className="text-sm text-gray-500 mb-4"> . , .</p> <p className="text-sm text-gray-500 mb-4"> . , .</p>
@@ -42,7 +49,7 @@ const BudgetInputForm: React.FC<BudgetInputFormProps> = ({
<div className="flex justify-end"> <div className="flex justify-end">
<Button <Button
onClick={handleSaveCategoryBudgets} type="submit"
size="sm" size="sm"
className="bg-neuro-income hover:bg-neuro-income/90 text-white mx-[6px]" className="bg-neuro-income hover:bg-neuro-income/90 text-white mx-[6px]"
> >
@@ -52,6 +59,7 @@ const BudgetInputForm: React.FC<BudgetInputFormProps> = ({
</div> </div>
</div> </div>
</div> </div>
</form>
</div> </div>
</div> </div>
); );

View File

@@ -15,6 +15,8 @@ export const useExtendedBudgetUpdate = (
amount: number, amount: number,
newCategoryBudgets?: Record<string, number> newCategoryBudgets?: Record<string, number>
) => { ) => {
console.log('확장 예산 업데이트 시작:', type, amount, newCategoryBudgets);
// 기본 예산 목표 업데이트 // 기본 예산 목표 업데이트
handleBudgetUpdate(type, amount); handleBudgetUpdate(type, amount);
@@ -22,7 +24,17 @@ export const useExtendedBudgetUpdate = (
if (newCategoryBudgets) { if (newCategoryBudgets) {
console.log('카테고리 예산 업데이트:', newCategoryBudgets); console.log('카테고리 예산 업데이트:', newCategoryBudgets);
setCategoryBudgets(newCategoryBudgets); setCategoryBudgets(newCategoryBudgets);
// 카테고리 예산 업데이트 이벤트 발생
setTimeout(() => {
window.dispatchEvent(new Event('categoryBudgetsUpdated'));
}, 100);
} }
// 모든 업데이트가 완료된 후 전역 예산 데이터 업데이트 이벤트 발생
setTimeout(() => {
window.dispatchEvent(new Event('budgetDataUpdated'));
}, 200);
}; };
return extendedBudgetUpdate; return extendedBudgetUpdate;

View File

@@ -22,19 +22,23 @@ export const calculateUpdatedBudgetData = (
if (type === 'monthly') { if (type === 'monthly') {
// 월간 예산이 직접 입력된 경우 // 월간 예산이 직접 입력된 경우
monthlyAmount = amount; monthlyAmount = amount;
// 월 30일 기준 (실제 사용 시 값 확인) // 월 30일 기준
dailyAmount = Math.round(monthlyAmount / 30); dailyAmount = Math.round(monthlyAmount / 30);
// 월 4.3주 기준 (실제 사용 시 값 확인) // 월 4.3주 기준 (30일 / 7일)
weeklyAmount = Math.round(monthlyAmount / 4.3); weeklyAmount = Math.round(monthlyAmount / 4.3);
} else if (type === 'weekly') { } else if (type === 'weekly') {
// 주간 예산이 직접 입력된 경우 // 주간 예산이 직접 입력된 경우
weeklyAmount = amount; weeklyAmount = amount;
// 월 4.3주 기준 (30일 / 7일)
monthlyAmount = Math.round(weeklyAmount * 4.3); monthlyAmount = Math.round(weeklyAmount * 4.3);
// 주 7일 기준
dailyAmount = Math.round(weeklyAmount / 7); dailyAmount = Math.round(weeklyAmount / 7);
} else { // 'daily' } else { // 'daily'
// 일일 예산이 직접 입력된 경우 // 일일 예산이 직접 입력된 경우
dailyAmount = amount; dailyAmount = amount;
// 주 7일 기준
weeklyAmount = Math.round(dailyAmount * 7); weeklyAmount = Math.round(dailyAmount * 7);
// 월 30일 기준
monthlyAmount = Math.round(dailyAmount * 30); monthlyAmount = Math.round(dailyAmount * 30);
} }

View File

@@ -51,11 +51,6 @@ export const useBudgetTabContent = ({
useEffect(() => { useEffect(() => {
const handleBudgetDataUpdated = () => { const handleBudgetDataUpdated = () => {
console.log(`BudgetTabContent: 전역 예산 데이터 이벤트 감지, 현재 targetAmount=${targetAmount}`); console.log(`BudgetTabContent: 전역 예산 데이터 이벤트 감지, 현재 targetAmount=${targetAmount}`);
// 입력 폼이 열려있고 예산이 설정된 경우 폼 닫기
if (showBudgetInput && targetAmount > 0) {
console.log('예산이 설정되어 입력 폼을 닫습니다.');
setShowBudgetInput(false);
}
}; };
window.addEventListener('budgetDataUpdated', handleBudgetDataUpdated); window.addEventListener('budgetDataUpdated', handleBudgetDataUpdated);
@@ -65,13 +60,6 @@ export const useBudgetTabContent = ({
// 예산 설정 여부 확인 - 데이터 targetAmount가 실제로 0보다 큰지 확인 // 예산 설정 여부 확인 - 데이터 targetAmount가 실제로 0보다 큰지 확인
const isBudgetSet = targetAmount > 0; const isBudgetSet = targetAmount > 0;
useEffect(() => {
if (isBudgetSet && showBudgetInput) {
console.log('예산이 설정되었으므로 입력 폼을 닫습니다.');
setShowBudgetInput(false);
}
}, [isBudgetSet, showBudgetInput]);
// 실제 백분율 계산 (초과해도 실제 퍼센트로 표시) // 실제 백분율 계산 (초과해도 실제 퍼센트로 표시)
const actualPercentage = targetAmount > 0 ? Math.round((spentAmount / targetAmount) * 100) : 0; const actualPercentage = targetAmount > 0 ? Math.round((spentAmount / targetAmount) * 100) : 0;
const percentage = Math.min(actualPercentage, 100); // 대시보드 표시용으로는 100% 제한 const percentage = Math.min(actualPercentage, 100); // 대시보드 표시용으로는 100% 제한