fix: [eaccount] 기간 검색 시 stale closure 문제 수정
- loadTransactions/loadSplits에 명시적 날짜 파라미터 추가 - 조회 버튼 클릭 시 TransactionTable prop의 최신 날짜 직접 전달 - 편의 버튼(이번달/지난달/D-N월) 클릭 시 자동 검색 트리거
This commit is contained in:
@@ -1636,7 +1636,7 @@ className="px-3 py-1.5 text-sm bg-stone-100 text-stone-600 rounded-lg hover:bg-s
|
||||
D-5월
|
||||
</button>
|
||||
<button
|
||||
onClick={onSearch}
|
||||
onClick={() => onSearch(dateFrom, dateTo)}
|
||||
className="px-4 py-1.5 text-sm bg-emerald-600 text-white rounded-lg hover:bg-emerald-700 transition-colors font-medium flex items-center gap-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
@@ -1910,15 +1910,17 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
}
|
||||
};
|
||||
|
||||
const loadTransactions = async (page = 1) => {
|
||||
const loadTransactions = async (page = 1, fromOverride = null, toOverride = null) => {
|
||||
const from = fromOverride || dateFrom;
|
||||
const to = toOverride || dateTo;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setHasChanges(false);
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
startDate: dateFrom.replace(/-/g, ''),
|
||||
endDate: dateTo.replace(/-/g, ''),
|
||||
startDate: from.replace(/-/g, ''),
|
||||
endDate: to.replace(/-/g, ''),
|
||||
accountNum: selectedAccount,
|
||||
page: page,
|
||||
limit: 50
|
||||
@@ -1943,7 +1945,7 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
setPagination(data.data?.pagination || {});
|
||||
setSummary(data.data?.summary || {});
|
||||
// 분개 데이터도 함께 로드
|
||||
loadSplits();
|
||||
loadSplits(from, to);
|
||||
} else {
|
||||
setError(data.error || '조회 실패');
|
||||
setLogs([]);
|
||||
@@ -1957,11 +1959,11 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
};
|
||||
|
||||
// 분개 데이터 로드
|
||||
const loadSplits = async () => {
|
||||
const loadSplits = async (fromOverride = null, toOverride = null) => {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
startDate: dateFrom.replace(/-/g, ''),
|
||||
endDate: dateTo.replace(/-/g, ''),
|
||||
startDate: (fromOverride || dateFrom).replace(/-/g, ''),
|
||||
endDate: (toOverride || dateTo).replace(/-/g, ''),
|
||||
});
|
||||
const response = await fetch(`${API.splits}?${params}`);
|
||||
const data = await response.json();
|
||||
@@ -2243,6 +2245,7 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
const dates = getMonthDates(0);
|
||||
setDateFrom(dates.from);
|
||||
setDateTo(dates.to);
|
||||
loadTransactions(1, dates.from, dates.to);
|
||||
};
|
||||
|
||||
// 지난달 버튼
|
||||
@@ -2250,6 +2253,7 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
const dates = getMonthDates(-1);
|
||||
setDateFrom(dates.from);
|
||||
setDateTo(dates.to);
|
||||
loadTransactions(1, dates.from, dates.to);
|
||||
};
|
||||
|
||||
// N개월 전 버튼
|
||||
@@ -2257,6 +2261,7 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
const dates = getMonthDates(offset);
|
||||
setDateFrom(dates.from);
|
||||
setDateTo(dates.to);
|
||||
loadTransactions(1, dates.from, dates.to);
|
||||
};
|
||||
|
||||
const formatCurrency = (val) => new Intl.NumberFormat('ko-KR').format(val || 0) + '원';
|
||||
@@ -2351,7 +2356,7 @@ className="p-1 text-red-500 hover:bg-red-50 rounded transition-colors"
|
||||
onThisMonth={handleThisMonth}
|
||||
onLastMonth={handleLastMonth}
|
||||
onMonthOffset={handleMonthOffset}
|
||||
onSearch={() => loadTransactions()}
|
||||
onSearch={(from, to) => loadTransactions(1, from, to)}
|
||||
totalCount={summary.count || logs.length}
|
||||
onCastChange={handleCastChange}
|
||||
onSave={handleSave}
|
||||
|
||||
Reference in New Issue
Block a user