From f56279674ab5da3ff0ed4112d1d5cda6d091b122 Mon Sep 17 00:00:00 2001 From: qkdflrgs Date: Fri, 11 Aug 2023 03:02:19 +0900 Subject: [PATCH] =?UTF-8?q?feat/#150:=20=EB=A7=88=EC=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=86=A4=20=ED=8E=B8=EC=A7=91=20=EC=BB=B4=ED=8F=AC=EB=84=8C?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MilestoneList/EditMilestone.tsx | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 FE/src/components/MilestoneList/EditMilestone.tsx 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" ? "마일스톤 편집" : "새로운 마일스톤 추가"} + + + + + + + + + +