feat: NoticeEditPage, useNoticeEdit 훅 추가
This commit is contained in:
parent
761d348bf0
commit
a66db94341
15
frontend/src/hooks/api/useNoticeEdit.js
Normal file
15
frontend/src/hooks/api/useNoticeEdit.js
Normal file
@ -0,0 +1,15 @@
|
||||
import instance from '../../utils/axios/instance';
|
||||
import { API_URL } from '../../constants';
|
||||
|
||||
export function useNoticeEdit() {
|
||||
const noticeEdit = (boardId, title, content) => {
|
||||
const newNotice = {
|
||||
title,
|
||||
content,
|
||||
};
|
||||
console.log(newNotice);
|
||||
return instance.put(`${API_URL}/board/${boardId}`, newNotice);
|
||||
};
|
||||
|
||||
return { noticeEdit };
|
||||
}
|
32
frontend/src/pages/NoticeEditPage/NoticeEditPage.jsx
Normal file
32
frontend/src/pages/NoticeEditPage/NoticeEditPage.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import { EditArticle } from '../../components/Article';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useNoticeEdit } from '../../hooks/api/useNoticeEdit';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useNoticeDetail } from '../../hooks/api/useNoticeDetail';
|
||||
|
||||
export default function NoticeEditPage() {
|
||||
const navigate = useNavigate();
|
||||
const { noticeId } = useParams();
|
||||
const { noticeEdit } = useNoticeEdit();
|
||||
|
||||
const { data } = useNoticeDetail(noticeId);
|
||||
const notice = data?.data;
|
||||
|
||||
const handleSubmit = async (e, title, content) => {
|
||||
e.preventDefault();
|
||||
|
||||
await noticeEdit(noticeId, title, content);
|
||||
|
||||
navigate('..');
|
||||
};
|
||||
return (
|
||||
<EditArticle
|
||||
topic="글 쓰기"
|
||||
title="공지사항"
|
||||
prevTitle={notice.title}
|
||||
prevContent={notice.content}
|
||||
onSubmit={handleSubmit}
|
||||
isPut={true}
|
||||
/>
|
||||
);
|
||||
}
|
1
frontend/src/pages/NoticeEditPage/index.js
Normal file
1
frontend/src/pages/NoticeEditPage/index.js
Normal file
@ -0,0 +1 @@
|
||||
export { default } from './NoticeEditPage';
|
Loading…
Reference in New Issue
Block a user