diff --git a/FE/src/App.tsx b/FE/src/App.tsx index 89087d7b5..815367fcf 100644 --- a/FE/src/App.tsx +++ b/FE/src/App.tsx @@ -24,7 +24,10 @@ function App() { }> }> }> - }> + } + > }> }> diff --git a/FE/src/components/MilestoneList/EditMilestone.tsx b/FE/src/components/MilestoneList/EditMilestone.tsx new file mode 100644 index 000000000..09b79364c --- /dev/null +++ b/FE/src/components/MilestoneList/EditMilestone.tsx @@ -0,0 +1,145 @@ +import { styled } from "styled-components"; +import LabelInput from "../common/TextInput/LabelInput"; +import Button from "../common/Button/Button"; + +type Props = { + id?: number; + type?: "edit" | "add"; + title: string; + description: string; + deadline: string; + onChangeTitle(e: React.ChangeEvent): void; + onChangeDescription(e: React.ChangeEvent): void; + onChangeDeadline(e: React.ChangeEvent): void; + cancelEdit(): void; + confirmEdit(): void; +}; + +export default function EditMilestone({ + id, + type = "edit", + title, + description, + deadline, + onChangeTitle, + onChangeDescription, + onChangeDeadline, + cancelEdit, + confirmEdit, +}: Props) { + const confirmEditMilestone = async () => { + const URL = `http://3.34.141.196/api/milestones/${id}`; + + const putData = { + title: title, + description: description, + deadline: deadline, + }; + + const headers = { + "Content-Type": "application/json", + }; + + try { + const response = await fetch(URL, { + method: "PUT", + headers: headers, + body: JSON.stringify(putData), + }); + + if (response.status === 204) { + confirmEdit(); + } else { + console.log("PUT 요청에 실패하였습니다. 상태 코드:", response.status); + } + } catch (error) { + console.error("API 호출 오류:", error); + } + }; + + return ( + + + {type === "edit" ? "마일스톤 편집" : "새로운 마일스톤 추가"} + + + + + + + + + +