Skip to content

Commit

Permalink
Merge pull request #104 from COW-dev/feature#102
Browse files Browse the repository at this point in the history
�fix : 활동보고서 버튼 에러 해결
  • Loading branch information
keemsebin authored Nov 23, 2023
2 parents ba8f941 + ef28e78 commit e4aee2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
20 changes: 13 additions & 7 deletions src/components/report/category/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import Image from 'next/image';
import { useCookies } from 'react-cookie';
import toast from 'react-hot-toast';
import LeftArrow from '@/assets/leftArrow.svg';
import RightArrow from '@/assets/rightArrow.svg';
import SearchImg from '@/assets/search.svg';
import Modal from '@/components/common/Modal';
import Club from '@/components/modal/report/Club';
import { useAdminAllClubs } from '@/hooks/api/club/useAdminAllClubs';
import { useCurrentReports } from '@/hooks/api/club/useCurrentReports';
import useModal from '@/hooks/common/useModal';
import { AdminClub } from '@/types/club';
import ClubList from './ClubList';
Expand Down Expand Up @@ -34,12 +36,14 @@ const Category = ({
setVisible,
}: Props) => {
const [{ token }] = useCookies(['token']);

const [active, setActive] = useState<string>(REPORT_TYPE.CLUB);
const [clubList, setClubList] = useState<string[]>([]);
const { data: clubs } = useAdminAllClubs(token);
const [week, setWeek] = useState<number>(term);
const { openModal, visible: modalVisible, closeModal, modalRef } = useModal();
const currentTerm = Number(useCurrentReports(token).data?.data.term);
useEffect(() => {
if (currentTerm) setTerm(currentTerm);
}, [currentTerm]);

useEffect(() => {
if (clubs) {
Expand Down Expand Up @@ -80,22 +84,24 @@ const Category = ({
width={10}
height={10}
alt="leftArrow"
className={`${Number(week) === 1 && `hidden`}`}
onClick={() => {
setWeek(week - 1);
if (term === 1)
return toast.error('이전 회차가 존재하지 않습니다.');
setTerm(term - 1);
}}
/>
</div>
<div className="mx-2"> {week}회차</div>
<div className="mx-2"> {term}회차</div>
<div className="flex min-w-[10px] flex-col items-center justify-center">
<Image
src={RightArrow}
width={10}
height={10}
alt="rightArrow"
className={`${Number(term) === Number(week) && `hidden`}`}
onClick={() => {
setWeek(week + 1);
if (term === currentTerm)
return toast.error('다음 회차가 열리지 않았습니다.');
setTerm(term + 1);
}}
/>
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/pages/admin/report/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { useState } from 'react';
import Head from 'next/head';
import Image from 'next/image';
import { useCookies } from 'react-cookie';
import ArrowDown from '@/assets/arrowDown.svg';
import ArrowUp from '@/assets/arrowUp.svg';
import Heading from '@/components/common/Heading';
import Category from '@/components/report/category';
import ReportItem from '@/components/report/ReportItem';
import { useCurrentReports } from '@/hooks/api/club/useCurrentReports';

export default function Index() {
const [{ token }] = useCookies(['token']);
const [visible, setVisible] = useState<boolean>(true);
const [club, setClub] = useState<string>('너나들이');
const currentTerm = useCurrentReports(token).data?.data.term ?? 1;
const [term, setTerm] = useState<number>(currentTerm);
const [term, setTerm] = useState<number>(1);

return (
<>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ export default function Home() {

useEffect(() => {
const clubList = data?.data ?? [];
const sortedClubs = [...clubList].sort(
let sortedClubs = [...clubList].sort(
(a, b) =>
a.category.localeCompare(b.category) || a.name.localeCompare(b.name),
);
const semiClubs = sortedClubs.filter(
(club) => club.category === '준동아리',
);
sortedClubs = sortedClubs.filter((club) => club.category !== '준동아리');
sortedClubs = [...sortedClubs, ...semiClubs];
setClubs(sortedClubs);
setFilteredClubs(sortedClubs);
}, [data]);
Expand Down

0 comments on commit e4aee2a

Please sign in to comment.