codestates / codestates/UptoDoor
[๐ช Error Handling] ๋ฐฐ์ด[์ด๋ฏธ์ง/์ธํ์ ๋ ฅ] ์ถ๊ฐ๊ธฐ๋ฅ / 2021-09-25
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
### ์ด๋ค ์๋ฌ์ธ๊ฐ์?
- ์ด๋ฏธ์ง/์ธํ ๊ธฐ๋ฅ์๋ ๋ฉ๋ด๋ฐฐ์ด ์ถ๊ฐ ์ ์ด๋ฏธ์ง์ ์ธํ์ ํ
์คํธ๋ค์ด ์ถ๊ฐ๋ ๋์ง๋ง ์ฌ์ง์์ ์์
์
- ์ด๋ฏธ์ง์
๋ก๋๋ Dropzone ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ.
- ์ ์ฒด ๋ฉ๋ด ์์ ๋ฐ ์ญ์ ๊ธฐ๋ฅ ์ id ๊ฐ์ ์ถ์ถํ์ฌ ์ผ์นํ๋ id ๋ฅผ ์ฐพ์์ผํ๋๋ฐ Dropzone ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ฐพ์๋ด๋๊ฒ์ด ์ด๋ ค์ ์.
### ์๋ฌ ๋ฉ์์ง
### ์๋ฌ ํธ๋ค๋ง ๋ฐฉ๋ฒ
- Dropzone ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ฌ์ฉํ์ง ์๊ธฐ๋ก ๊ฒฐ์ .
```js
๊ธฐ์กด์๋ฌ์ฝ๋
const changeMenuName = (e:any) => {
setMenuName(e.target.value)
const lastIdx = menuArr.length-1;
const copyArr = menuArr.slice()
copyArr[lastIdx].menuName = e.target.value
setMenuArr(copyArr);
}
const dropHandler = (file:any) => {
const formData = new FormData();
const config = {
headers: { 'content-type' : 'multipart/form-data'}
}
formData.append('file',file[0]);
//dispatch action axios ๊ด๋ฆฌ๋๊ฑฐ ์์ผํจ.
axios.post(`${END_POINTS}/image`,formData,config)
.then((res)=>{
if(res.data.success){
const copyArr = menuArr.slice()
const lastIdx = copyArr.length-1;
copyArr[lastIdx].menuImg = res.data.filePath
console.log("copyImg๋ง๋ค์ด๊ฐ๋ ๋ฐฐ์ด",copyArr)
setMenuImg(res.data.filePath)
}else{
alert('ํ์ผ์ ์ฅ์คํจ')
}
})
.catch((err)=>{
return console.log('==file ๊ฐ์ ธ์ค๊ธฐ ์คํจ===',err)
})
}
{({getRootProps, getInputProps}) => (
{el.menuImg.length === 0 ?
+
:
}
)}
```

**ํด๊ฒฐ์ฝ๋**
```js
const dropHandler = (e:any) => {
const file = e.target.files
const formData = new FormData();
const config = {
headers: { 'content-type' : 'multipart/form-data'}
}
formData.append('file',file[0]);
//dispatch action axios ๊ด๋ฆฌ๋๊ฑฐ ์์ผํจ.
axios.post(`${END_POINTS}/image`,formData,config)
.then((res)=>{
if(res.data.success){
const copyArr = JSON.parse(JSON.stringify(menuArr));
// console.log('copyArr===',copyArr)
// console.log('copyArr target===',copyArr[e.target.id])
copyArr[e.target.id].menuImg = res.data.filePath
setMenuArr(copyArr)
setMenuImg(res.data.filePath)
}else{
alert('ํ์ผ์ ์ฅ์คํจ')
}
})
.catch((err)=>{
return console.log('==file ๊ฐ์ ธ์ค๊ธฐ ์คํจ===',err)
})
}
// FileUp ์ ๋ฉ๋ดํด๋ฆญํ ์ ์๋ + ๋ถ๋ถ / MenuImg ๋ฉ๋ด์ ๋ก๋ ์ ๋ํ๋๋ ์ด๋ฏธ์ง
๋ฉ๋ด ์ด๋ฏธ์ง
{checkHandler(e)}}
/>
{uploadHandler(e)}}
id={idx}
src = {el.menuImg}
alt = {el.menuImg}/>
```
๊ธฐ์กด์ ์๋ณธ๋ฐฐ์ด์ด ๋ณ๊ฒฝ๋์ง์๋ ์์๋ณต์ฌ์ธ slice ๋ฅผ ์ฌ์ฉํ ํ menuArr ์ ์ ์ฉ์ํค๊ฒ๊ณผ ๋ฌ๋ฆฌ,
๊น์๋ณต์ฌ ๋ฐฉ์์ ์ด์ฉํ๊ณ ์ด๋ฒคํธ๊ฐ ๋ฐ์๋ ๋๋ง๋ค ์๊ธฐ๋ id ๊ฐ์ ์ธ๋ฑ์ค๋ก ๋ฃ์ด ์ ์ฉ์์ผฐ๋ค.
dropzone ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ๋๋ก ๊ณต๋ถํ๊ณ ์ฌ์ฉํ์ง ์์์ ์ด๋ค ์๋ฆฌ๋ก ์๋ํ๋์ง ์ ๋๋ก ์์ง ๋ชปํ ์ฑ ํธํ ๊ฒ ๊ฐ์ "๊ทธ๋ฅ" ์ฌ์ฉํ๊ฒ ํ๊ทผ์ด์๋ค.
์ค๋ฅ๊ฐ ํฐ์ง ํ ๋ค๋ฆ๊ฒ ๊ณต์๋ฌธ์๋ฅผ ์ฐพ์๋ณด๊ฑฐ๋ ๊ตฌ๊ธ๋ง์ ํ์ฌ ํด๊ฒฐํ๋ คํ์ผ๋ ์ํ๋ ์ ๋ณด๋ฅผ ์ป์ ์ ์์ด ๊ฒฐ๊ตญ์ ์ฌ์ฉํ์ง ์๊ฒ ๋์๋ค.
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ์ ๊ผญ๊ผญ ์ ํํ๊ฒ ๊ณต๋ถํ๊ณ ์ ์ฉํด์ผ๊ฒ ๋ค.
### ์๋ฌ ํธ๋ค๋ง์ ์ํด ์ฐธ๊ณ ํ ๋ ํผ๋ฐ์ค ๋งํฌ
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.