Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuna committed Aug 27, 2024
2 parents 4758419 + 4a74fb9 commit 8a450a4
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 180 deletions.
15 changes: 8 additions & 7 deletions src/apis/outAccept/outAccept.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQuery } from "@tanstack/react-query";
import { instance } from "..";
import apiError from "@/hook/apiError";

Expand Down Expand Up @@ -35,15 +35,16 @@ interface ClassProp {
type: string;
}

export const useGetClass = () => {
export const useGetClass = (grade: number, class_num: number, type: string) => {
const { handleError } = apiError();
return useMutation<applicationDataProp[], applicationDataProp[], ClassProp>({
mutationFn: async (param: ClassProp) => {
return useQuery({
queryKey: ["useGetClass", grade, class_num, type],
queryFn: async () => {
try {
const response = await instance.get(
`${param.type}/grade?grade=${param.grade}&class_num=${param.class}`
const { data } = await instance.get<applicationDataProp[]>(
`${type}/grade?grade=${grade}&class_num=${class_num}`
);
return response.data;
return data;
} catch (error) {
handleError(error);
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/afterManage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const AfterManage = () => {
const [modal, setModal] = useState<boolean>(false);
const [change, setChange] = useState<boolean>(false);
const [clubList, setClubList] = useState<ClubList[]>([]);
const [dataList, setDataList] = useState<AfterStudent[]>();
const [saveModal, setSaveModal] = useState<boolean>(false);
const [dataList, setDataList] = useState<AfterStudent[]>();
const [selectClub, setSelectClub] = useState<string>("대동여지도");
const { selectedStudents, selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();
const { data: getAfter } = GetAfterStudent();
const { data: getClub } = GetClubList(selectClub);
const { data: getAfter, refetch: ReGetAfter } = GetAfterStudent();
const { data: getClub, refetch: ReGetClub } = GetClubList(selectClub);
const { mutate: Post } = PostStudent();

const { mutate: CheckClub } = CheckStatus();
Expand Down Expand Up @@ -148,11 +148,11 @@ const AfterManage = () => {
};
updatedData.push(studentData);
}
FixStatusMutate(updatedData, {
onSuccess: () => {
location.reload();
},
});
});
FixStatusMutate(updatedData, {
onSuccess: () => {
ReGetAfter();
},
});
setSaveModal(false);
};
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/common/list/after/check/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import AfterCheck from "../page";
import useAttendanceStore from "@/stores/useChangeStatus";

interface State {
state1: string;
Expand Down Expand Up @@ -41,6 +42,8 @@ const CheckList: React.FC<State> = ({
return "현체";
case "EMPLOYMENT":
return "취업";
case "GO_HOME":
return "귀가";
default:
return "";
}
Expand All @@ -55,7 +58,6 @@ const CheckList: React.FC<State> = ({
useEffect(() => {
localStorage.setItem(id, JSON.stringify(statusList));
}, [id, statusList]);

const handleChange = (index: number, newState: string) => {
const newStatusList = [...statusList];
for (let i = index; i < newStatusList.length; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/app/components/common/list/after/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
return "#414BA2";
case "출석":
return "#475467";
case "귀가":
"#475467";
default:
return undefined;
}
Expand All @@ -80,6 +82,8 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
return "MOVEMENT";
case "출석":
return "ATTENDANCE";
case "귀가":
return "GO_HOME";
default:
return "";
}
Expand Down Expand Up @@ -131,6 +135,12 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
>
외출
</div>
<div
className={`${commonStyle} text-neutral-50`}
onClick={() => handleOptionClick("귀가")}
>
귀가
</div>
<div
className={`${commonStyle} text-error-400`}
onClick={() => handleOptionClick("무단")}
Expand Down
61 changes: 0 additions & 61 deletions src/app/components/common/surveyModal/index.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions src/app/main/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { GetStudentNum, TodaySelfStudys } from "@/apis/main";
import { GetTeacherName } from "@/apis/login/login";
import { useRouter } from "next/navigation";
import { TodaySelfStudy } from "@/apis/type";
import SurveyModal from "../components/common/surveyModal";

interface Type {
out: number;
Expand All @@ -39,7 +38,6 @@ const Main = () => {
const { data: CountNum } = GetStudentNum();
const { data: getName } = GetTeacherName();
const { data: selfStudyData } = TodaySelfStudys(getFullToday());
const [surveyModal, setSurveyModal] = useState<boolean>(false);

useEffect(() => {
if (selfStudyData) {
Expand Down Expand Up @@ -75,13 +73,6 @@ const Main = () => {
router.push(`/outList`);
}

useEffect(() => {
const check = localStorage.getItem("survey");
if (check !== "OK") {
setSurveyModal(true);
}
}, []);

return (
<div className="w-full h-full">
<Header />
Expand Down Expand Up @@ -177,13 +168,6 @@ const Main = () => {
</div>
</div>
<div className=" bg-neutral-700 h-96"></div>
{surveyModal && (
<SurveyModal
onClick={() => {
setSurveyModal(false);
}}
/>
)}
</div>
);
};
Expand Down
105 changes: 29 additions & 76 deletions src/app/outAccept/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@ const OutAccept = () => {
const [accept, setAccept] = useState<boolean>(false);
const { selectedStudents, selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();
const [data, setData] = useState<applicationDataProp[]>([]);

const { mutate: outAcceptMutate } = useOutAccept();
const { mutate: getClassMutate } = useGetClass();
const { data: getClassMutate, refetch: ReGetClassMutate } = useGetClass(
selectedGrade,
selectedClass,
selectedTab ? "application" : "early-return"
);

const onClickTab = (tab: boolean) => {
setSelectedTab(tab);
};

useEffect(() => {
AcceptDataList();
}, [selectedTab]);

useEffect(() => {
AcceptDataList();
}, [selectedGrade, selectedClass]);

const handleGradeChange = (selectedOption: number) => {
if (selectedOption === 5) {
setSelectedGrade(5);
Expand Down Expand Up @@ -77,31 +71,6 @@ const OutAccept = () => {
setSelectedClass(setclass_num);
}, []);

const AcceptDataList = async () => {
try {
if (selectedGrade && selectedClass) {
const reqOption = selectedTab ? "application" : "early-return";
await getClassMutate(
{
type: reqOption,
grade: selectedGrade,
class: selectedClass,
},
{
onSuccess: (data) => {
setData(data);
},
onError: (error) => {
console.log(error);
},
}
);
}
} catch (error) {
console.error("Out accept error", error);
}
};

const Acceptconfirm = async () => {
try {
if (selectedGrade && selectedClass) {
Expand All @@ -114,9 +83,8 @@ const OutAccept = () => {
},
{
onSuccess: () => {
setData(data);
setAccept(false);
location.reload();
ReGetClassMutate();
},
onError: () => {
setAccept(false);
Expand Down Expand Up @@ -167,12 +135,11 @@ const OutAccept = () => {
ids: selectedStudents,
},
{
onSuccess: (response) => {
setData(data);
onSuccess: () => {
setRefuse(false);
location.reload();
ReGetClassMutate();
},
onError: (error) => {
onError: () => {
setRefuse(false);
},
}
Expand All @@ -192,47 +159,33 @@ const OutAccept = () => {
setAccept(false);
};

const previous = () => {
router.push("/outAccept/previous");
};

return (
<BackGround
linkChildren="외출 수락"
subTitle="외출 수락"
secondTitle={getFullToday()}
DropChildren={
<>
<Button colorType="ghost" buttonSize="small" onClick={previous}>
<Button
colorType="ghost"
buttonSize="small"
onClick={() => router.push("/outAccept/previous")}
>
외출 기록보기
</Button>
{selectedTab ? (
<div className=" flex gap-5">
<Dropdown
type="all"
onChange={handleGradeChange}
homeRoom={true}
/>
<Dropdown
type="class"
onChange={handleClassChange}
homeRoom={true}
/>
</div>
) : (
<div className=" flex gap-5">
<Dropdown
type="all"
onChange={handleGradeChange}
homeRoom={true}
/>
<Dropdown
type="class"
onChange={handleClassChange}
homeRoom={true}
/>
</div>
)}
<div className=" flex gap-5">
{selectedTab ? (
<>
<Dropdown type="all" onChange={handleGradeChange} homeRoom />
<Dropdown type="class" onChange={handleClassChange} homeRoom />
</>
) : (
<>
<Dropdown type="all" onChange={handleGradeChange} homeRoom />
<Dropdown type="class" onChange={handleClassChange} homeRoom />
</>
)}
</div>
</>
}
>
Expand All @@ -244,7 +197,7 @@ const OutAccept = () => {
/>
{selectedTab ? (
<div className="flex flex-wrap gap-5 justify-between">
{data.map((dataItem, index) => (
{getClassMutate?.map((dataItem, index) => (
<AcceptList
onClick={() =>
handleAcceptListClick(dataItem.id, dataItem.username)
Expand All @@ -258,7 +211,7 @@ const OutAccept = () => {
</div>
) : (
<div className="flex flex-wrap gap-5 justify-between">
{data.map((dataItem, index) => (
{getClassMutate?.map((dataItem, index) => (
<AcceptList
onClick={() =>
handleAcceptListClick(dataItem.user_id, dataItem.username)
Expand Down
Loading

0 comments on commit 8a450a4

Please sign in to comment.