refactor: API 중앙화 최종 (5/5)

- Schedule.jsx import 경로 오류 수정
- AdminSchedule.jsx API 모듈 적용 (schedulesApi, categoriesApi)
- 전체: PC public 6개, 모바일 Home 1개, Admin 2개 적용 완료
This commit is contained in:
caadiq 2026-01-09 22:09:42 +09:00
parent 0ff9f196f1
commit 0722ca10f3
2 changed files with 10 additions and 22 deletions

View file

@ -12,6 +12,8 @@ import Toast from '../../../components/Toast';
import Tooltip from '../../../components/Tooltip';
import useScheduleStore from '../../../stores/useScheduleStore';
import { getTodayKST, formatDate } from '../../../utils/date';
import * as schedulesApi from '../../../api/admin/schedules';
import * as categoriesApi from '../../../api/admin/categories';
// - React.memo
const ScheduleItem = memo(function ScheduleItem({
@ -370,8 +372,7 @@ function AdminSchedule() {
//
const fetchCategories = async () => {
try {
const res = await fetch('/api/admin/schedule-categories');
const data = await res.json();
const data = await categoriesApi.getCategories();
setCategories([
{ id: 'all', name: '전체', color: 'gray' },
...data
@ -385,8 +386,7 @@ function AdminSchedule() {
const fetchSchedules = async () => {
setLoading(true);
try {
const res = await fetch(`/api/admin/schedules?year=${year}&month=${month + 1}`);
const data = await res.json();
const data = await schedulesApi.getSchedules(year, month + 1);
setSchedules(data);
} catch (error) {
console.error('일정 로드 오류:', error);
@ -501,24 +501,12 @@ function AdminSchedule() {
setDeleting(true);
try {
const token = localStorage.getItem('adminToken');
const response = await fetch(`/api/admin/schedules/${scheduleToDelete.id}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${token}`,
},
});
if (response.ok) {
setToast({ type: 'success', message: '일정이 삭제되었습니다.' });
fetchSchedules(); //
} else {
const data = await response.json();
setToast({ type: 'error', message: data.error || '삭제 실패' });
}
await schedulesApi.deleteSchedule(scheduleToDelete.id);
setToast({ type: 'success', message: '일정이 삭제되었습니다.' });
fetchSchedules();
} catch (error) {
console.error('삭제 오류:', error);
setToast({ type: 'error', message: '삭제 중 오류가 발생했습니다.' });
setToast({ type: 'error', message: error.message || '삭제 중 오류가 발생했습니다.' });
} finally {
setDeleting(false);
setDeleteDialogOpen(false);

View file

@ -4,8 +4,8 @@ import { motion, AnimatePresence } from 'framer-motion';
import { Clock, ChevronLeft, ChevronRight, ChevronDown, Tag, Search, ArrowLeft, Link2 } from 'lucide-react';
import { useInfiniteQuery } from '@tanstack/react-query';
import { useInView } from 'react-intersection-observer';
import { getTodayKST } from '../../../../utils/date';
import { getSchedules, getCategories, searchSchedules as searchSchedulesApi } from '../../../../api/public/schedules';
import { getTodayKST } from '../../../utils/date';
import { getSchedules, getCategories, searchSchedules as searchSchedulesApi } from '../../../api/public/schedules';
function Schedule() {
const navigate = useNavigate();