-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from youmdang/React-염정훈-sprint6
[염정훈] Sprint6
- Loading branch information
Showing
22 changed files
with
602 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.env | ||
|
||
# testing | ||
/coverage | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
export async function getProducts({ pageSize, order }) { | ||
const query = `pageSize=${pageSize}&orderBy=${order}`; | ||
const response = await fetch( | ||
`https://panda-market-api.vercel.app/products?page=1&${query}` | ||
); | ||
export async function getProducts({ page, pageSize, order }) { | ||
const apiUrl = process.env.REACT_APP_API_URL; | ||
const query = `page=${page}&pageSize=${pageSize}&orderBy=${order}`; | ||
const response = await fetch(`${apiUrl}.vercel.app/products?${query}`); | ||
const body = await response.json(); | ||
return body; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
|
||
function AddItem() { | ||
const [formData, setFormDate] = useState({ | ||
name: "", | ||
info: "", | ||
price: "", | ||
tag: "", | ||
}); | ||
const [addItemBtn, setAddItemBtn] = useState(""); | ||
const [btnDisabled, setBtnDisabled] = useState(true); | ||
const [inputFileUrl, setInputFileUrl] = useState(null); | ||
const inputFileImg = useRef(null); | ||
const imgAccept = ".jpg, .jpeg, .png"; | ||
|
||
const inputChange = (e) => { | ||
// input value 상태 변경 | ||
const { name, value } = e.target; | ||
setFormDate({ | ||
...formData, | ||
[name]: value, | ||
}); | ||
}; | ||
|
||
const inputFileChange = () => { | ||
const inputFile = inputFileImg.current.files[0]; | ||
console.log(inputFile); | ||
|
||
if (inputFile) { | ||
const fileUrl = URL.createObjectURL(inputFile); | ||
setInputFileUrl(fileUrl); | ||
} | ||
}; | ||
|
||
const addImgDelete = () => { | ||
setInputFileUrl(null); | ||
}; | ||
|
||
const validAddItem = () => { | ||
// 유효성 검사 | ||
if ( | ||
formData.name !== "" && | ||
formData.info !== "" && | ||
formData.price !== "" && | ||
formData.tag !== "" | ||
) { | ||
setAddItemBtn("on"); | ||
setBtnDisabled(false); | ||
} else { | ||
setAddItemBtn(""); | ||
setBtnDisabled(true); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
// input 데이터 변경 될때마다 유효성 검사 실행 | ||
validAddItem(); | ||
}, [formData]); | ||
|
||
return ( | ||
<section className="add-item-wrap max-wrap"> | ||
<form method="post"> | ||
<div className="add-item-title"> | ||
<h2>상품 등록하기</h2> | ||
<button type="button" disabled={btnDisabled} className={addItemBtn}> | ||
등록 | ||
</button> | ||
</div> | ||
<div className="add-input"> | ||
<h3 className="add-input-title">상품 이미지</h3> | ||
<div className="add-img-list"> | ||
<label htmlFor="add-input-img" className="add-img-area"> | ||
<img src="/images/i-plus.png" alt="플러스 아이콘" /> | ||
이미지 등록 | ||
</label> | ||
<input | ||
id="add-input-img" | ||
type="file" | ||
ref={inputFileImg} | ||
accept={imgAccept} | ||
onChange={inputFileChange} | ||
/> | ||
{inputFileUrl ? ( | ||
<div className="add-img-item"> | ||
<img src={inputFileUrl} alt="상품 등록 이미지" /> | ||
<button type="button" onClick={addImgDelete}></button> | ||
</div> | ||
) : ( | ||
"" | ||
)} | ||
</div> | ||
</div> | ||
<div className="add-input"> | ||
<label htmlFor="add-input-name" className="add-input-title"> | ||
상풍명 | ||
</label> | ||
<input | ||
id="add-input-name" | ||
type="text" | ||
name="name" | ||
placeholder="상품명을 입력해주세요." | ||
value={formData.name} | ||
onChange={inputChange} | ||
/> | ||
</div> | ||
<div className="add-input"> | ||
<label htmlFor="add-input-info" className="add-input-title"> | ||
상품 소개 | ||
</label> | ||
<textarea | ||
id="add-input-info" | ||
name="info" | ||
placeholder="상품 소개를 입력해주세요." | ||
value={formData.info} | ||
onChange={inputChange} | ||
></textarea> | ||
</div> | ||
<div className="add-input"> | ||
<label htmlFor="add-input-price" className="add-input-title"> | ||
판매가격 | ||
</label> | ||
<input | ||
id="add-input-price" | ||
type="number" | ||
name="price" | ||
placeholder="판매 가격을 입력해주세요." | ||
value={formData.price === NaN ? null : formData.price} | ||
onChange={inputChange} | ||
/> | ||
</div> | ||
<div className="add-input"> | ||
<label htmlFor="add-input-tag" className="add-input-title"> | ||
태그 | ||
</label> | ||
<input | ||
id="add-input-tag" | ||
type="text" | ||
name="tag" | ||
placeholder="태그를 입력해주세요." | ||
value={formData.tag} | ||
onChange={inputChange} | ||
/> | ||
<ul className="tag-list"> | ||
<li> | ||
티셔츠 <button type="button"></button> | ||
</li> | ||
<li> | ||
상의 <button type="button"></button> | ||
</li> | ||
</ul> | ||
</div> | ||
</form> | ||
</section> | ||
); | ||
} | ||
|
||
export default AddItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.