From 4a4b319c92accef46817249bab6705ef4a9cf5dd Mon Sep 17 00:00:00 2001 From: Chaeyoung Shin Date: Tue, 10 Dec 2024 00:10:37 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=AA=A8?= =?UTF-8?q?=EB=8B=AC=20=EC=9C=A0=EC=A0=80=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EB=A1=9C=EC=BB=AC=20=EC=8A=A4=ED=86=A0=EB=A6=AC=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CalendarInfoModal.jsx | 75 ++++++++++++++++++++++------ src/components/CreateEventModal.jsx | 2 +- src/components/EventInfo.jsx | 6 +-- src/styles/calendar.css | 3 ++ 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/src/components/CalendarInfoModal.jsx b/src/components/CalendarInfoModal.jsx index ea56b56..6658640 100644 --- a/src/components/CalendarInfoModal.jsx +++ b/src/components/CalendarInfoModal.jsx @@ -16,7 +16,6 @@ import { export default function CalendarInfo({ calendar, onClose, userId }) { const user_id = localStorage.getItem("user_id"); - console.log(user_id); const [calendarState, setCalendarState] = useState({ name: calendar.name, description: calendar.description, @@ -28,9 +27,7 @@ export default function CalendarInfo({ calendar, onClose, userId }) { }); const [isDeleteModalOpen, setDeleteModalOpen] = useState(false); const [isEdit, setIsEdit] = useState(false); - // 상태 변경 핸들러 - console.log("---"); - console.log(calendar); + // 상태 변경 핸들러; const updateState = (key, value) => { setCalendarState((prev) => ({ ...prev, @@ -38,6 +35,39 @@ export default function CalendarInfo({ calendar, onClose, userId }) { })); }; + const save = async () => { + try { + const token = localStorage.getItem("token"); // 토큰 가져오기 + console.log(calendarState); + const response = await instance.patch( + `/api/calendars/${calendar.calendar_id}/`, + { + name: calendarState.name, + description: calendarState.description, + is_public: calendarState.isPublic, + color: calendarState.color, + creator: calendarState.creator, + invitation_code: calendarState.invitation_code, + }, + + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }, + ); + + if (response.status === 200) { + // 상태 업데이트 및 편집 종료 + resetState(); + onClose(); + } + } catch (error) { + console.error("캘린더 수정 실패:", error); + alert("캘린더 수정에 실패했습니다. 다시 시도해 주세요."); + } + }; const resetState = () => { setCalendarState({ name: calendar.name, @@ -213,18 +243,35 @@ export default function CalendarInfo({ calendar, onClose, userId }) { )} -
- setIsEdit(true)} - /> - {calendar.creator_id == user_id && ( - + + +
+ ) : ( +
+ setDeleteModalOpen(true)} + onClick={() => setIsEdit(true)} /> - )} -
+ {calendar.creator_id == user_id && ( + + )} + + )} )} diff --git a/src/components/CreateEventModal.jsx b/src/components/CreateEventModal.jsx index 0dddaa3..94d5ff4 100644 --- a/src/components/CreateEventModal.jsx +++ b/src/components/CreateEventModal.jsx @@ -196,7 +196,7 @@ export default function CreateEvent({ onClose, setEvents }) { className="absolute right-[1.2rem] top-[1.2rem] cursor-pointer text-darkGray" onClick={onClose} /> -
+
{/* 이벤트 제목 */} { @@ -430,9 +431,8 @@ export default function EventInfo({ onClose, eventDetails, setEvents }) {
handleViewChange("edit")} /> {calInfo.members && - calInfo.members.find( - (cal) => cal === userInfo.user_nickname, - ) !== undefined && ( + calInfo.members.find((cal) => cal === user_nickname) !== + undefined && (