codestates / codestates/UptoDoor

[๐ŸŒช Error Handling] ๋ฐฐ์—ด[์ด๋ฏธ์ง€/์ธํ’‹์ž…๋ ฅ] ์ถ”๊ฐ€๊ธฐ๋Šฅ / 2021-09-25

Open
#196 0 comments 0 reactions 1 assignee Claimed by @22sook00 View on GitHub
Client complete error week3
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 ?
+
:

}

)}

```
![แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-09-27 แ„‹แ…ฉแ„’แ…ฎ 8 21 06](https://user-images.githubusercontent.com/80618616/134898888-aaf1e26d-26bd-451d-8975-00e76cd5285a.png)

**ํ•ด๊ฒฐ์ฝ”๋“œ**
```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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.