idonknow
This commit is contained in:
@@ -42,8 +42,8 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
|
||||
setIsLoadingInstructors(true);
|
||||
try {
|
||||
// 외부 API 호출
|
||||
const response = await apiService.getUsersCompact();
|
||||
// 외부 API 호출 - type이 'ADMIN'인 사용자만 조회
|
||||
const response = await apiService.getUsersCompact({ type: 'ADMIN', limit: 10 });
|
||||
const data = response.data;
|
||||
|
||||
// API 응답이 배열이 아닌 경우 처리 (예: { items: [...] } 형태)
|
||||
@@ -57,50 +57,50 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
// API 응답 데이터를 UserRow 형식으로 변환
|
||||
const transformedUsers: UserRow[] = usersArray.length > 0
|
||||
? usersArray.map((user: any) => {
|
||||
// 가입일을 YYYY-MM-DD 형식으로 변환
|
||||
const formatDate = (dateString: string | null | undefined): string => {
|
||||
if (!dateString) return new Date().toISOString().split('T')[0];
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toISOString().split('T')[0];
|
||||
} catch {
|
||||
return new Date().toISOString().split('T')[0];
|
||||
// 가입일을 YYYY-MM-DD 형식으로 변환
|
||||
const formatDate = (dateString: string | null | undefined): string => {
|
||||
if (!dateString) return new Date().toISOString().split('T')[0];
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toISOString().split('T')[0];
|
||||
} catch {
|
||||
return new Date().toISOString().split('T')[0];
|
||||
}
|
||||
};
|
||||
|
||||
// null 값을 명시적으로 처리
|
||||
const getValue = (value: any, fallback: string = '-') => {
|
||||
if (value === null || value === undefined) return fallback;
|
||||
if (typeof value === 'string' && value.trim() === '') return fallback;
|
||||
return String(value);
|
||||
};
|
||||
|
||||
// status가 "ACTIVE"이면 활성화, 아니면 비활성화
|
||||
const accountStatus: 'active' | 'inactive' =
|
||||
user.status === 'ACTIVE' || user.status === 'active' ? 'active' : 'inactive';
|
||||
|
||||
// role 데이터 처리
|
||||
let userRole: 'learner' | 'instructor' | 'admin' = 'learner'; // 기본값
|
||||
if (user.role) {
|
||||
const roleLower = String(user.role).toLowerCase();
|
||||
if (roleLower === 'instructor' || roleLower === '강사') {
|
||||
userRole = 'instructor';
|
||||
} else if (roleLower === 'admin' || roleLower === '관리자') {
|
||||
userRole = 'admin';
|
||||
} else {
|
||||
userRole = 'learner';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// null 값을 명시적으로 처리
|
||||
const getValue = (value: any, fallback: string = '-') => {
|
||||
if (value === null || value === undefined) return fallback;
|
||||
if (typeof value === 'string' && value.trim() === '') return fallback;
|
||||
return String(value);
|
||||
};
|
||||
|
||||
// status가 "ACTIVE"이면 활성화, 아니면 비활성화
|
||||
const accountStatus: 'active' | 'inactive' =
|
||||
user.status === 'ACTIVE' || user.status === 'active' ? 'active' : 'inactive';
|
||||
|
||||
// role 데이터 처리
|
||||
let userRole: 'learner' | 'instructor' | 'admin' = 'learner'; // 기본값
|
||||
if (user.role) {
|
||||
const roleLower = String(user.role).toLowerCase();
|
||||
if (roleLower === 'instructor' || roleLower === '강사') {
|
||||
userRole = 'instructor';
|
||||
} else if (roleLower === 'admin' || roleLower === '관리자') {
|
||||
userRole = 'admin';
|
||||
} else {
|
||||
userRole = 'learner';
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: String(user.id || user.userId || Math.random()),
|
||||
joinDate: formatDate(user.createdAt || user.joinDate || user.join_date),
|
||||
name: getValue(user.name || user.userName, '-'),
|
||||
email: getValue(user.email || user.userEmail, '-'),
|
||||
role: userRole,
|
||||
status: accountStatus,
|
||||
};
|
||||
})
|
||||
|
||||
return {
|
||||
id: String(user.id || user.userId || Math.random()),
|
||||
joinDate: formatDate(user.createdAt || user.joinDate || user.join_date),
|
||||
name: getValue(user.name || user.userName, '-'),
|
||||
email: getValue(user.email || user.userEmail, '-'),
|
||||
role: userRole,
|
||||
status: accountStatus,
|
||||
};
|
||||
})
|
||||
: [];
|
||||
|
||||
setInstructors(transformedUsers);
|
||||
@@ -322,10 +322,21 @@ export default function CourseRegistrationModal({ open, onClose, onSave, onDelet
|
||||
} else {
|
||||
// 등록 모드: POST /subjects
|
||||
try {
|
||||
await apiService.createSubject({
|
||||
courseName: courseName.trim(),
|
||||
instructorName: selectedInstructor.name,
|
||||
});
|
||||
const createRequestBody: {
|
||||
title: string;
|
||||
instructor: string;
|
||||
imageKey?: string;
|
||||
} = {
|
||||
title: courseName.trim(),
|
||||
instructor: selectedInstructor.name,
|
||||
};
|
||||
|
||||
// imageKey 처리: 등록 모드에서 새 이미지가 있으면 포함
|
||||
if (imageKey) {
|
||||
createRequestBody.imageKey = imageKey;
|
||||
}
|
||||
|
||||
await apiService.createSubject(createRequestBody);
|
||||
|
||||
// 성공 시 onSave 콜백 호출 및 모달 닫기
|
||||
if (onSave && selectedInstructor) {
|
||||
|
||||
Reference in New Issue
Block a user