diff --git a/src/pages/DiaryPage.js b/src/pages/DiaryPage.js index 518209d..bdfa880 100644 --- a/src/pages/DiaryPage.js +++ b/src/pages/DiaryPage.js @@ -58,7 +58,7 @@ const DiaryPage = () => { console.log(error); }); - navigate("/editdiary"); // {diaryid} 추가 + navigate("/editdiary", { state: { diaryInfo } }); }; diff --git a/src/pages/DiaryWritePage.js b/src/pages/DiaryWritePage.js index dadbee6..a896e9b 100644 --- a/src/pages/DiaryWritePage.js +++ b/src/pages/DiaryWritePage.js @@ -47,7 +47,7 @@ const DiaryWritePage = () => { formData.append("title", title); formData.append("content", content); formData.append("date", startDate.toISOString().split("T")[0]); - formData.append("travel", "664c257dac93cdbc69a66bf5"); // travelid 대체 + formData.append("travel", "664c3dc4300f7b0c6126c483"); // travelid 대체 files.forEach((file) => { formData.append("images", file.fileObject); diff --git a/src/pages/EditDiaryWritePage.js b/src/pages/EditDiaryWritePage.js index 42cfba7..8217d1d 100644 --- a/src/pages/EditDiaryWritePage.js +++ b/src/pages/EditDiaryWritePage.js @@ -12,15 +12,18 @@ import { useNavigate } from "react-router-dom"; import { useLocation } from "react-router"; const EditDiaryWritePage = () => { + const { state } = useLocation(); + const { diaryInfo } = state || {}; + + const [startDate, setStartDate] = useState(diaryInfo?.date ? new Date(diaryInfo.date) : null); + const [title, setTitle] = useState(diaryInfo?.title || ""); + const [content, setContent] = useState(diaryInfo?.content || ""); + const [files, setFiles] = useState(diaryInfo?.url || []); - const [startDate, setStartDate] = useState(); - const [title, setTitle] = useState(""); - const [content, setContent] = useState(""); const [isCancelModalOpen, setIsCancelModalOpen] = useState(false); // Cancel 버튼을 위한 모달 상태 const [isSaveModalOpen, setIsSaveModalOpen] = useState(false); // Save 버튼을 위한 모달 상태 const [imagePreview, setImagePreview] = useState(null); - const [files, setFiles] = useState([]); - const { state } = useLocation(); + // const [files, setFiles] = useState([]); // const [travelid, setTravelId] = useState(state); const [diaryId, setDiaryId] = useState({ diaryid: "" });