From 60d8087b17b89dfceb785994a81e39e1cba9a539 Mon Sep 17 00:00:00 2001 From: inung1004 Date: Fri, 10 Nov 2023 00:34:35 +0900 Subject: [PATCH] =?UTF-8?q?fix=20::=20API=20=EC=97=B0=EB=8F=99=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20return=20=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activityAccept/ApplicationList.tsx | 2 +- src/components/activityAccept/Modal.tsx | 14 +-- .../activityAccept/MovedStudent.tsx | 4 +- src/components/attendance/Filter.tsx | 4 +- src/components/sidebar/SidebarLayout.tsx | 4 +- src/pages/attendance.tsx | 4 +- src/pages/change-person/club.tsx | 16 +-- src/pages/main.tsx | 106 +++++++++--------- src/pages/weekend-meal.tsx | 8 +- src/utils/api/common/index.ts | 2 +- src/utils/api/outing/index.ts | 2 +- src/utils/api/selfStudy/index.ts | 12 +- src/utils/api/weekendMeal/index.ts | 7 +- 13 files changed, 91 insertions(+), 94 deletions(-) diff --git a/src/components/activityAccept/ApplicationList.tsx b/src/components/activityAccept/ApplicationList.tsx index 5c60fd3..1dd5090 100644 --- a/src/components/activityAccept/ApplicationList.tsx +++ b/src/components/activityAccept/ApplicationList.tsx @@ -48,7 +48,7 @@ const ApplicationList = ({ grade: gradeResult.id as number, classNum: classResult.id as number, floor: layerResult.id as number, - type: (todayType?.data.type as string) || "SELF_STUDY", + type: (todayType?.type as string) || "SELF_STUDY", }), { cacheTime: 0, diff --git a/src/components/activityAccept/Modal.tsx b/src/components/activityAccept/Modal.tsx index 22e1eec..4bd0d10 100644 --- a/src/components/activityAccept/Modal.tsx +++ b/src/components/activityAccept/Modal.tsx @@ -108,15 +108,13 @@ const OutingIssueModal = ({ setIsOpenOutingModal }: OutingIssueModalProps) => { value={name} onChange={(e) => setName(e.target.value)} /> - {name != "" && !(userList?.data.length === 0) && ( + {name != "" && !(userList?.length === 0) && ( - {userList?.data.map( - (value: SearchedUserListType, idx: number) => ( - onSetId(value)}> - {value.num} {value.name} - - ) - )} + {userList?.map((value: SearchedUserListType, idx: number) => ( + onSetId(value)}> + {value.num} {value.name} + + ))} )} 추가 diff --git a/src/components/activityAccept/MovedStudent.tsx b/src/components/activityAccept/MovedStudent.tsx index c53fc5f..b36b5bb 100644 --- a/src/components/activityAccept/MovedStudent.tsx +++ b/src/components/activityAccept/MovedStudent.tsx @@ -57,8 +57,8 @@ const MovedStudent = ({ - {moveList?.data.move_list.length ? ( - moveList?.data.move_list.map((data) => ( + {moveList?.move_list.length ? ( + moveList?.move_list.map((data) => ( { () => getLayerClassList( floorDropDownResult.id, - isSuccessDateType && !!dateType.data.type ? dateType.data.type : "" + isSuccessDateType && !!dateType.type ? dateType.type : "" ), { - enabled: isSuccessDateType && !!dateType.data.type, + enabled: isSuccessDateType && !!dateType.type, } ); diff --git a/src/components/sidebar/SidebarLayout.tsx b/src/components/sidebar/SidebarLayout.tsx index a557aa5..378b76d 100644 --- a/src/components/sidebar/SidebarLayout.tsx +++ b/src/components/sidebar/SidebarLayout.tsx @@ -61,7 +61,7 @@ const SidebarLayout = ({ children }: { children: React.ReactNode }) => { const router = useRouter(); const { handleError } = useApiError(); - const { data: state, isSuccess } = useQuery( + const { data: state } = useQuery( "state", () => getTodaySelfStudyTeacherWhether(), { @@ -83,7 +83,7 @@ const SidebarLayout = ({ children }: { children: React.ReactNode }) => { logo -

{state?.data.name} 선생님

+

{state?.name} 선생님

{nameToInfo.map((item, idx) => { diff --git a/src/pages/attendance.tsx b/src/pages/attendance.tsx index 88b002b..f934e3a 100644 --- a/src/pages/attendance.tsx +++ b/src/pages/attendance.tsx @@ -39,8 +39,8 @@ const AttendancePage = () => { <>
- {isSuccess && attendanceCheckList.data.student_list.length ? ( - attendanceCheckList.data.student_list.map((data, idx) => { + {isSuccess && attendanceCheckList.student_list.length ? ( + attendanceCheckList.student_list.map((data, idx) => { return ( { return ( - {clubList && clubList.data.student_list.length ? ( - clubList.data.student_list?.map((list) => ( + {clubList && clubList.student_list.length ? ( + clubList.student_list?.map((list) => ( diff --git a/src/pages/main.tsx b/src/pages/main.tsx index b754de4..ed51b46 100644 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -10,87 +10,85 @@ import { getMainpageStudnetCount, } from "@/utils/api/selfStudy/index"; import { useApiError } from "@/hooks/useApiError"; +import { MainPageStudentNumber } from "@/models/selfStudy/response"; + +const QUERY_KEYS = { + POST_LIST: "postlist", + STATE: "state", + STUDENTS: "students", +}; + +const OutingText = ({ students }: { students: MainPageStudentNumber }) => ( + <> +

현재 외출 신청 학생은

+

+ 총 {students?.application}명입니다. +

+ +); + +const MoveText = ({ students }: { students: MainPageStudentNumber }) => ( + <> +

현재 2층에서 이동한

+

+ 학생 수는 {students?.classroom_movement}명입니다. +

+ +); + +const OutingListText = ({ students }: { students: MainPageStudentNumber }) => ( + <> +

현재 외출 중인 학생은

+

+ 총 {students?.picnic}명입니다. +

+ +); const Home = () => { const { handleError } = useApiError(); - const { data } = useQuery("postlist", () => getTodaySelfStudyTeacher(), { - onError: handleError, - }); + + const { data: teachers } = useQuery( + QUERY_KEYS.POST_LIST, + getTodaySelfStudyTeacher, + { onError: handleError } + ); const { data: state } = useQuery( - "state", - () => getTodaySelfStudyTeacherWhether(), - { - onError: handleError, - } + QUERY_KEYS.STATE, + getTodaySelfStudyTeacherWhether, + { onError: handleError } ); const { data: students } = useQuery( - "students", - () => getMainpageStudnetCount(), + QUERY_KEYS.STUDENTS, + getMainpageStudnetCount, { onError: handleError, cacheTime: 0 } ); - const OutingText = () => { - return ( - <> -

현재 외출 신청 학생은

-

- 총 {students?.data.application}명입니다. -

- - ); - }; - - const MoveText = () => { - return ( - <> -

현재 2층에서 이동한

-

- 학생 수는 {students?.data.classroom_movement}명입니다. -

- - ); - }; - - const OutingListText = () => { - return ( - <> -

현재 외출 중인 학생은

-

- 총 {students?.data.picnic}명입니다. -

- - ); - }; - return ( - + } img={Outing} btnText="외출 수락하러 가기" link="/activity-accept" /> } img={Attendance} btnText="출결 상태 확인하기" link="/attendance" /> } img={OutingList} btnText="외출자 목록보기" link="/outlist" diff --git a/src/pages/weekend-meal.tsx b/src/pages/weekend-meal.tsx index b3dad13..3cc4b3f 100644 --- a/src/pages/weekend-meal.tsx +++ b/src/pages/weekend-meal.tsx @@ -68,13 +68,13 @@ const WeekendMeal = () => { }), { onSuccess: () => { - setIsTeacherCheck(isTeacherCheckData?.data.check); + setIsTeacherCheck(isTeacherCheckData?.check); }, } ); useEffect(() => { - setIsTeacherCheck(isTeacherCheckData?.data.check); + setIsTeacherCheck(isTeacherCheckData?.check); }, [isTeacherCheckData]); const { mutate: teacherCheck } = useMutation( @@ -130,12 +130,12 @@ const WeekendMeal = () => {
diff --git a/src/utils/api/common/index.ts b/src/utils/api/common/index.ts index 5ddcdf3..7caf8fe 100644 --- a/src/utils/api/common/index.ts +++ b/src/utils/api/common/index.ts @@ -14,7 +14,7 @@ export const getDateType = async (date: string) => { const dateType = await instance.get( `/pick/admin/?date=${date}` ); - return dateType; + return dateType.data; }; interface GetTeachersListDto { diff --git a/src/utils/api/outing/index.ts b/src/utils/api/outing/index.ts index 32a4244..3bec966 100644 --- a/src/utils/api/outing/index.ts +++ b/src/utils/api/outing/index.ts @@ -48,5 +48,5 @@ export const searchUser = async (name: string) => { const userList = await instance.get( `/users/search?name=${name}` ); - return userList; + return userList.data; }; diff --git a/src/utils/api/selfStudy/index.ts b/src/utils/api/selfStudy/index.ts index 5685df8..518ed26 100644 --- a/src/utils/api/selfStudy/index.ts +++ b/src/utils/api/selfStudy/index.ts @@ -27,14 +27,14 @@ import { export const getTodaySelfStudyTeacherWhether = async () => { const todaySelfStudyTeacherWhether = await instance.get(`/pick/admin/state`); - return todaySelfStudyTeacherWhether; + return todaySelfStudyTeacherWhether.data; }; export const getTodaySelfStudyTeacher = async () => { const todaySelfStudyTeacher = await instance.get( `/pick/self-study/today` ); - return todaySelfStudyTeacher; + return todaySelfStudyTeacher.data; }; export const getChargeClass = async () => { @@ -63,14 +63,14 @@ export const getMainpageStudnetCount = async () => { const getManipageCount = await instance.get( `/pick/admin/students/count` ); - return getManipageCount; + return getManipageCount.data; }; export const getMoveStudentList = async (request: MoveStudentRequest) => { const moveStudentList = await instance.get( `/pick/admin/movement?grade=${request.grade}&classNum=${request.classNum}&floor=${request.floor}` ); - return moveStudentList; + return moveStudentList.data; }; export const getAttendanceCheckList = async ( @@ -79,7 +79,7 @@ export const getAttendanceCheckList = async ( const attendanceCheckList = await instance.get( `/pick/admin/attendance/${request.classroom_id}?date=${request.date}` ); - return attendanceCheckList; + return attendanceCheckList.data; }; export const getAfterSchoolMemberList = async (after_school_id: string) => { @@ -93,7 +93,7 @@ export const getClubMemberList = async (club_id: string) => { const clubMemberList = await instance.get( `/pick/admin/club/${club_id}` ); - return clubMemberList; + return clubMemberList.data; }; export const postIssuanceOuting = async (request: IssuanceOuting) => { diff --git a/src/utils/api/weekendMeal/index.ts b/src/utils/api/weekendMeal/index.ts index 64a2250..75bbc06 100644 --- a/src/utils/api/weekendMeal/index.ts +++ b/src/utils/api/weekendMeal/index.ts @@ -9,10 +9,10 @@ import instance from "@/utils/axios"; export const getWeekendMealStudentList = async ( request: WeekendMealStudentListRequestDto ) => { - const weekendMealStudentList = await instance.get( + const response = await instance.get( `/applications/admin/weekend-meal/?grade=${request.gradeNum}&classNum=${request.classNum}` ); - return weekendMealStudentList; + return response.data; }; export const checkTeacher = async (request: CheckTeacherRequestDto) => { @@ -47,7 +47,8 @@ export const weekendMealPeriodChange = async (allowedPeriod: boolean) => { export const getIsTeacherCheck = async ( request: getIsTeacherCheckRequestDto ) => { - return instance.get( + const response = await instance.get( `/applications/admin/check?grade=${request.gradeNum}&classNum=${request.classNum}` ); + return response.data; };