Skip to content

Commit

Permalink
Merge pull request #103 from IT-Cotato/fix/misc
Browse files Browse the repository at this point in the history
[Fix] 통계 관련 자잘한 오류 수정
  • Loading branch information
yongaricode authored Feb 21, 2025
2 parents 67d6ea8 + 91764d1 commit 929fd85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 12 additions & 11 deletions src/components/Statistics/Empty.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useState } from 'react';
import Frame from '../../assets/images/Frame.svg?react';
import Button from '../Button';
import StatisticsButton from '../StatisticsButton';
import Modal from '../Modal/Modal';
import CreateModal from '../Modal/CreateModal';

const Empty = () => {
interface EmptyProps {
setModalOpen: (value: boolean) => void;
}

const Empty = ({ setModalOpen }: EmptyProps) => {
const userRole = localStorage.getItem('roleInfo');
const [modalOpen, setModalOpen] = useState(false);

return (
<div className="p-4 flex flex-col justify-center gap-6 items-center">
Expand All @@ -17,11 +16,13 @@ const Empty = () => {
<p>시험 종류를 추가하고</p>
<p>성적 통계를 한번에 보세요!</p>
</div>
{userRole == 'TEACHER' ? <StatisticsButton type="시험" onClick={() => setModalOpen(true)} /> : ''}
{modalOpen && (
<Modal onClose={() => setModalOpen(false)}>
<CreateModal type="시험" setModalOpen={setModalOpen} />
</Modal>
{userRole == 'TEACHER' && (
<StatisticsButton
type="시험"
onClick={() => {
setModalOpen(true);
}}
/>
)}
</div>
);
Expand Down
14 changes: 10 additions & 4 deletions src/pages/Statistics/Statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const Statistics = () => {
data.data.examBox.map((subject: Subject, index: number) => ({
id: subject.id,
title: subject.name,
isClicked: index == 0 ? true : false,
isClicked: index === 0,
})),
);
getExamGrade(data.data.examBox[0].id);
setSelectedTag(data.data.examBox[0].id);
setName(data.data.examBox[0].name);
}
});
}, [modalOpen]);
Expand All @@ -59,7 +60,6 @@ const Statistics = () => {
if (data.data.exams.length == 0) {
setData([]);
} else {
setName(data.data.examBoxName);
setData(data.data.exams);
}
});
Expand All @@ -69,7 +69,12 @@ const Statistics = () => {
if (tags?.length == 0 || !tags) {
return (
<div className="flex flex-col h-full justify-center items-center">
<Empty />
<Empty setModalOpen={setModalOpen} />
{modalOpen && (
<Modal onClose={() => setModalOpen(false)}>
<CreateModal type="시험" setModalOpen={setModalOpen} />
</Modal>
)}
</div>
);
}
Expand All @@ -79,6 +84,7 @@ const Statistics = () => {

getExamGrade(id);
setSelectedTag(id);
setName(title);
};

if (!data) {
Expand All @@ -96,7 +102,7 @@ const Statistics = () => {
</div>
{/* 그래프 */}
<div className="flex flex-col pt-4 pb-6 rounded-lg bg-gray-50 w-full justify-center items-center px-4 gap-6">
<h1 className="text-body2 font-semibold leading-8 tracking-[-0.18px]">시험 종류명</h1>
<h1 className="text-body2 font-semibold leading-8 tracking-[-0.18px]">{name}</h1>
<div className="w-full h-full">
<Chart data={data} />
</div>
Expand Down

0 comments on commit 929fd85

Please sign in to comment.