Skip to content

Commit

Permalink
fix :: API 연동 함수 return 값 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
inung1004 committed Nov 9, 2023
1 parent 2d8e8c0 commit 60d8087
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/components/activityAccept/ApplicationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions src/components/activityAccept/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) && (
<SearchStudentList>
{userList?.data.map(
(value: SearchedUserListType, idx: number) => (
<span key={idx} onClick={() => onSetId(value)}>
{value.num} {value.name}
</span>
)
)}
{userList?.map((value: SearchedUserListType, idx: number) => (
<span key={idx} onClick={() => onSetId(value)}>
{value.num} {value.name}
</span>
))}
</SearchStudentList>
)}
<AddButton onClick={pushUserIdList}>추가</AddButton>
Expand Down
4 changes: 2 additions & 2 deletions src/components/activityAccept/MovedStudent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const MovedStudent = ({
</ActivityBtn>
</HeadBar>
<MovingBox>
{moveList?.data.move_list.length ? (
moveList?.data.move_list.map((data) => (
{moveList?.move_list.length ? (
moveList?.move_list.map((data) => (
<MovingComponent
key={data.student_number}
student_number={data.student_number}
Expand Down
4 changes: 2 additions & 2 deletions src/components/attendance/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ const Filter = ({ setClassName, setDate, setClassroomId }: Props) => {
() =>
getLayerClassList(
floorDropDownResult.id,
isSuccessDateType && !!dateType.data.type ? dateType.data.type : ""
isSuccessDateType && !!dateType.type ? dateType.type : ""
),
{
enabled: isSuccessDateType && !!dateType.data.type,
enabled: isSuccessDateType && !!dateType.type,
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/components/sidebar/SidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
{
Expand All @@ -83,7 +83,7 @@ const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
<SidebarWrapper id="sidebar">
<TitleContainer>
<Image onClick={onClickLogo} src={Logo} alt="logo" />
<h1>{state?.data.name} 선생님</h1>
<h1>{state?.name} 선생님</h1>
</TitleContainer>
<ItemContainer>
{nameToInfo.map((item, idx) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/attendance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const AttendancePage = () => {
<>
<Header className={className} isFriday={isFriday} />
<StudentWrapper>
{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 (
<List
key={idx}
Expand Down
16 changes: 8 additions & 8 deletions src/pages/change-person/club.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from "@emotion/styled";
import { useEffect, useState } from "react";
import { useState } from "react";
import { ItemType } from "../../models/common/index";
import Member from "@/components/club/member";
import DropDown from "@/components/common/Dropdown";
Expand Down Expand Up @@ -69,22 +69,22 @@ const ClubPerson = () => {

return (
<PageContainer
title={clubList?.data.club_name! && `${clubList?.data.club_name}`}
title={clubList?.club_name! && `${clubList?.club_name}`}
subTitle={
clubList?.data
? `${clubList?.data.classroom_name}(${clubList?.data.teacher_name}
clubList
? `${clubList.classroom_name}(${clubList.teacher_name}
선생님 담당)`
: `층 및 동아리를 선택해주세요.`
}
filter={filter}
>
<Container>
{clubList && clubList.data.student_list.length ? (
clubList.data.student_list?.map((list) => (
{clubList && clubList.student_list.length ? (
clubList.student_list?.map((list) => (
<Member
key={list.student_id}
head_club_id={clubList.data.club_id}
club_name={clubList.data.club_name}
head_club_id={clubList.club_id}
club_name={clubList.club_name}
refetch={refetch}
{...list}
/>
Expand Down
106 changes: 52 additions & 54 deletions src/pages/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<>
<p>현재 외출 신청 학생은</p>
<p>
<i>{students?.application}</i>입니다.
</p>
</>
);

const MoveText = ({ students }: { students: MainPageStudentNumber }) => (
<>
<p>현재 2층에서 이동한</p>
<p>
학생 수는 <i>{students?.classroom_movement}</i>입니다.
</p>
</>
);

const OutingListText = ({ students }: { students: MainPageStudentNumber }) => (
<>
<p> 현재 외출 중인 학생은</p>
<p>
<i>{students?.picnic}</i>입니다.
</p>
</>
);

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 (
<>
<p>현재 외출 신청 학생은</p>
<p>
<i>{students?.data.application}</i>입니다.
</p>
</>
);
};

const MoveText = () => {
return (
<>
<p>현재 2층에서 이동한</p>
<p>
학생 수는 <i>{students?.data.classroom_movement}</i>입니다.
</p>
</>
);
};

const OutingListText = () => {
return (
<>
<p> 현재 외출 중인 학생은</p>
<p>
<i>{students?.data.picnic}</i>입니다.
</p>
</>
);
};

return (
<MainPageContainer>
<Date
date={state?.data.date!}
name={state?.data.name!}
floor={state?.data.floor!}
/>
<Date date={state?.date!} name={state?.name!} floor={state?.floor!} />
<TodayTeacher
second_floor={data?.data.second_floor!}
third_floor={data?.data.third_floor!}
fourth_floor={data?.data.fourth_floor!}
second_floor={teachers?.second_floor!}
third_floor={teachers?.third_floor!}
fourth_floor={teachers?.fourth_floor!}
/>
<CardContainer>
<Card
text={OutingText}
text={() => <OutingText students={students!} />}
img={Outing}
btnText="외출 수락하러 가기"
link="/activity-accept"
/>
<Card
text={MoveText}
text={() => <MoveText students={students!} />}
img={Attendance}
btnText="출결 상태 확인하기"
link="/attendance"
/>
<Card
text={OutingListText}
text={() => <OutingListText students={students!} />}
img={OutingList}
btnText="외출자 목록보기"
link="/outlist"
Expand Down
8 changes: 4 additions & 4 deletions src/pages/weekend-meal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -130,12 +130,12 @@ const WeekendMeal = () => {
<StudentContainer
title="응답자"
subTitle="응답자의 상태는 수정할 수 없습니다"
students={studentList?.data.response_students}
students={studentList?.response_students}
/>
<StudentContainer
title="미응답자"
subTitle="미응답자의 상태를 수정할 수 있습니다"
students={studentList?.data.non_response_students}
students={studentList?.non_response_students}
/>
</Wrapper>
</PageContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getDateType = async (date: string) => {
const dateType = await instance.get<GetDateTypeDto>(
`/pick/admin/?date=${date}`
);
return dateType;
return dateType.data;
};

interface GetTeachersListDto {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api/outing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export const searchUser = async (name: string) => {
const userList = await instance.get<SearchedUserListType[]>(
`/users/search?name=${name}`
);
return userList;
return userList.data;
};
12 changes: 6 additions & 6 deletions src/utils/api/selfStudy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import {
export const getTodaySelfStudyTeacherWhether = async () => {
const todaySelfStudyTeacherWhether =
await instance.get<TodaySelfStudyTeacher>(`/pick/admin/state`);
return todaySelfStudyTeacherWhether;
return todaySelfStudyTeacherWhether.data;
};

export const getTodaySelfStudyTeacher = async () => {
const todaySelfStudyTeacher = await instance.get<TodaySelfStudyTeacherDto>(
`/pick/self-study/today`
);
return todaySelfStudyTeacher;
return todaySelfStudyTeacher.data;
};

export const getChargeClass = async () => {
Expand Down Expand Up @@ -63,14 +63,14 @@ export const getMainpageStudnetCount = async () => {
const getManipageCount = await instance.get<MainPageStudentNumber>(
`/pick/admin/students/count`
);
return getManipageCount;
return getManipageCount.data;
};

export const getMoveStudentList = async (request: MoveStudentRequest) => {
const moveStudentList = await instance.get<MoveSudentList>(
`/pick/admin/movement?grade=${request.grade}&classNum=${request.classNum}&floor=${request.floor}`
);
return moveStudentList;
return moveStudentList.data;
};

export const getAttendanceCheckList = async (
Expand All @@ -79,7 +79,7 @@ export const getAttendanceCheckList = async (
const attendanceCheckList = await instance.get<AttendanceCheckStudentList>(
`/pick/admin/attendance/${request.classroom_id}?date=${request.date}`
);
return attendanceCheckList;
return attendanceCheckList.data;
};

export const getAfterSchoolMemberList = async (after_school_id: string) => {
Expand All @@ -93,7 +93,7 @@ export const getClubMemberList = async (club_id: string) => {
const clubMemberList = await instance.get<ClubMemberList>(
`/pick/admin/club/${club_id}`
);
return clubMemberList;
return clubMemberList.data;
};

export const postIssuanceOuting = async (request: IssuanceOuting) => {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/api/weekendMeal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
};

0 comments on commit 60d8087

Please sign in to comment.