Skip to content

Commit

Permalink
add : 전공동아리 정보 추가 및 교실 이동 전체 조회
Browse files Browse the repository at this point in the history
add : 전공동아리 정보 추가 및 교실 이동 전체 조회
  • Loading branch information
phyuna0525 authored Jun 25, 2024
2 parents 1724955 + 72a15fa commit fc087bd
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 34 deletions.
16 changes: 16 additions & 0 deletions src/apis/changeClass/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ export const AcceptClassChange = () => {
});
};

export const AllClassChange = () => {
const { handleError } = apiError();
return useMutation<FloorClass[], Error, { status: "QUIET" | "OK" }>({
mutationFn: async (param) => {
try {
const { data } = await instance.get(
`/class-room/all?status=${param.status}`
);
return data;
} catch (error) {
handleError(error);
}
},
});
};

export const AcceptClass = () => {
const { handleError } = apiError();
return useMutation<void, Error, { status: string; id: string[] }>({
Expand Down
7 changes: 4 additions & 3 deletions src/apis/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ export interface ChangeClub {
}

export interface changeClass {
id: string;
class_num: number;
classroom_name: string;
floor: number;
end_period: number;
grade: number;
id: string;
move: string;
num: number;
user_id: string;
start_period: number;
username: string;
}

Expand Down
38 changes: 23 additions & 15 deletions src/app/classChange/ok/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@ import { getFullToday } from "@/utils/date";
import { useState } from "react";
import Dropdown from "../../components/common/dropdown";
import ChangeClass from "../../components/common/list/changeClass/page";
import { ChangeClassList, GetFloor } from "@/apis/changeClass";
import { AllClassChange, ChangeClassList, GetFloor } from "@/apis/changeClass";
import { getStudentString } from "@/utils/until";
import { BackGround } from "../../components/common/background";
import Link from "next/link";

interface changeClass {
id: string;
class_num: number;
classroom_name: string;
floor: number;
end_period: number;
grade: number;
id: string;
move: string;
num: number;
user_id: string;
start_period: number;
username: string;
}

const ClassChangeOk = () => {
const [selectedTab, setSelectedTab] = useState<boolean>(true);
const [selectedGrade, setSelectedGrade] = useState<number>(1);
const [selectedClass, setSelectedClass] = useState<number>(1);
const { mutate: changelistMutate } = ChangeClassList();
const [floorData, setFloorData] = useState<changeClass[]>([]);
const { mutate: changelistFloorMutate } = GetFloor();
const [changelist, setChangelist] = useState<changeClass[]>([]);
const [selectedFloor, setSelectedFloor] = useState<number>(2);
const [selectedFloor, setSelectedFloor] = useState<number>(5);

const { mutate: changelistMutate } = ChangeClassList();
const { mutate: changelistFloorMutate } = GetFloor();
const { mutate: AllClassChangeList } = AllClassChange();

const onClickTab = (tab: boolean) => {
setSelectedTab(tab);
Expand All @@ -55,13 +58,18 @@ const ClassChangeOk = () => {
ChangeClassDataFloor();
}, [selectedFloor]);

useEffect(() => {
changeClassData();
}, []);

const ChangeClassDataFloor = async () => {
try {
if (selectedFloor) {
if (selectedFloor === 5) {
await AllClassChangeList(
{ status: "OK" },
{
onSuccess: (data) => {
setFloorData(data);
},
}
);
} else {
try {
await changelistFloorMutate(
{ floor: selectedFloor },
{
Expand All @@ -73,9 +81,9 @@ const ClassChangeOk = () => {
},
}
);
} catch (error) {
console.log(error);
}
} catch (error) {
console.log(error);
}
};

Expand Down
36 changes: 26 additions & 10 deletions src/app/classChange/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use client";
import { getFullToday } from "@/utils/date";
import { BackGround } from "../components/common/background";
import { AcceptClass, AcceptClassChange } from "@/apis/changeClass";
import {
AcceptClass,
AcceptClassChange,
AllClassChange,
} from "@/apis/changeClass";
import Dropdown from "../components/common/dropdown";
import { useEffect, useState } from "react";
import Button from "../components/common/Button";
Expand All @@ -24,7 +28,7 @@ interface FloorClass {
}

const ClassChange = () => {
const [selectedFloor, setSelectedFloor] = useState<number>(2);
const [selectedFloor, setSelectedFloor] = useState<number>(5);
const [data, setData] = useState<FloorClass[]>([]);
const [accept, setAccept] = useState<boolean>(false);
const [refuse, setRefuse] = useState<boolean>(false);
Expand All @@ -33,6 +37,7 @@ const ClassChange = () => {

const { mutate: AccpetMutate } = AcceptClassChange();
const { mutate: AccpetList } = AcceptClass();
const { mutate: AllClassChangeR } = AllClassChange();

const Accept = () => {
if (selectedStudents.length === 0) {
Expand All @@ -47,20 +52,31 @@ const ClassChange = () => {
};

const Accpet = async () => {
try {
await AccpetMutate(
{ floor: selectedFloor },
if (selectedFloor === 5) {
await AllClassChangeR(
{ status: "QUIET" },
{
onSuccess: (data) => {
setData(data);
},
onError: (error) => {
alert(error.name);
},
}
);
} catch (error) {
console.log(error);
} else {
try {
await AccpetMutate(
{ floor: selectedFloor },
{
onSuccess: (data) => {
setData(data);
},
onError: (error) => {
alert(error.name);
},
}
);
} catch (error) {
console.log(error);
}
}
};

Expand Down
21 changes: 15 additions & 6 deletions src/app/components/common/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface DropProps {
const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
const [selectedGradeOption, setSelectedGradeOption] = useState<number>(1);
const [selectedClassOption, setSelectedClassOption] = useState<number>(1);
const [selectedFloorOption, setSelectedFloorOption] = useState<number>(2);
const [selectedFloorOption, setSelectedFloorOption] = useState<number>(5);
const [selectedClubOption, setSelectedClubOption] =
useState<string>("세미나실 2-1(대동여지도)");
const [selectedAllOption, setSelectedAllOption] = useState<number>(1);
Expand Down Expand Up @@ -45,7 +45,7 @@ const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);
}, [type]);

const handleOptionClick = (option: any) => {
if (onChange) {
Expand Down Expand Up @@ -81,6 +81,7 @@ const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
{ value: 2, label: "2층" },
{ value: 3, label: "3층" },
{ value: 4, label: "4층" },
{ value: 5, label: "전체" },
];

const AllOption = [
Expand All @@ -104,10 +105,16 @@ const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
];

const clubOptions = [
{ value: "자습", label: "3-1교실(자습)" },
{ value: "대동여지도", label: "세미나실 2-1(대동여지도)" },
{ value: "DMS", label: "세미나실 2-2(DMS)" },
{ value: "gram", label: "세미나실 2-3(gram)" },
{ value: "Liear", label: "세미나실 2-4(Liear)" },
{ value: "gram1", label: "3-2교실(gram)" },
{ value: "EXIT", label: "소개1실(EXIT)" },
{ value: "Lift", label: "소개2실(Lift)" },
{ value: "DMS3학년", label: "소개 3실(DMS 3학년)" },
{ value: "자습", label: "2-1교실(자습)" },
{ value: "Log", label: "세미나실 3-1(Log)" },
{ value: "은하", label: "세미나실 3-2(은하)" },
{ value: "PiCK", label: "세미나실 3-3(PiCK)" },
Expand All @@ -116,7 +123,7 @@ const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
{ value: "TeamQSS", label: "세미나실 4-1(TeamQSS)" },
{ value: "NoNamed", label: "세미나실 4-2(NoNamed)" },
{ value: "Modeep", label: "세미나실 4-3(Modeep)" },
{ value: "자습", label: "자습" },
{ value: "자습", label: "1-1교실(자습)" },
];

const options =
Expand All @@ -143,21 +150,23 @@ const Dropdown: React.FC<DropProps> = ({ type, onChange }) => {
: type === "class"
? `${selectedClassOption}반`
: type === "floor"
? `${selectedFloorOption}층`
? selectedFloorOption === 5
? `전체`
: `${selectedFloorOption}층`
: type === "all"
? selectedAllOption === 5
? `전체`
: `${selectedAllOption}학년`
: selectedClubOption}
<Image
src={isDropdownVisible ? `${downarrow.src}` : `${arrow.src}`}
src={isDropdownVisible ? downarrow.src : arrow.src}
alt="arrow"
width={16}
height={16}
/>
</div>
{isDropdownVisible && (
<div className="absolute h-auto max-h-72 overflow-y-scroll bg-white border rounded-lg w-full text-Button-S z-20">
<div className="absolute h-auto max-h-72 overflow-y-scroll bg-white border rounded-lg w-max text-Button-S z-20">
{generateOptions(options)}
</div>
)}
Expand Down

0 comments on commit fc087bd

Please sign in to comment.