Skip to content

Commit

Permalink
fix : main 및 자습감독 등록 수정
Browse files Browse the repository at this point in the history
fix : main 및 자습감독 등록 수정
  • Loading branch information
phyuna0525 authored Mar 13, 2024
2 parents c1d8989 + ba63f2a commit d8eb6f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
17 changes: 10 additions & 7 deletions src/apis/outList/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,18 @@ export const SelfstudyGet = () => {
};

export const DayTeacher = () => {
return useMutation<todaySelfStudy[], Error, null>({
mutationFn: async () => {
return useMutation<todaySelfStudy[], Error, { date: string }>({
mutationFn: async (param) => {
try {
const accessToken = getToken();
const response = await instance.get(`/self-study/today`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const response = await instance.get(
`/self-study/today/date=${param.date}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
return response?.data.sort((i: any, j: any) => i.floor - j.floor);
} catch (error) {
throw error;
Expand Down
45 changes: 19 additions & 26 deletions src/app/components/common/modal/selfStudyTeacher.tsx/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ChangeProps {

interface postTeacherProp {
date: string;
teachers: { floor: number; teacher: string }[];
teacher: { floor: number; teacher: string }[];
}

interface ModalProps {
Expand All @@ -28,35 +28,15 @@ const SelfStudyModal: React.FC<ModalProps> = ({
}) => {
const [secondData, setSecondData] = useState({ floor: 2, teacher: "" });
const [thirdData, setThirdData] = useState({ floor: 3, teacher: "" });
const [fourthData, setFourthData] = useState({ floor: 4, teacher: "" });
const [fourthData, setFourthData] = useState({ floor: 4, teacher: "" }); // 수정된 부분: fourthData

const { mutate: postTeacherMutate } = PostTeacher();

const handleChange = (
event: React.ChangeEvent<HTMLInputElement>,
floor: number
) => {
const { value } = event.target;
switch (floor) {
case 2:
setSecondData({ ...secondData, teacher: value });
break;
case 3:
setThirdData({ ...thirdData, teacher: value });
break;
case 4:
setFourthData({ ...fourthData, teacher: value });
break;
default:
break;
}
};

const submitTeachers = async () => {
try {
const postData: postTeacherProp = {
date: moment(initialDate).format("YYYY-MM-DD"),
teachers: [
teacher: [
{ floor: secondData.floor, teacher: secondData.teacher },
{ floor: thirdData.floor, teacher: thirdData.teacher },
{ floor: fourthData.floor, teacher: fourthData.teacher },
Expand Down Expand Up @@ -86,6 +66,16 @@ const SelfStudyModal: React.FC<ModalProps> = ({
</div>
);

const SecondhandleChange = ({ text, name }: ChangeProps) => {
setSecondData({ ...secondData, [name]: text });
};
const thirdhandleChange = ({ text, name }: ChangeProps) => {
setThirdData({ ...thirdData, [name]: text });
};
const fourthhandleChange = ({ text, name }: ChangeProps) => {
setFourthData({ ...fourthData, [name]: text }); // 수정된 부분: setFourthData
};

return (
<div className="fixed inset-0 flex items-center justify-center bg-gray-800 bg-opacity-30">
<div className="bg-white rounded-xl px-24 py-13 w-155">
Expand All @@ -104,26 +94,29 @@ const SelfStudyModal: React.FC<ModalProps> = ({
<Input
type="text"
label="2층 자습감독"
onChange={(e) => handleChange(e, 2)}
onChange={SecondhandleChange}
value={secondData.teacher}
placeholder="선생님 이름을 입력해주세요."
width="92"
name="teacher"
/>
<Input
type="text"
label="3층 자습감독"
onChange={(e) => handleChange(e, 3)}
onChange={thirdhandleChange}
value={thirdData.teacher}
placeholder="선생님 이름을 입력해주세요."
width="92"
name="teacher"
/>
<Input
type="text"
label="4층 자습감독"
onChange={(e) => handleChange(e, 4)}
onChange={fourthhandleChange}
value={fourthData.teacher}
placeholder="선생님 이름을 입력해주세요."
width="92"
name="teacher"
/>
</div>
{renderButtons()}
Expand Down
19 changes: 12 additions & 7 deletions src/app/main/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ const Main = () => {

const Check = async () => {
try {
await todayCheck(null, {
onSuccess: (data) => {
setSelfStudy(data);
},
onError: (error) => {
console.log(error);
await todayCheck(
{
date: today.toString(),
},
});
{
onSuccess: (data) => {
setSelfStudy(data);
},
onError: (error) => {
console.log(error);
},
}
);
} catch (error) {
console.log("오류 발생", error);
}
Expand Down

0 comments on commit d8eb6f6

Please sign in to comment.