fix: [ecard] 기간 검색 stale closure 문제 수정
- loadTransactions/loadSplits/loadJournalStatuses에 명시적 날짜 파라미터 추가 - 조회 버튼 클릭 시 현재 날짜 직접 전달 - 편의 버튼(이번달/지난달/D-N월) 클릭 시 자동 검색 트리거
This commit is contained in:
@@ -2134,15 +2134,17 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
}
|
||||
};
|
||||
|
||||
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, ''),
|
||||
cardNum: selectedCard,
|
||||
page: page,
|
||||
limit: 200
|
||||
@@ -2167,16 +2169,16 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
}
|
||||
|
||||
// 분리 데이터 로드
|
||||
loadSplits();
|
||||
loadJournalStatuses();
|
||||
loadSplits(from, to);
|
||||
loadJournalStatuses(from, to);
|
||||
};
|
||||
|
||||
// 분리 데이터 로드
|
||||
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();
|
||||
@@ -2191,11 +2193,11 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
};
|
||||
|
||||
// 복식부기 분개 상태 로드
|
||||
const loadJournalStatuses = async () => {
|
||||
const loadJournalStatuses = 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.journalStatuses}?${params}`);
|
||||
const data = await response.json();
|
||||
@@ -2733,6 +2735,7 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
const dates = getMonthDates(0);
|
||||
setDateFrom(dates.from);
|
||||
setDateTo(dates.to);
|
||||
loadTransactions(1, dates.from, dates.to);
|
||||
};
|
||||
|
||||
// 지난달 버튼
|
||||
@@ -2740,6 +2743,7 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
const dates = getMonthDates(-1);
|
||||
setDateFrom(dates.from);
|
||||
setDateTo(dates.to);
|
||||
loadTransactions(1, dates.from, dates.to);
|
||||
};
|
||||
|
||||
// N개월 전 버튼 (offset: -2, -3, -4 등)
|
||||
@@ -2747,6 +2751,7 @@ className="px-3 py-1 bg-green-500 text-white text-xs rounded-lg hover:bg-green-6
|
||||
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) + '원';
|
||||
@@ -2877,7 +2882,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={() => loadTransactions()}
|
||||
onClick={() => loadTransactions(1, dateFrom, dateTo)}
|
||||
className="px-4 py-1.5 text-sm bg-purple-600 text-white rounded-lg hover:bg-purple-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">
|
||||
|
||||
Reference in New Issue
Block a user