Merge branch 'frontend' into 'fe/livekit'

# Conflicts:
#   frontend/src/hooks/api/useAuth.js
#   frontend/src/pages/MyInfoChangePage/MyInfoChangePage.jsx
#   frontend/src/pages/PasswordChangePage/PasswordChangePage.jsx
This commit is contained in:
조현수 2024-08-05 11:44:59 +09:00
commit 3ed79652bd
10 changed files with 68 additions and 11 deletions

View File

@ -1,13 +1,17 @@
import { Link } from 'react-router-dom';
import styles from './ClassCard.module.css';
export default function ClassCard({ path, children }) {
export default function ClassCard({ img, path, children }) {
return (
<Link
to={path}
className={styles.card}
>
<div className={styles.thumbnail} />
<img
src={'img'}
alt="강의 이미지"
className={styles.thumbnail}
/>
<div>{children}</div>
</Link>
);

View File

@ -17,8 +17,8 @@ export default function LectureLayout() {
const { data } = useLectureInfo(lectureId);
const lecture = data?.data;
const userType = useBoundStore((state) => state.userType);
const handleDelete = () => {
lectureDelete(lectureId);
const handleDelete = async () => {
await lectureDelete(lectureId);
navigate('..');
};
const lectureData = {
@ -29,7 +29,7 @@ export default function LectureLayout() {
endDate: lecture.endDate,
time: lecture.time,
};
console.log(lectureData);
return (
<>
<LectureHeader

View File

@ -0,0 +1,26 @@
import { ClassCard } from '../../components/ClassCard';
import { ClassGrid } from '../../components/ClassGrid';
import { MaxWidthLayout } from '../../components/Layout';
import { useLectures } from '../../hooks/api/useLectures';
export default function StudentHomePage() {
const { data: allLectures } = useLectures();
const allClasses = allLectures?.data ?? [];
console.log(allClasses);
return (
<MaxWidthLayout>
<ClassGrid title="전체 강의">
{allClasses.map?.((lecture) => (
<ClassCard
key={lecture.id}
path={`/lecture/${lecture.id}/info`}
img={lecture.image}
>
{lecture.title}
</ClassCard>
))}
</ClassGrid>
</MaxWidthLayout>
);
}

View File

@ -0,0 +1 @@
export { default } from './DefaultHomePage';

View File

@ -1,16 +1,16 @@
import useBoundStore from '../../store';
import StudentHomePage from '../StudentHomePage/StudentHomePage';
import TeacherHomePage from '../TeacherHomePage';
import DefaultHomePage from '../DefaultHomePage';
export default function HomePage() {
const userType = useBoundStore((state) => state.userType);
// TODO:
switch (userType) {
case 'student':
return <StudentHomePage />;
case 'teacher':
return <TeacherHomePage />;
default:
return <StudentHomePage />;
return <DefaultHomePage />;
}
}

View File

@ -1,7 +1,9 @@
import { LectureForm } from '../../components/LectureForm';
import { useLectureCreate } from '../../hooks/api/useLectureCreate';
import { useNavigate } from 'react-router-dom';
export default function LectureCreatePage() {
const navigate = useNavigate();
const { lectureCreate } = useLectureCreate();
const handleSubmit = async (lectureObject, imageFile) => {
@ -12,8 +14,9 @@ export default function LectureCreatePage() {
formData.append('image', imageFile);
}
const response = await lectureCreate(formData);
console.log(response?.data);
await lectureCreate(formData).then(() => {
navigate('..');
});
};
return (

View File

@ -1,5 +1,17 @@
import { InfoEditForm } from '../../components/InfoEditForm';
import { useAuth } from '../../hooks/api/useAuth';
import { useNavigate } from 'react-router-dom';
export default function MyInfoChangePage() {
return <InfoEditForm />;
const navigate = useNavigate();
const { updateInfo } = useAuth();
const handleSubmit = async (e, username, useremail) => {
e.preventDefault();
await updateInfo(username, useremail)
.then(() => navigate('/'))
.catch((err) => console.log(err));
};
return <InfoEditForm onSubmit={handleSubmit} />;
}

View File

@ -1,5 +1,12 @@
import { PasswordChangeForm } from '../../components/PasswordChangeForm';
import { useAuth } from '../../hooks/api/useAuth';
import { useNavigate } from 'react-router-dom';
export default function PasswordChangePage() {
return <PasswordChangeForm />;
const navigate = useNavigate();
const { updatePassword } = useAuth();
const handleSubmit = async (currentPw, newPw, newPwCheck) => {
await updatePassword(currentPw, newPw, newPwCheck).then(() => navigate('/'));
};
return <PasswordChangeForm onSubmit={handleSubmit} />;
}

View File

@ -19,6 +19,7 @@ export default function StudentHomePage() {
<ClassCard
key={lecture.id}
path={`/lecture/${lecture.id}`}
img={lecture.image}
>
{lecture.title}
</ClassCard>
@ -29,6 +30,7 @@ export default function StudentHomePage() {
<ClassCard
key={lecture.id}
path={`/lecture/${lecture.id}/info`}
img={lecture.image}
>
{lecture.title}
</ClassCard>

View File

@ -6,6 +6,7 @@ import { useMyLectures } from '../../hooks/api/useMyLectures';
export default function TeacherHomePage() {
const { data: myLectures } = useMyLectures();
const onGoingClasses = myLectures?.data ?? [];
console.log(onGoingClasses);
// TODO: ,
return (
<MaxWidthLayout>
@ -14,6 +15,7 @@ export default function TeacherHomePage() {
<ClassCard
key={lecture.id}
path={`/lecture/${lecture.id}`}
img={lecture.image}
>
{lecture.title}
</ClassCard>