-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] refactor: Textarea를 사용하는 공통 장문형 답변 입력 컴포넌트 분리 (#252)
* feat: 공통 textarea 컴포넌트 작성 * refactor: longReviewItem의 로직을 커스텀 훅으로 분리 * refactor: longReviewItem으로 이름 변경 및 컴포넌트 구현 * chore: 기존의 ReviewItem 제거 및 리뷰 작성 페이지에 LongReviewItem 적용
- Loading branch information
Showing
7 changed files
with
97 additions
and
100 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { TextareaHTMLAttributes } from 'react'; | ||
|
||
import useLongReviewItem from '@/hooks/useLongReviewItem'; | ||
|
||
import * as S from './styles'; | ||
|
||
interface LongReviewItemProps extends TextareaHTMLAttributes<HTMLTextAreaElement> { | ||
minLength: number; | ||
maxLength: number; | ||
initialValue?: string; | ||
} | ||
|
||
const LongReviewItem = ({ minLength, maxLength, initialValue = '', style, ...rest }: LongReviewItemProps) => { | ||
const { value, textLength, isError, errorMessage, handleChange, handleBlur } = useLongReviewItem({ | ||
minLength, | ||
maxLength, | ||
initialValue, | ||
}); | ||
|
||
return ( | ||
<S.TextareaContainer> | ||
<S.Textarea | ||
value={value} | ||
$isError={isError} | ||
$style={style} | ||
onChange={handleChange} | ||
onBlur={handleBlur} | ||
{...rest} | ||
/> | ||
<S.TextareaInfoContainer> | ||
<S.ReviewTextareaError>{isError && errorMessage}</S.ReviewTextareaError> | ||
<S.ReviewTextLength>{textLength}</S.ReviewTextLength> | ||
</S.TextareaInfoContainer> | ||
</S.TextareaContainer> | ||
); | ||
}; | ||
|
||
export default LongReviewItem; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState } from 'react'; | ||
|
||
interface UseLongReviewItemProps { | ||
minLength: number; | ||
maxLength: number; | ||
initialValue?: string; | ||
} | ||
|
||
const useLongReviewItem = ({ minLength, maxLength, initialValue }: UseLongReviewItemProps) => { | ||
const [value, setValue] = useState(initialValue); | ||
const [isError, setIsError] = useState(false); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
const value = e.target.value; | ||
if (value.length <= maxLength) setValue(value); | ||
if (value.length >= minLength) setIsError(false); | ||
}; | ||
|
||
const handleBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => { | ||
const value = e.target.value; | ||
if (value.length < minLength) { | ||
setIsError(true); | ||
setErrorMessage(`최소 ${minLength}자 이상 작성해 주세요.`); | ||
} else { | ||
setIsError(false); | ||
setErrorMessage(''); | ||
} | ||
}; | ||
|
||
return { | ||
value, | ||
textLength: `${(value && value.length) || 0} / ${maxLength}`, | ||
isError, | ||
errorMessage, | ||
handleChange, | ||
handleBlur, | ||
}; | ||
}; | ||
|
||
export default useLongReviewItem; |
58 changes: 0 additions & 58 deletions
58
frontend/src/pages/ReviewWriting/components/ReviewItem/index.tsx
This file was deleted.
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