This commit is contained in:
46
src/pages/PostCreate.js
Normal file
46
src/pages/PostCreate.js
Normal file
@ -0,0 +1,46 @@
|
||||
import React, { useState } from 'react';
|
||||
import blogApi from '../api/blogApi';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
const PostCreate = () => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [content, setContent] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await blogApi.post('/api/blog/create/', { title, content });
|
||||
alert('게시글이 등록되었습니다.');
|
||||
navigate('/posts');
|
||||
} catch (err) {
|
||||
alert('등록 실패: ' + (err.response?.data?.detail || err.message));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl mx-auto p-8">
|
||||
<h1 className="text-2xl font-bold mb-4">게시글 작성</h1>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="제목"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
className="w-full px-4 py-2 mb-4 border rounded"
|
||||
/>
|
||||
<textarea
|
||||
placeholder="내용"
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
className="w-full px-4 py-2 mb-4 border rounded min-h-[150px]"
|
||||
/>
|
||||
<button
|
||||
onClick={handleSubmit}
|
||||
className="bg-[#3B82F6] text-white px-6 py-2 rounded hover:bg-blue-700"
|
||||
>
|
||||
작성 완료
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PostCreate;
|
Reference in New Issue
Block a user