Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

공지사항 기능 구현 #32

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/Apis/NoticeApi.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/Apis/admin/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import instance from "../api";
import instance from "../axios";
import { LoginRequest } from "./type";

const router = "/admin";
Expand Down
31 changes: 0 additions & 31 deletions src/Apis/api.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/Apis/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import axios from "axios";
import { Cookie } from "../Utils/Cookie";

export const instance = axios.create({
baseURL: process.env.REACT_APP_BASE_URL,
timeout: 10000,
});

instance.interceptors.request.use(
(config) => {
const token = Cookie.get("access_token");
if (token) config.headers.Authorization = `bearer ${token}`;
return config;
},
(err) => {
alert("오류 발생");
return Promise.reject(err);
}
);

instance.interceptors.response.use(
(res) => {
return res;
},
(err) => {
console.log(err);
}
);

export default instance;
41 changes: 41 additions & 0 deletions src/Apis/notice/notice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import instance from "../axios";
import {
createCommentResponse,
createNoticeRequest,
getCommentResponse,
getNoticeDetailResponse,
getNoticeResponse,
updateNoticeRequest,
updateNoticeResponse,
} from "./type";

export const createNotice = async (data: createNoticeRequest) => {
return await instance.post("/admin/post_notification", data);
};

export const getNotice = async () => {
return await instance.get<getNoticeResponse[]>("/get_notification_all_admin");
};

export const getNoticeDetail = async (notificationId: number) => {
return await instance.get<getNoticeDetailResponse>(`/get_notification_detail?notification_id=${notificationId}`);
};

export const deleteNotice = async (notificationId: number) => {
return await instance.delete(`/admin/delete_notification?notification_id=${notificationId}`);
};

export const updateNotice = async (notificationId: number, data: updateNoticeRequest) => {
return await instance.put<updateNoticeResponse>(
`/admin/update_notification?notification_id=${notificationId}`,
data
);
};

export const createComment = async (notificationId: number, content: string) => {
return await instance.post<createCommentResponse>(`/admin/notifications/${notificationId}/comments`, content);
};

export const getComment = async (notificationId: number) => {
return await instance.get<getCommentResponse[]>(`/notifications/${notificationId}/comments`);
};
61 changes: 61 additions & 0 deletions src/Apis/notice/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export type createNoticeRequest = {
title: string;
content: string;
grade: string[];
class_num: string[];
};

export interface getNoticeResponse {
title: string;
date: string;
id: number;
major: string;
}

export interface getNoticeDetailResponse {
title: string;
content: string;
grade: string[];
class_num: string[];
id: number;
author_id: string;
author_name: string;
date: string;
}

export interface updateNoticeRequest {
title: string;
content: string;
grade: string[];
class_num: string[];
}

export interface updateNoticeResponse {
title: string;
content: string;
grade: string[];
class_num: string[];
id: number;
author_id: string;
author_name: string;
date: string;
}

export interface createCommentResponse {
id: number;
content: string;
date: string;
author_id: string;
notification_id: number;
author_type: string;
}

export interface getCommentResponse {
id: number;
content: string;
date: string;
author_id: string;
notification_id: number;
author_type: string;
author_name: string;
}
107 changes: 94 additions & 13 deletions src/Components/HomeWork/CheckClass.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,137 @@
import styled from "styled-components";
import Check from "../../Assets/Check.svg";
import React, { useState } from "react";

interface CheckClassProps {
onChangeGrade: (grades: string[]) => void;
onChangeClassNum: (classNums: string[]) => void;
initialGrade?: string[];
initialClassNum?: string[];
}

export const CheckClass: React.FC<CheckClassProps> = ({
onChangeClassNum,
onChangeGrade,
initialClassNum = [],
initialGrade = [],
}) => {
const [selectedClass, setSelectedClass] = useState<{ grade: string; classNum: string }[]>([]);

const handleClassChange = (grade: string, classNum: string) => {
const isSelected = selectedClass.some((selected) => selected.grade === grade && selected.classNum === classNum);

let updatedClasses;
if (isSelected) {
updatedClasses = selectedClass.filter(
(selected) => !(selected.grade === grade && selected.classNum === classNum)
);
} else {
updatedClasses = [...selectedClass, { grade, classNum }];
}

setSelectedClass(updatedClasses);

onChangeGrade(updatedClasses.map((item) => item.grade));
onChangeClassNum(updatedClasses.map((item) => item.classNum));
};

export const CheckClass = () => {
return (
<Wrapper>
<p>대상 반 선택</p>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "1" && selected.classNum === "1")}
onChange={() => handleClassChange("1", "1")}
/>
<p>1학년 1반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "1" && selected.classNum === "2")}
onChange={() => handleClassChange("1", "2")}
/>
<p>1학년 2반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "1" && selected.classNum === "3")}
onChange={() => handleClassChange("1", "3")}
/>
<p>1학년 3반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "1" && selected.classNum === "4")}
onChange={() => handleClassChange("1", "4")}
/>
<p>1학년 4반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "2" && selected.classNum === "1")}
onChange={() => handleClassChange("2", "1")}
/>
<p>2학년 1반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "2" && selected.classNum === "2")}
onChange={() => handleClassChange("2", "2")}
/>
<p>2학년 2반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "2" && selected.classNum === "3")}
onChange={() => handleClassChange("2", "3")}
/>
<p>2학년 3반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "2" && selected.classNum === "4")}
onChange={() => handleClassChange("2", "4")}
/>
<p>2학년 4반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "3" && selected.classNum === "1")}
onChange={() => handleClassChange("3", "1")}
/>
<p>3학년 1반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "3" && selected.classNum === "2")}
onChange={() => handleClassChange("3", "2")}
/>
<p>3학년 2반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "3" && selected.classNum === "3")}
onChange={() => handleClassChange("3", "3")}
/>
<p>3학년 3반</p>
</CheckBoxWrapper>
<CheckBoxWrapper>
<CheckBox type="checkbox" />
<CheckBox
type="checkbox"
checked={selectedClass.some((selected) => selected.grade === "3" && selected.classNum === "4")}
onChange={() => handleClassChange("3", "4")}
/>
<p>3학년 4반</p>
</CheckBoxWrapper>
</Wrapper>
Expand Down
1 change: 1 addition & 0 deletions src/Components/HomeWork/CompleteHomeWork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Wrapper = styled.div`
gap: 28px;
display: flex;
flex-direction: column;
margin-bottom: 20px;
`;

const TextWrapper = styled.div`
Expand Down
Loading