-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FE-73♻️ Tag관리 함수 훅으로 분리 * FE-73✨ RadioGroup 로직 수정 * FE-73✨ 유효성검사 추가 * FE-73♻️ 저자 본인 선택시의 로직 변경 * FE-73✨ 중복 태그 검사 로직 추가 * FE-73♻️ 출처 유효성(optional)검사 수정 * FE-73✨ 필수항목 입력했을때 버튼 활성화 * FE-73🐛 태그를 입력했다가 지웠을때 버튼 활성화되있는 버그 수정 * FE-73🐛 useEffect 의존성배열 lint problem 해결 * FE-73🐛 url유효성검사 에러 메세지 안뜨는 버그 수정 --------- Co-authored-by: 우지석 <[email protected]>
- Loading branch information
Showing
4 changed files
with
162 additions
and
84 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
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,36 @@ | ||
import { useState } from 'react'; | ||
import { UseFormSetValue, UseFormGetValues, UseFormSetError } from 'react-hook-form'; | ||
import { AddEpigramFormType } from '@/schema/addEpigram'; | ||
|
||
// NOTE: setError메서드로 FormField에 에러 설정 가능 | ||
const useTagManagement = (setValue: UseFormSetValue<AddEpigramFormType>, getValues: UseFormGetValues<AddEpigramFormType>, setError: UseFormSetError<AddEpigramFormType>) => { | ||
const [currentTag, setCurrentTag] = useState(''); | ||
|
||
const handleAddTag = () => { | ||
if (currentTag && currentTag.length <= 10) { | ||
const currentTags = getValues('tags') || []; | ||
if (currentTags.length < 3) { | ||
// NOTE: 중복된 태그가 있는지 확인 | ||
if (currentTags.includes(currentTag)) { | ||
setError('tags', { type: 'manual', message: '이미 저장된 태그입니다.' }); | ||
} else { | ||
setValue('tags', [...currentTags, currentTag]); | ||
setCurrentTag(''); | ||
setError('tags', { type: 'manual', message: '' }); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const handleRemoveTag = (tagToRemove: string) => { | ||
const currentTags = getValues('tags') || []; | ||
setValue( | ||
'tags', | ||
currentTags.filter((tag) => tag !== tagToRemove), | ||
); | ||
}; | ||
|
||
return { currentTag, setCurrentTag, handleAddTag, handleRemoveTag }; | ||
}; | ||
|
||
export default useTagManagement; |
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.