-
Notifications
You must be signed in to change notification settings - Fork 39
[김진선] refactor/sprint6 #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
addiescode-sj
merged 13 commits into
codeit-bootcamp-frontend:React-김진선
from
jinsunkimdev:React-김진선-refactor/sprint6
Jul 2, 2025
The head ref may contain hidden characters: "React-\uAE40\uC9C4\uC120-refactor/sprint6"
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9f0a3af
refactor: normalize folder casing
jinsunkimdev 914477a
feat: 상품 등록 폼 기본 기능 구현
jinsunkimdev 89f32f1
feat: 상품 등록 폼 UI 및 입력 검증 로직 추가
jinsunkimdev 07f5161
fix: 이미지 등록 중복 시 에러 메시지 출력 및 input 리셋 처리
jinsunkimdev b866e8a
리액트 ref사용한 제어 컴포넌트 폼
jinsunkimdev be318b3
비제어로 폼 만들어 보기
jinsunkimdev 6adb3b2
Merge branch 'React-김진선' into React-김진선-sprint6
jinsunkimdev e0287f3
제어+비제어로 폼 작성
jinsunkimdev 9d3a9b6
제어+비제어로 폼 기능 완성
jinsunkimdev baa3784
useForm 파일 가독성을 위해 수정
jinsunkimdev 1e6f39b
netlify빌드 에러 해결
jinsunkimdev 5c3f930
feat: 리뷰 내용 반영 및 수정
jinsunkimdev 58a7cb5
chore: 주석 수정
jinsunkimdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
...ems/components/AllProducts/AllProducts.js → ...ms/components/all-products/AllProducts.js
This file contains hidden or 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...s/components/BestProducts/BestProducts.js → .../components/best-products/BestProducts.js
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...mponents/ProductSection/ProductSection.js → ...ponents/product-section/ProductSection.js
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,136 @@ | ||
| import styles from "./Additem.module.css"; | ||
| import { useForm } from "./hooks/useForm"; | ||
| import ImageUpload from "./components/ImageUpload"; | ||
| import TextInputField from "./components/TextInputField"; | ||
| import TagInput from "./components/TagInput"; | ||
| import { useValidation } from "./hooks/useValidation"; | ||
| import { formatWithCommas } from "./utils/formatUtils"; | ||
|
|
||
| export default function Additem() { | ||
| console.count('rendering') | ||
| const { validations } = useValidation(); | ||
| const { | ||
| errors, | ||
| handleChange, | ||
| handleBlur, | ||
| handleSubmit, | ||
| getFieldValue, | ||
| setFieldValue, | ||
| } = useForm({ | ||
| initialValues: { | ||
| productName: "", | ||
| productDescription: "", | ||
| productPrice: "", | ||
| productTag: [], | ||
| uploadImage: null, | ||
| }, | ||
| validations, | ||
| onSubmit: (formData) => { | ||
| // 콤마 제거 + 숫자형으로 변환 | ||
| const numericPrice = Number(formData.productPrice.replace(/,/g, "")); | ||
| const payload = { | ||
| ...formData, | ||
| productPrice: numericPrice, | ||
| }; | ||
| console.log("제출 데이터:", payload); | ||
| }, | ||
| }); | ||
|
|
||
| // 필수 필드만 모두 채워졌는지 확인 | ||
| const isSubmitEnabled = | ||
| getFieldValue("productName").trim() !== "" && | ||
| getFieldValue("productDescription").trim() !== "" && | ||
| getFieldValue("productPrice").trim() !== "" && | ||
| Array.isArray(getFieldValue("productTag")) && | ||
| getFieldValue("productTag").length > 0; | ||
|
|
||
| return ( | ||
| <form className={styles.form} onSubmit={handleSubmit}> | ||
| <header className={styles.header}> | ||
| <h1 className={styles.title}>상품 등록하기</h1> | ||
| <button | ||
| type="submit" | ||
| className={styles.submitButton} | ||
| disabled={!isSubmitEnabled} | ||
| > | ||
| 등록 | ||
| </button> | ||
| </header> | ||
| <div className={styles.inputContainer}> | ||
| <ImageUpload | ||
| onImageChange={(file) => { | ||
| handleChange( | ||
| "uploadImage", | ||
| () => file | ||
| )({ target: { value: file } }); | ||
| }} | ||
| previewUrl={ | ||
| getFieldValue("uploadImage") && | ||
| URL.createObjectURL(getFieldValue("uploadImage")) | ||
| } | ||
| /> | ||
| {<p className={styles.errorText}>{errors.uploadImage || "\u00A0"}</p>} | ||
|
|
||
| <TextInputField | ||
| label="상품명" | ||
| name="productName" | ||
| onChange={handleChange("productName")} | ||
| onBlur={handleBlur("productName")} | ||
| placeholder="상품명을 입력해주세요" | ||
| error={errors.productName} | ||
| wrapperClass={styles.inputWrapper} | ||
| inputClass={styles.input} | ||
| errorClass={styles.errorText} | ||
| /> | ||
|
|
||
| <TextInputField | ||
| as="textarea" | ||
| label="상품 소개" | ||
| name="productDescription" | ||
| onChange={handleChange("productDescription")} | ||
| onBlur={handleBlur("productDescription")} | ||
| placeholder="상품 소개를 입력해주세요" | ||
| error={errors.productDescription} | ||
| wrapperClass={styles.inputWrapper} | ||
| textAreaClass={styles.textArea} | ||
| errorClass={styles.errorText} | ||
| /> | ||
|
|
||
| <TextInputField | ||
| label="상품 가격" | ||
| name="productPrice" | ||
| onChange={handleChange("productPrice")} | ||
| onBlur={handleBlur("productPrice", formatWithCommas)} | ||
| placeholder="숫자만 입력해주세요" | ||
| error={errors.productPrice} | ||
| wrapperClass={styles.inputWrapper} | ||
| inputClass={styles.input} | ||
| errorClass={styles.errorText} | ||
| /> | ||
|
|
||
| <TagInput | ||
| name="productTag" | ||
| label="태그" | ||
| tags={getFieldValue("productTag")} | ||
| // 태그 배열이 바뀔 때만 호출될 “상태 업데이트” 함수 | ||
| setTags={(newTags) => { | ||
| setFieldValue("productTag", newTags); | ||
| }} | ||
| onChange={handleChange("productTag")} | ||
| onBlur={() => | ||
| handleBlur("productTag")({ | ||
| target: { value: getFieldValue("productTag") }, | ||
| }) | ||
| } | ||
| error={errors.productTag} | ||
| wrapperClass={styles.inputWrapper} | ||
| inputClass={styles.input} | ||
| errorClass={styles.errorText} | ||
| tagContainerClass={styles.tagsContainer} | ||
| tagClass={styles.tag} | ||
| removeButtonClass={styles.removeTagButton} | ||
| /> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
This file contains hidden or 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,99 @@ | ||
| .form { | ||
| display: flex; | ||
| flex-direction: column; | ||
| color: var(--color-gray-800); | ||
| } | ||
|
|
||
| .title { | ||
| font-size: var(--font-size-md-lg); | ||
| font-weight: var(--font-weight-bold); | ||
| vertical-align: middle; | ||
| padding-bottom: 24px; | ||
| } | ||
|
|
||
| .header { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .inputContainer { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 24px; | ||
| } | ||
|
|
||
| .inputWrapper { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| } | ||
|
|
||
| .submitButton { | ||
| background-color: #3692ff; | ||
| color: white; | ||
| padding: var(--form-submit-button); | ||
| border: none; | ||
| border-radius: 8px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .submitButton:disabled { | ||
| background-color: #ccc; | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| .input{ | ||
| border: none; | ||
| border-radius: 12px; | ||
| color: #1F2937; | ||
| font-size: 16px; | ||
| font-weight: 400; | ||
| background-color: #F3F4F6; | ||
| height: 56px; | ||
| padding: 16px 24px; | ||
| } | ||
|
|
||
| .textArea{ | ||
| resize: none; | ||
| border: none; | ||
| border-radius: 12px; | ||
| color: #1F2937; | ||
| font-size: 16px; | ||
| font-weight: 400; | ||
| background-color: #F3F4F6; | ||
| height: var(--text-area-height); | ||
| padding: 16px 24px; | ||
| } | ||
|
|
||
| .errorText { | ||
| color: red; | ||
| font-size: 14px; | ||
| margin-top: 4px; | ||
| } | ||
|
|
||
| .tagsContainer { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .tag { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| padding: 6px 12px; | ||
| background-color: #F3F4F6; | ||
| border-radius: 26px; | ||
| margin-right: 8px; | ||
| margin-bottom: 8px; | ||
| font-size: 16px; | ||
| font-weight: 400; | ||
| } | ||
|
|
||
| .removeTagButton { | ||
| margin-left: 8px; | ||
| background: transparent; | ||
| border: none; | ||
| cursor: pointer; | ||
| font-weight: bold; | ||
| } |
This file contains hidden or 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,73 @@ | ||
| import { useRef, useState } from "react"; | ||
| import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
| import { faPlus, faTimesCircle } from "@fortawesome/free-solid-svg-icons"; | ||
| import styles from "./ImageUpload.module.css" | ||
|
|
||
| export default function ImageUpload({ onImageChange }) { | ||
| const uploadImgRef = useRef(); | ||
| const [previewUrl, setPreviewUrl] = useState(""); // 프리뷰 이미지 URL | ||
|
|
||
| // 이미지 등록 버튼을 누르면 숨겨져 있는 실제 file타입 input태그 클릭함 | ||
| const handleUpload = () => { | ||
| if (uploadImgRef.current) { | ||
| uploadImgRef.current.value = ""; // ← 같은 파일도 다시 선택 가능하게 | ||
| uploadImgRef.current.click(); | ||
| } | ||
| }; | ||
| // URL.createObjectURL(file)로 임시 URL 생성해서 프리뷰 띄우는 함수 | ||
| const handleFileChange = () => { | ||
| const file = uploadImgRef.current?.files?.[0]; | ||
| if (file) { | ||
| const url = URL.createObjectURL(file); | ||
| setPreviewUrl(url); | ||
| onImageChange(file, url); // 부모에게 전달 | ||
| } | ||
| }; | ||
| // 프리뷰 이미지 닫기 함수 | ||
| const handleRemovePreviewButton = ()=>{ | ||
| setPreviewUrl(null); | ||
| if (uploadImgRef.current) { | ||
| uploadImgRef.current.value = ""; | ||
| } | ||
| onImageChange(null, null); // 삭제 알림 | ||
| } | ||
|
|
||
| return ( | ||
| <div className={styles.inputWrapper}> | ||
| <h3>상품 이미지</h3> | ||
| {/* 안 보이게 숨겨져 있음 */} | ||
| <input | ||
| type="file" | ||
| accept="image/*" | ||
| ref={uploadImgRef} | ||
| name="imageUpload" | ||
| style={{ display: "none" }} | ||
| onChange={handleFileChange} | ||
| /> | ||
| {/* 실제로 보이는 부분 */} | ||
| <div className={styles.imageWrapper}> | ||
| <div className={styles.imageUploadBox} onClick={handleUpload}> | ||
| <FontAwesomeIcon icon={faPlus} className={styles.plus} /> | ||
| <div>이미지 등록</div> | ||
| </div> | ||
| {/* preview 이미지 */} | ||
| {previewUrl && ( | ||
| <div className={styles.imagePreviewWrapper}> | ||
| <img | ||
| src={previewUrl} | ||
| alt="미리보기" | ||
| className={styles.imagePreview} | ||
| /> | ||
| <div | ||
| type="button" | ||
| onClick={handleRemovePreviewButton} | ||
| className={styles.removeImageButton} | ||
| > | ||
| <FontAwesomeIcon icon={faTimesCircle} /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 입력 필드가 하나의 부모 컴포넌트 안에 직접 렌더링됨