-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
101 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/components/items/registration/productDescriptionInput.tsx
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,31 @@ | ||
import cn from '@/lib/cn'; | ||
import { ProductInputProps } from './types'; | ||
|
||
export default function ProductDescriptionInput({ | ||
register, | ||
errors, | ||
}: ProductInputProps) { | ||
return ( | ||
<div className='input-section'> | ||
<label className='input-label'>상품 소개</label> | ||
<textarea | ||
className={cn('input-base', errors.description && 'error-input')} | ||
placeholder='상품 소개를 입력해주세요' | ||
{...register('description', { | ||
required: '상품 소개를 입력해주세요', | ||
minLength: { | ||
value: 10, | ||
message: '10자 이상 입력해주세요', | ||
}, | ||
maxLength: { | ||
value: 100, | ||
message: '100자 이하로 입력해주세요', | ||
}, | ||
})} | ||
/> | ||
{errors.description && ( | ||
<span className='error-message'>{errors.description.message}</span> | ||
)} | ||
</div> | ||
); | ||
} |
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,27 @@ | ||
import cn from '@/lib/cn'; | ||
import { ProductInputProps } from './types'; | ||
|
||
export default function ProductNameInput({ | ||
register, | ||
errors, | ||
}: ProductInputProps) { | ||
return ( | ||
<div className='input-section'> | ||
<label className='input-label'>상품명</label> | ||
<input | ||
className={cn('input-base', errors.name && 'error-input')} | ||
placeholder='상품명을 입력해주세요' | ||
{...register('name', { | ||
required: '상품명을 입력해주세요', | ||
maxLength: { | ||
value: 10, | ||
message: '10자 이내로 입력해주세요', | ||
}, | ||
})} | ||
/> | ||
{errors.name && ( | ||
<span className='error-message'>{errors.name.message}</span> | ||
)} | ||
</div> | ||
); | ||
} |
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,31 @@ | ||
import cn from '@/lib/cn'; | ||
import { ProductInputProps } from './types'; | ||
|
||
export default function ProductPriceInput({ | ||
register, | ||
errors, | ||
}: ProductInputProps) { | ||
return ( | ||
<div className='input-section'> | ||
<label className='input-label'>판매가격</label> | ||
<input | ||
type='number' | ||
className={cn('input-base', errors.price && 'error-input')} | ||
placeholder='판매 가격을 입력해주세요' | ||
{...register('price', { | ||
valueAsNumber: true, | ||
validate: { | ||
isNumber: (value) => !Number.isNaN(value) || '숫자로 입력해주세요', | ||
isInteger: (value) => | ||
(Number.isInteger(value) && value >= 0) || | ||
'양의 정수를 입력해주세요', | ||
}, | ||
required: '판매 가격을 입력해주세요', | ||
})} | ||
/> | ||
{errors.price && ( | ||
<span className='error-message'>{errors.price.message}</span> | ||
)} | ||
</div> | ||
); | ||
} |
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,23 @@ | ||
import cn from '@/lib/cn'; | ||
import { ProductTagInputProps } from './types'; | ||
|
||
export default function ProductTagInput({ | ||
tagInput, | ||
handleAddTag, | ||
setTagInput, | ||
tagError, | ||
}: ProductTagInputProps) { | ||
return ( | ||
<div className='input-section'> | ||
<label className='input-label'>태그</label> | ||
<input | ||
value={tagInput} | ||
onChange={(e) => setTagInput(e.target.value)} | ||
onKeyDown={handleAddTag} | ||
placeholder='태그를 입력해주세요.' | ||
className={cn('input-base', tagError.length && 'error-input')} | ||
/> | ||
{tagError && <span className='error-message'>{tagError}</span>} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { faX } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { TagsContainerProps } from './types'; | ||
|
||
export default function TagsContainer({ | ||
tags, | ||
handleRemoveTag, | ||
}: TagsContainerProps) { | ||
return ( | ||
<div className='flex gap-3'> | ||
{tags.map((tag, index) => ( | ||
<span | ||
className='bg-bg-tag flex items-center justify-between px-3 py-[6px] rounded-[26px] gap-2' | ||
key={tag} | ||
> | ||
#{tag} | ||
<button | ||
type='button' | ||
className='w-5 h-5 bg-bg-close-button rounded-full flex items-center justify-center text-text-white-secondary' | ||
onClick={() => handleRemoveTag(index)} | ||
> | ||
<FontAwesomeIcon | ||
icon={faX} | ||
className='w-2' | ||
/> | ||
</button> | ||
</span> | ||
))} | ||
</div> | ||
); | ||
} |
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,6 +1,25 @@ | ||
import { FieldErrors, UseFormRegister } from 'react-hook-form'; | ||
|
||
export interface ProductRegistrationFormData { | ||
name: string; | ||
description: string; | ||
price: number; | ||
tags: string[]; | ||
} | ||
|
||
export interface ProductInputProps { | ||
register: UseFormRegister<ProductRegistrationFormData>; | ||
errors: FieldErrors<ProductRegistrationFormData>; | ||
} | ||
|
||
export interface ProductTagInputProps { | ||
tagInput: string; | ||
handleAddTag: (e: React.KeyboardEvent<HTMLInputElement>) => void; | ||
setTagInput: (value: string) => void; | ||
tagError: string; | ||
} | ||
|
||
export interface TagsContainerProps { | ||
tags: string[]; | ||
handleRemoveTag: (index: number) => void; | ||
} |