feat: NoticeEditPage, useNoticeEdit 훅 추가

This commit is contained in:
정기영 2024-07-29 13:54:25 +09:00
parent 761d348bf0
commit a66db94341
3 changed files with 48 additions and 0 deletions

View 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 };
}

View 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}
/>
);
}

View File

@ -0,0 +1 @@
export { default } from './NoticeEditPage';