Skip to content

Commit

Permalink
chore : 외출자 층별 조회
Browse files Browse the repository at this point in the history
chore : 외출자 층별 조회
  • Loading branch information
phyuna0525 authored Jul 9, 2024
2 parents b5f64de + 0a98514 commit 7ebff24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
18 changes: 12 additions & 6 deletions src/apis/outList/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface applicationOK {
grade: number;
class_num: number;
num: number;
reason: string;
}

interface OutListData {
Expand Down Expand Up @@ -126,14 +127,19 @@ export const ReturnSchool = () => {
});
};

export const OutListProp = () => {
export const FloorOutList = () => {
const { handleError } = apiError();
return useQuery<applicationOK[]>({
queryKey: ["outListProp"],
queryFn: async () => {
return useMutation<
applicationOK[],
Error,
{ floor: number; status: "QUIET" | "NO" | "OK" }
>({
mutationFn: async (param) => {
try {
const response = await instance.get(`/application/non-return`);
return response.data;
const { data } = await instance.get(
`application/floor?floor=${param.floor}&status=${param.status}`
);
return data;
} catch (error) {
handleError(error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/common/list/out/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ interface OutProps {
student: string;
returnTime: string;
id: string;
reason: string;
}

const Out: React.FC<OutProps> = ({ student, returnTime, id }) => {
const Out: React.FC<OutProps> = ({ student, returnTime, id, reason }) => {
return (
<>
<div className="rounded-lg flex justify-between items-center bg-white py-5 px-4 w-120 border hover:border-primary-400">
Expand Down
35 changes: 23 additions & 12 deletions src/app/outList/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import React from "react";
import { useRouter } from "next/navigation";
import DoubleTab from "../components/common/tab/page";
import Button from "../components/common/Button";
import { getFullToday } from "@/utils/date";
import ReturnHome from "../components/common/list/returnHome/page";
import Out from "../components/common/list/out/page";
import { useState, useEffect } from "react";
import { OutListProp, ReturnHomeList } from "@/apis/outList/list";
import { FloorOutList, ReturnHomeList } from "@/apis/outList/list";
import { getStudentString } from "@/utils/until";
import { BackGround } from "../components/common/background";
import Dropdown from "../components/common/dropdown";

interface earlyreturnOK {
id: string;
Expand All @@ -28,30 +28,42 @@ interface applicationOK {
grade: number;
class_num: number;
num: number;
reason: string;
}

const OutList = () => {
const [selectedTab, setSelectedTab] = useState<boolean>(true);
const [applicationList, setApplicationList] = useState<applicationOK[]>([]);
const [earlyreturnlist, setEarlyreturnList] = useState<earlyreturnOK[]>([]);
const [selectedFloor, setSelectedFloor] = useState<number>(5);

const router = useRouter();

const { data: outList } = OutListProp();
const { mutate: floorList } = FloorOutList();
const { data: home } = ReturnHomeList();

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

const reason = () => {
router.push(`/outList/reason`);
const handleFloorChange = (selectedOption: number) => {
setSelectedFloor(selectedOption);
};

const Get = async () => {
floorList(
{ floor: selectedFloor, status: "OK" },
{
onSuccess: (data) => {
setApplicationList(data);
},
}
);
};

useEffect(() => {
if (outList) {
setApplicationList(outList);
}
}, [outList]);
Get();
}, [selectedFloor]);

useEffect(() => {
if (home) {
Expand All @@ -71,9 +83,7 @@ const OutList = () => {
secondChildren="조기귀가"
onClick={onClickTab}
/>
<Button colorType="ghost" buttonSize="small" onClick={reason}>
사유보기
</Button>
<Dropdown type="floor" onChange={handleFloorChange} />
</>
}
>
Expand All @@ -85,6 +95,7 @@ const OutList = () => {
key={index}
returnTime={data.end_time}
student={getStudentString(data)}
reason={data.reason}
/>
))}
</div>
Expand Down

0 comments on commit 7ebff24

Please sign in to comment.