Merge branch 'FE/DefaultHomePage' into 'frontend'

[Front-End] feat: DefaultHomePage 추가

See merge request s11-webmobile1-sub2/S11P12A701!38
This commit is contained in:
조현수 2024-08-05 11:43:28 +09:00
commit 676bba7cbd
11 changed files with 54 additions and 15 deletions

View File

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

View File

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

View File

@ -47,8 +47,7 @@ export function useAuth() {
const logout = () => { const logout = () => {
return instance return instance
.post(`${API_URL}/user/logout`) .post(`${API_URL}/user/logout`)
.then((response) => { .then(() => {
console.log(response);
setUserType(null); setUserType(null);
setToken(null); setToken(null);
}) })

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 useBoundStore from '../../store';
import StudentHomePage from '../StudentHomePage/StudentHomePage'; import StudentHomePage from '../StudentHomePage/StudentHomePage';
import TeacherHomePage from '../TeacherHomePage'; import TeacherHomePage from '../TeacherHomePage';
import DefaultHomePage from '../DefaultHomePage';
export default function HomePage() { export default function HomePage() {
const userType = useBoundStore((state) => state.userType); const userType = useBoundStore((state) => state.userType);
// TODO:
switch (userType) { switch (userType) {
case 'student': case 'student':
return <StudentHomePage />; return <StudentHomePage />;
case 'teacher': case 'teacher':
return <TeacherHomePage />; return <TeacherHomePage />;
default: default:
return <StudentHomePage />; return <DefaultHomePage />;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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