diff --git a/react-springboot/book/book-frontend/src/pages/book/Detail.js b/react-springboot/book/book-frontend/src/pages/book/Detail.js index a17e9df8..1b391060 100644 --- a/react-springboot/book/book-frontend/src/pages/book/Detail.js +++ b/react-springboot/book/book-frontend/src/pages/book/Detail.js @@ -28,10 +28,16 @@ const Detail = (props) => { }); }; + const updateBook = () => { + props.history.push('/updateForm/' + id); + }; + return (

책 상세보기

- {' '} + {' '} diff --git a/react-springboot/book/book-frontend/src/pages/book/UpdateForm.js b/react-springboot/book/book-frontend/src/pages/book/UpdateForm.js index 393e90bf..aafcad55 100644 --- a/react-springboot/book/book-frontend/src/pages/book/UpdateForm.js +++ b/react-springboot/book/book-frontend/src/pages/book/UpdateForm.js @@ -1,12 +1,83 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; +import { Button, Form } from 'react-bootstrap'; + +const UpdateForm = (props) => { + const id = props.match.params.id; + const [book, setBook] = useState({ + title: '', + author: '', + }); + + useEffect(() => { + fetch('http://localhost:8080/book/' + id) + .then((res) => res.json()) + .then((res) => { + setBook(res); + }); + }, [id]); + + const changeValue = (e) => { + setBook({ + ...book, + [e.target.name]: e.target.value, + }); + }; + + const submitBook = (e) => { + e.preventDefault(); + fetch('http://localhost:8080/book/' + id, { + method: 'put', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + }, + body: JSON.stringify(book), + }) + .then((res) => { + return res.status === 200 ? res.json() : null; + }) + .then((res) => { + res !== null + ? props.history.push('/book/' + id) + : alert('책 수정 실패'); + }) + .catch((error) => { + console.log(error); + }); + }; -const UpdateForm = () => { return (
-

책 수정하기

+
+ + Title + + + + + + Author + + + + + +
); }; export default UpdateForm; -

책 수정하기

;