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 1, 2024
2 parents 422dfb2 + 895f18c commit 8e5c84b
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 99 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev -H 0.0.0.0",
"build": "next build",
"start": "next start",
"start": "next dev -H 0.0.0.0",
"lint": "next lint"
},
"dependencies": {
Expand Down
39 changes: 14 additions & 25 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios, { AxiosError } from "axios";
import { cookie } from "@/utils/auth";
import { useRouter } from "next/navigation";

const BASEURL = process.env.NEXT_PUBLIC_API_KEY;

Expand Down Expand Up @@ -38,40 +37,30 @@ refreshInstance.interceptors.request.use(

instance.interceptors.response.use(
(response) => response,
async (error: AxiosError<AxiosError>) => {
async (error: AxiosError) => {
if (axios.isAxiosError(error) && error.response) {
const { status } = error.response.data;
const { status } = error.response;
if (status === 401) {
const refreshToken = cookie.get("refresh_token");
if (refreshToken) {
try {
const res = await axios.put(
`${BASEURL}/refresh`,
{},
{
await axios
.put(`${BASEURL}/admin/refresh`, null, {
headers: {
"X-Refresh-Token": `Bearer ${refreshToken}`,
"X-Refresh-Token": `${refreshToken}`,
},
}
);
const { data } = res.data;
const accessToken = data.accessToken;
cookie.set("access_token", accessToken);
if (error.config) {
error.config.headers.Authorization = `Bearer ${accessToken}`;
return axios.request(error.config);
}
} catch {
throw error;
})
.then((response) => {
const data = response.data;
cookie.set("access_token", data.access_token);
cookie.set("refresh_token", data.refresh_token);
});
} catch (refreshError) {
return Promise.reject(refreshError);
}
} else {
throw error;
}
} else {
throw error;
}
} else {
throw error;
}
return Promise.reject(error);
}
);
4 changes: 0 additions & 4 deletions src/apis/notice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ interface Getnotice {
title: string;
create_at: string;
teacher: string;
grade: number[];
}

interface DetailNoticeType {
title: string;
content: string;
create_at: string;
teacher: string;
grade: number[];
}

interface post {
title: string;
content: string;
grade: number[];
}

interface ModifyProp {
id: string;
title: string;
content: string;
grade: number[];
}

export const GetNoticeList = () => {
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
Expand Up @@ -58,7 +58,9 @@ const CheckList: React.FC<State> = ({

const handleChange = (index: number, newState: string) => {
const newStatusList = [...statusList];
newStatusList[index] = newState;
for (let i = index; i < newStatusList.length; i++) {
newStatusList[index] = newState;
}
setStatusList(newStatusList);
};

Expand Down
12 changes: 2 additions & 10 deletions src/app/components/common/list/notice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ interface NoticeProp {
title: string;
teacher: string;
createAt: string;
grade: string;
id: string;
}

const NoticeList: React.FC<NoticeProp> = ({
title,
teacher,
createAt,
grade,
id,
}) => {
const NoticeList: React.FC<NoticeProp> = ({ title, teacher, createAt, id }) => {
const router = useRouter();

const MoveDetail = () => {
Expand All @@ -31,8 +24,7 @@ const NoticeList: React.FC<NoticeProp> = ({
<div className=" max-w-96 overflow-hidden whitespace-nowrap text-overflow-ellipsis">
{title}
</div>
<div className=" flex justify-between w-76">
<div>{grade}</div>
<div className=" flex gap-7">
<div>{teacher}</div>
<div>{createAt}</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/app/components/common/modal/schedule/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const PostSchedule: React.FC<ModalProps> = ({ onCancel, initialDate }) => {
event_name: scheduleData.event_name,
date: formattedDate,
};
setScheduleData(newScheduleData);
await addScheduleMutate(newScheduleData, {
onSuccess: () => {
location.reload();
Expand Down
4 changes: 2 additions & 2 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";
import { NextPage } from "next";
import { QueryClient } from "react-query";
import Input from "../components/common/input";
import Button from "../components/common/Button";
import Picklogo from "../../assets/img/Icon/pickname.svg";
Expand Down Expand Up @@ -28,6 +27,7 @@ const Login: NextPage = () => {
const handleChange = ({ text, name }: ChangeProps) => {
setData({ ...data, [name]: text });
};

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
onClickBtn();
Expand All @@ -39,7 +39,7 @@ const Login: NextPage = () => {

const onClickBtn = async () => {
try {
const result = await loginMutate(data, {
await loginMutate(data, {
onSuccess: (res) => {
const accessToken = res.access_token;
const refreshToken = res.refresh_token;
Expand Down
2 changes: 1 addition & 1 deletion src/app/main/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const Main = () => {
href="outList"
img={outStudent}
number={data?.out}
buttonChildren="외출 중인 학생 보기"
buttonChildren="외출/조기귀가 중인 학생 보기"
color="primary"
contentChildren="현재 외출중인 "
/>
Expand Down
11 changes: 1 addition & 10 deletions src/app/notice/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface DetailNoticeType {
content: string;
create_at: string;
teacher: string;
grade: number[];
}

const DetailNotice: NextPage = () => {
Expand All @@ -40,7 +39,7 @@ const DetailNotice: NextPage = () => {

const deleteNotice = async () => {
try {
const result = await delelteMutate(
await delelteMutate(
{ id: id },
{
onSuccess: () => {
Expand Down Expand Up @@ -87,14 +86,6 @@ const DetailNotice: NextPage = () => {
작성자
<div className=" text-neutral-400">{data?.teacher} 선생님</div>
</div>
<div className=" flex text-Button-L gap-2">
학년
<div className=" text-neutral-400">
{data?.grade.map((grade, index) => (
<span key={index}>{`${Grade([grade])}학년 `}</span>
))}
</div>
</div>
</div>
<div className=" flex flex-col gap-7">
<div className=" text-heading5 text-neutral-100">
Expand Down
35 changes: 5 additions & 30 deletions src/app/notice/modify/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ interface DetailNoticeType {
content: string;
create_at: string;
teacher: string;
grade: number[];
}

const ModifyNotice = () => {
const router = useRouter();
const [title, setTitle] = useState("");
const [content, setContent] = useState("");
const [selectedGrade, setSelectedGrade] = useState<number>(1);
const { mutate: DetailDataMutate } = DetailNoticeData();
const [data, setData] = useState<DetailNoticeType>();
const { mutate: modifyMutate } = ModifyNoticeData();

Expand All @@ -36,32 +34,14 @@ const ModifyNotice = () => {
const idParam = param.get("id");

const id = idParam ? idParam : "";
const { data: DetailDataMutate } = DetailNoticeData(id);

useEffect(() => {
getData();
setData(data);
setTitle(DetailDataMutate?.title || "");
setContent(DetailDataMutate?.content || "");
}, []);

const getData = async () => {
try {
const result = await DetailDataMutate(
{ id: id },
{
onSuccess: (data) => {
setData(data);
setTitle(data.title);
setContent(data.content);
setSelectedGrade(data.grade[0]);
},
onError: (error) => {
console.log(`${error.message} : 에러가 발생했습니다`);
},
}
);
} catch (error) {
console.log(error);
}
};

const handleTitleChange = ({ text, name }: ChangeProps) => {
setTitle(text);
};
Expand All @@ -76,11 +56,10 @@ const ModifyNotice = () => {

const handleSubmit = async () => {
try {
const result = await modifyMutate({
await modifyMutate({
id: id,
title: title,
content: content,
grade: [selectedGrade],
});
alert("공지가 수정되었습니다");
router.back();
Expand Down Expand Up @@ -116,10 +95,6 @@ const ModifyNotice = () => {
name="title"
/>
</div>
<div>
학년
<SelectGrade onSelect={handleGradeSelect} />
</div>
</div>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/app/notice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface GetnoticeList {
title: string;
create_at: string;
teacher: string;
grade: number[];
}

const Notice = () => {
Expand Down Expand Up @@ -46,7 +45,6 @@ const Notice = () => {
<div className=" flex text-sub-title2-M px-14 justify-between">
<div className=" text-sub-title2-M">제목</div>
<div className=" flex gap-20">
<div>학년</div>
<div>작성자</div>
<div>작성일</div>
</div>
Expand All @@ -59,7 +57,6 @@ const Notice = () => {
id={item.id}
createAt={item.create_at}
teacher={`${item.teacher} 선생님`}
grade={`${Grade(item.grade)}학년`}
/>
))}
</div>
Expand Down
9 changes: 2 additions & 7 deletions src/app/notice/write/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const WriteNotice = () => {
const { mutate: uploadNotice } = PostNotice();
const [title, setTitle] = useState("");
const [content, setContent] = useState("");
const [selectedGrade, setSelectedGrade] = useState<number>(1);

const ColorType = () => {
if (title === "" || content === "") {
Expand All @@ -30,8 +29,8 @@ const WriteNotice = () => {
const post = async () => {
if (ColorType() === "primary") {
try {
const result = await uploadNotice(
{ title, content, grade: [selectedGrade] },
await uploadNotice(
{ title, content },
{
onSuccess: () => {
nav.push("/notice");
Expand Down Expand Up @@ -83,10 +82,6 @@ const WriteNotice = () => {
name="title"
/>
</div>
<div>
학년
<SelectGrade onSelect={setSelectedGrade} />
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/selfStudyCheck/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SelfStudyCheck = () => {
const [saveModal, setSaveModal] = useState<boolean>(false);
const { mutate: ChangeMutate } = CheckStatus();
const { mutate: CheckMutate } = ClassStudentCheck();
const { selectedStudents, selectedStudentName, handleAcceptListClick } =
const { selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();

const handleSaveModalConfirm = async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/hook/apiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const ApiError = () => {
alert("400 잘못된 요청입니다");
};

const handle401: ErrorHandler = () => {
router.push("login");
};
const handle401: ErrorHandler = () => {};

const handle403: ErrorHandler = () => {
alert("403 권한이 없습니다");
Expand Down

0 comments on commit 8e5c84b

Please sign in to comment.