feat: 강의 상태(수강중/수강신청/X)에 따른 버튼 변경

This commit is contained in:
정기영 2024-08-06 15:47:08 +09:00
parent c87fe0170b
commit a26a09332e
2 changed files with 22 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import styles from './ClassInfo.module.css';
export default function ClassInfo({ classTerm, classTime, onPending = false, onSubmit }) {
export default function ClassInfo({ classTerm, classTime, status = 'NOT_ENROLLED', onSubmit }) {
// TODO: ()
return (
<div className={styles.classInfo}>
<div className={styles.title}>수업정보</div>
@ -17,9 +18,11 @@ export default function ClassInfo({ classTerm, classTime, onPending = false, onS
<button
onClick={onSubmit}
className={styles.button}
disabled={onPending}
disabled={status === 'PENDING'}
>
{onPending ? '수강신청 중' : '수강신청'}
{status === 'PENDING' && '수강신청 중'}
{status === 'ENROLLED' && '강의 상세페이지로 이동'}
{status === 'NOT_ENROLLED' && '수강신청'}
</button>
</div>
);

View File

@ -15,8 +15,7 @@ export default function LectureInfoPage() {
const startDate = new Date(lectureData.startDate).toLocaleDateString();
const endDate = new Date(lectureData.endDate).toLocaleDateString();
const userType = useBoundStore((state) => state.userType);
console.log(lectureData);
const onPending = lectureData.status === 'PENDING' ? true : false;
const status = lectureData.status;
const { lectureRegister } = useLectureRegister();
const handleSubmit = () => {
if (userType === null) {
@ -24,15 +23,20 @@ export default function LectureInfoPage() {
navigate('/auth/login');
}
lectureRegister(lectureId)
.then(() => {
// navigate(`/lecture/${lectureId}`);
window.alert('강사가 수강신청 수락시 수업이 시작됩니다.');
navigate('/');
})
.catch((err) => {
console.log(err);
});
if (status === 'ENROLLED') {
navigate(`/lecture/${lectureId}`);
}
if (status === 'NOT_ENROLLED') {
lectureRegister(lectureId)
.then(() => {
window.alert('강사가 수강신청 수락시 수업이 시작됩니다.');
navigate('/');
})
.catch((err) => {
console.log(err);
});
}
};
return (
@ -59,7 +63,7 @@ export default function LectureInfoPage() {
classTerm={`${startDate} ~ ${endDate}`}
classTime={lectureData.time}
onSubmit={handleSubmit}
onPending={onPending}
status={status}
/>
</aside>
</MaxWidthLayout>