교육과정 관리 등록
This commit is contained in:
@@ -5,7 +5,7 @@ import AdminSidebar from "@/app/components/AdminSidebar";
|
||||
import ChevronDownSvg from "@/app/svgs/chevrondownsvg";
|
||||
import DropdownIcon from "@/app/svgs/dropdownicon";
|
||||
import BackArrowSvg from "@/app/svgs/backarrow";
|
||||
import { MOCK_COURSES, MOCK_CURRENT_USER } from "@/app/admin/courses/mockData";
|
||||
import { getCourses, type Course } from "@/app/admin/courses/mockData";
|
||||
import CloseXOSvg from "@/app/svgs/closexo";
|
||||
|
||||
type Lesson = {
|
||||
@@ -24,6 +24,8 @@ export default function AdminLessonsPage() {
|
||||
const [isRegistrationMode, setIsRegistrationMode] = useState(false);
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const [courses, setCourses] = useState<Course[]>([]);
|
||||
const [currentUser, setCurrentUser] = useState<string>("관리자");
|
||||
|
||||
// 등록 폼 상태
|
||||
const [selectedCourse, setSelectedCourse] = useState<string>("");
|
||||
@@ -35,6 +37,60 @@ export default function AdminLessonsPage() {
|
||||
const [vrContentFiles, setVrContentFiles] = useState<string[]>([]);
|
||||
const [questionFileCount, setQuestionFileCount] = useState(0);
|
||||
|
||||
// 교육과정 목록 가져오기
|
||||
useEffect(() => {
|
||||
async function fetchCourses() {
|
||||
try {
|
||||
const data = await getCourses();
|
||||
setCourses(data);
|
||||
} catch (error) {
|
||||
console.error('교육과정 목록 로드 오류:', error);
|
||||
setCourses([]);
|
||||
}
|
||||
}
|
||||
fetchCourses();
|
||||
}, []);
|
||||
|
||||
// 현재 사용자 정보 가져오기
|
||||
useEffect(() => {
|
||||
async function fetchCurrentUser() {
|
||||
try {
|
||||
const token = typeof window !== 'undefined'
|
||||
? (localStorage.getItem('token') || document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('token='))
|
||||
?.split('=')[1])
|
||||
: null;
|
||||
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? `${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/me`
|
||||
: 'https://hrdi.coconutmeet.net/auth/me';
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.name) {
|
||||
setCurrentUser(data.name);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('사용자 정보 조회 오류:', error);
|
||||
}
|
||||
}
|
||||
fetchCurrentUser();
|
||||
}, []);
|
||||
|
||||
const totalCount = useMemo(() => lessons.length, [lessons]);
|
||||
|
||||
const ITEMS_PER_PAGE = 10;
|
||||
@@ -52,13 +108,13 @@ export default function AdminLessonsPage() {
|
||||
return sortedLessons.slice(startIndex, endIndex);
|
||||
}, [sortedLessons, currentPage]);
|
||||
|
||||
// 교육과정 옵션 - mockData에서 가져오기
|
||||
// 교육과정 옵션
|
||||
const courseOptions = useMemo(() =>
|
||||
MOCK_COURSES.map(course => ({
|
||||
courses.map(course => ({
|
||||
id: course.id,
|
||||
name: course.courseName
|
||||
}))
|
||||
, []);
|
||||
, [courses]);
|
||||
|
||||
// 외부 클릭 시 드롭다운 닫기
|
||||
useEffect(() => {
|
||||
@@ -129,7 +185,7 @@ export default function AdminLessonsPage() {
|
||||
lessonName,
|
||||
attachments,
|
||||
questionCount: questionFileCount,
|
||||
createdBy: MOCK_CURRENT_USER,
|
||||
createdBy: currentUser,
|
||||
createdAt: new Date().toISOString().split('T')[0],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user