fix: 관리 페이지 날짜 상태 조건부 초기화
문제: 일정 관리 페이지에서 날짜 선택 후 홈으로 갔다왔을 때 오늘 날짜로 초기화가 안됨 해결: - useScheduleStore에 preserveState 플래그 추가 - AdminSchedule에서 preserveState가 false면 오늘 날짜로 초기화 - AdminScheduleForm, AdminScheduleBots에서 일정 관리로 돌아갈 때 preserveState를 true로 설정하여 상태 유지
This commit is contained in:
parent
d6eb8d410c
commit
2dd5219265
4 changed files with 31 additions and 8 deletions
|
|
@ -136,6 +136,8 @@ function AdminSchedule() {
|
|||
selectedDate, setSelectedDate,
|
||||
currentDate, setCurrentDate,
|
||||
scrollPosition, setScrollPosition,
|
||||
preserveState, setPreserveState,
|
||||
reset,
|
||||
} = useScheduleStore();
|
||||
|
||||
// 로컬 상태 (페이지 이동 시 유지할 필요 없는 것들)
|
||||
|
|
@ -191,10 +193,18 @@ function AdminSchedule() {
|
|||
}
|
||||
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage, isSearchMode, searchTerm]);
|
||||
|
||||
// selectedDate가 없으면 오늘 날짜로 초기화
|
||||
// 페이지 진입 시 상태 초기화 (preserveState가 false인 경우만)
|
||||
useEffect(() => {
|
||||
if (!selectedDate) {
|
||||
if (preserveState) {
|
||||
// 일정 추가/수정, 봇 관리에서 돌아온 경우 - 플래그만 리셋
|
||||
setPreserveState(false);
|
||||
} else {
|
||||
// 다른 페이지에서 돌아온 경우 - 오늘 날짜로 초기화
|
||||
setSelectedDate(getTodayKST());
|
||||
setCurrentDate(new Date());
|
||||
setSearchInput('');
|
||||
setSearchTerm('');
|
||||
setIsSearchMode(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ import Toast from '../../../components/Toast';
|
|||
import Tooltip from '../../../components/Tooltip';
|
||||
import AdminHeader from '../../../components/admin/AdminHeader';
|
||||
import useToast from '../../../hooks/useToast';
|
||||
import useScheduleStore from '../../../stores/useScheduleStore';
|
||||
import * as botsApi from '../../../api/admin/bots';
|
||||
|
||||
function AdminScheduleBots() {
|
||||
const navigate = useNavigate();
|
||||
const { setPreserveState } = useScheduleStore();
|
||||
const [user, setUser] = useState(null);
|
||||
const { toast, setToast } = useToast();
|
||||
const [bots, setBots] = useState([]);
|
||||
|
|
@ -198,9 +200,12 @@ function AdminScheduleBots() {
|
|||
<Home size={16} />
|
||||
</Link>
|
||||
<ChevronRight size={14} />
|
||||
<Link to="/admin/schedule" className="hover:text-primary transition-colors">
|
||||
<button
|
||||
onClick={() => { setPreserveState(true); navigate('/admin/schedule'); }}
|
||||
className="hover:text-primary transition-colors"
|
||||
>
|
||||
일정 관리
|
||||
</Link>
|
||||
</button>
|
||||
<ChevronRight size={14} />
|
||||
<span className="text-gray-700">봇 관리</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import CustomTimePicker from "../../../components/admin/CustomTimePicker";
|
|||
import AdminHeader from "../../../components/admin/AdminHeader";
|
||||
import ConfirmDialog from "../../../components/admin/ConfirmDialog";
|
||||
import useToast from "../../../hooks/useToast";
|
||||
import useScheduleStore from "../../../stores/useScheduleStore";
|
||||
import * as authApi from "../../../api/admin/auth";
|
||||
import * as categoriesApi from "../../../api/admin/categories";
|
||||
import * as schedulesApi from "../../../api/admin/schedules";
|
||||
|
|
@ -36,6 +37,7 @@ import { getMembers } from "../../../api/public/members";
|
|||
|
||||
function AdminScheduleForm() {
|
||||
const navigate = useNavigate();
|
||||
const { setPreserveState } = useScheduleStore();
|
||||
const { id } = useParams();
|
||||
const isEditMode = !!id;
|
||||
|
||||
|
|
@ -495,6 +497,7 @@ function AdminScheduleForm() {
|
|||
: "일정이 추가되었습니다.",
|
||||
})
|
||||
);
|
||||
setPreserveState(true);
|
||||
navigate("/admin/schedule");
|
||||
} catch (error) {
|
||||
console.error("일정 저장 오류:", error);
|
||||
|
|
@ -678,12 +681,12 @@ function AdminScheduleForm() {
|
|||
<Home size={16} />
|
||||
</Link>
|
||||
<ChevronRight size={14} />
|
||||
<Link
|
||||
to="/admin/schedule"
|
||||
<button
|
||||
onClick={() => { setPreserveState(true); navigate('/admin/schedule'); }}
|
||||
className="hover:text-primary transition-colors"
|
||||
>
|
||||
일정 관리
|
||||
</Link>
|
||||
</button>
|
||||
<ChevronRight size={14} />
|
||||
<span className="text-gray-700">
|
||||
{isEditMode ? "일정 수정" : "일정 추가"}
|
||||
|
|
@ -1155,7 +1158,7 @@ function AdminScheduleForm() {
|
|||
<div className="flex items-center justify-end gap-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate("/admin/schedule")}
|
||||
onClick={() => { setPreserveState(true); navigate("/admin/schedule"); }}
|
||||
className="px-6 py-3 text-gray-700 hover:bg-gray-100 rounded-xl transition-colors font-medium"
|
||||
>
|
||||
취소
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ const useScheduleStore = create((set) => ({
|
|||
// 스크롤 위치
|
||||
scrollPosition: 0,
|
||||
|
||||
// 상태 유지 플래그 (일정 추가/수정, 봇 관리 페이지에서 돌아올 때만 true)
|
||||
preserveState: false,
|
||||
|
||||
// 상태 업데이트 함수
|
||||
setSearchInput: (value) => set({ searchInput: value }),
|
||||
setSearchTerm: (value) => set({ searchTerm: value }),
|
||||
|
|
@ -24,6 +27,7 @@ const useScheduleStore = create((set) => ({
|
|||
setSelectedDate: (value) => set({ selectedDate: value }),
|
||||
setCurrentDate: (value) => set({ currentDate: value }),
|
||||
setScrollPosition: (value) => set({ scrollPosition: value }),
|
||||
setPreserveState: (value) => set({ preserveState: value }),
|
||||
|
||||
// 상태 초기화
|
||||
reset: () =>
|
||||
|
|
@ -35,6 +39,7 @@ const useScheduleStore = create((set) => ({
|
|||
selectedDate: null,
|
||||
currentDate: new Date(),
|
||||
scrollPosition: 0,
|
||||
preserveState: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue