diff --git a/src/components/RegisterEditor/index.tsx b/src/components/RegisterEditor/index.tsx index b5668d3..fafa17f 100644 --- a/src/components/RegisterEditor/index.tsx +++ b/src/components/RegisterEditor/index.tsx @@ -74,11 +74,10 @@ const RegisterEditor = () => { if (!dataValidCheck(newEditor)) return; if (confirm("해당 필진을 등록하시겠습니까?")) { - if (!imageFile) return; const newEditorString = JSON.stringify(newEditor); const formData = new FormData(); - formData.append("file", imageFile); + imageFile !== null && formData.append("file", imageFile); formData.append( "data", new Blob([newEditorString], { type: "application/json" }) diff --git a/src/components/UpdateEditor/index.tsx b/src/components/UpdateEditor/index.tsx index f6e08ea..68d1528 100644 --- a/src/components/UpdateEditor/index.tsx +++ b/src/components/UpdateEditor/index.tsx @@ -26,7 +26,7 @@ const UpdateEditor = () => { EditorAPI.getEditorAll().then((data) => { setEditors(data); }); - }, [isDeleted]); + }, [isDeleted, editor]); const handleChangedFile = (e: React.ChangeEvent) => { const reader = new FileReader(); @@ -89,6 +89,7 @@ const UpdateEditor = () => { editorNameInputRef.current == null ) return; + editor ? console.log(editor.id) : console.log(""); const newEditor: Editor = { id: editor?.id, name: editorNameInputRef.current.value, @@ -98,29 +99,33 @@ const UpdateEditor = () => { if (!dataValidCheck(newEditor)) return; if (confirm("해당 필진을 수정하시겠습니까?")) { - if (!imageFile) return; const newEditorString = JSON.stringify(newEditor); const formData = new FormData(); - formData.append("file", imageFile); + imageFile !== null && formData.append("file", imageFile); formData.append( "data", new Blob([newEditorString], { type: "application/json" }) ); - console.log(formData); await EditorAPI.updateEditor(formData); + setEditor(newEditor); + await EditorAPI.getEditorAll().then((data) => { + setEditors(data); + }); } }; const showEditor = async (id: number) => { await EditorAPI.getEditor(id).then((res) => { - console.log(res); - const currentEditor: Editor = { - id: res.id, - name: res.name, - introduction: res.introduction, - file: res.imgUrl, - }; - setEditor(currentEditor); + setEditor(res); + if ( + fileInputRef.current == null || + editorIntroTextareaRef.current == null || + editorNameInputRef.current == null + ) + return; + setImageURL(res.imgUrl); + editorNameInputRef.current.value = res.name; + editorIntroTextareaRef.current.value = res.introduction; }); }; @@ -176,7 +181,7 @@ const UpdateEditor = () => {
- +

{