-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: 반려동물 정보 등록, 수정 관련 리팩터링 #360
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
311a5a9
feat/#359: 반려동물 등록 Context 수정
HyeryongChoi 3d7b16c
refactor/#359: 반려동물 등록 인풋 핸들러 훅으로 분리
HyeryongChoi a051771
refactor/#359: PetProfileEditionForm으로 분리
HyeryongChoi b12fe9c
refactor/#359: petProfile 관련 훅 파일 분리
HyeryongChoi 6d9ab3e
feat/#359: usePetProfileEdition 훅 추가
HyeryongChoi d3a55f6
refactor/#359: 에러메시지 상수로 분리
HyeryongChoi 63c984b
refactor#359: PropsWithChildren 타입 사용
HyeryongChoi 8c3679d
refactor/#359: useEasyNavigate 사용
HyeryongChoi 1ab6445
refactor/#359: 코드 간소화
HyeryongChoi a029eb1
refactor#359: onSuccess, onError 라이프사이클 활용
HyeryongChoi 4cf7990
Merge branch 'develop' of https://github.com/woowacourse-teams/2023-z…
HyeryongChoi 850b074
refactor/#359: zipgoLocalStorage를 사용하도록 변경
HyeryongChoi 9ed8f2b
refactor/#359: 반려동물 수정 및 삭제 mutation 구조 수정
HyeryongChoi 311fa20
refactor/#359: 변수명 수정
HyeryongChoi 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 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
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
245 changes: 245 additions & 0 deletions
245
frontend/src/components/PetProfile/PetProfileEditionForm/PetProfileEditionForm.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,245 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
import EditIconLight from '@/assets/svg/edit_icon_light.svg'; | ||
import TrashCanIcon from '@/assets/svg/trash_can_icon.svg'; | ||
import Input from '@/components/@common/Input/Input'; | ||
import Label from '@/components/@common/Label/Label'; | ||
import { PET_ERROR_MESSAGE, PET_SIZES } from '@/constants/petProfile'; | ||
import { usePetProfileEdition } from '@/hooks/petProfile/usePetProfileEdition'; | ||
import { usePetProfileValidation } from '@/hooks/petProfile/usePetProfileValidation'; | ||
|
||
import PetAgeSelect from '../PetAgeSelect'; | ||
import PetInfoInForm from '../PetInfoInForm'; | ||
|
||
const PetProfileEditionForm = () => { | ||
const { isMixedBreed } = usePetProfileValidation(); | ||
const { | ||
pet, | ||
isValidForm, | ||
isValidNameInput, | ||
isValidAgeSelect, | ||
isValidWeightInput, | ||
onChangeName, | ||
onChangeAge, | ||
onChangeWeight, | ||
onChangePetSize, | ||
onChangeImage, | ||
onSubmitNewPetProfile, | ||
onClickRemoveButton, | ||
} = usePetProfileEdition(); | ||
|
||
return ( | ||
<div> | ||
{pet && ( | ||
<> | ||
<FormContainer> | ||
<PetInfoWrapper> | ||
<PetInfoInForm | ||
petItem={{ ...pet, weight: Number(pet.weight) }} | ||
onChangeImage={onChangeImage} | ||
/> | ||
</PetInfoWrapper> | ||
|
||
<div> | ||
<InputLabel htmlFor="pet-name">이름 입력</InputLabel> | ||
<Input | ||
id="pet-name" | ||
value={pet.name} | ||
type="text" | ||
required | ||
minLength={1} | ||
placeholder="여기를 눌러 아이의 이름을 입력해주세요." | ||
maxLength={10} | ||
isValid | ||
onChange={onChangeName} | ||
design="underline" | ||
fontSize="1.3rem" | ||
/> | ||
<ErrorCaption>{isValidNameInput ? '' : PET_ERROR_MESSAGE.INVALID_NAME}</ErrorCaption> | ||
</div> | ||
<div> | ||
<InputLabel htmlFor="pet-age">나이 선택</InputLabel> | ||
<PetAgeSelect id="pet-age" onChange={onChangeAge} initialAge={pet.age} /> | ||
<ErrorCaption>{isValidAgeSelect ? '' : '나이를 선택해주세요!'} </ErrorCaption> | ||
</div> | ||
<div> | ||
<InputLabel htmlFor="pet-weight">몸무게 입력</InputLabel> | ||
<WeightInputContainer> | ||
<Input | ||
id="pet-weight" | ||
type="text" | ||
value={pet.weight} | ||
required | ||
minLength={1} | ||
placeholder="예) 7.5" | ||
maxLength={5} | ||
isValid | ||
onChange={onChangeWeight} | ||
design="underline" | ||
fontSize="1.3rem" | ||
inputMode="decimal" | ||
/> | ||
<Kg>kg</Kg> | ||
</WeightInputContainer> | ||
<ErrorCaption> | ||
{isValidWeightInput ? '' : PET_ERROR_MESSAGE.INVALID_WEIGHT} | ||
</ErrorCaption> | ||
</div> | ||
{isMixedBreed(pet.breed) && ( | ||
<div> | ||
<InputLabel htmlFor="pet-size">크기 선택</InputLabel> | ||
<PetSizeContainer role="radiogroup" id="pet-size"> | ||
{PET_SIZES.map(size => ( | ||
<Label | ||
key={size} | ||
role="radio" | ||
text={size} | ||
onClick={() => onChangePetSize(size)} | ||
clicked={pet.petSize === size} | ||
/> | ||
))} | ||
</PetSizeContainer> | ||
</div> | ||
)} | ||
</FormContainer> | ||
|
||
<ButtonContainer> | ||
<BasicButton | ||
type="button" | ||
$isEditButton | ||
onClick={onSubmitNewPetProfile} | ||
disabled={!isValidForm} | ||
> | ||
<EditIconImage src={EditIconLight} alt="" /> | ||
수정 | ||
</BasicButton> | ||
<BasicButton | ||
type="button" | ||
$isEditButton={false} | ||
onClick={() => { | ||
onClickRemoveButton(pet.id); | ||
}} | ||
> | ||
<img src={TrashCanIcon} alt="" /> | ||
삭제 | ||
</BasicButton> | ||
</ButtonContainer> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default PetProfileEditionForm; | ||
|
||
const FormContainer = styled.form` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 2rem; | ||
|
||
padding: 2rem; | ||
`; | ||
|
||
const PetInfoWrapper = styled.div` | ||
margin-bottom: 2rem; | ||
`; | ||
|
||
const InputLabel = styled.label` | ||
display: block; | ||
|
||
margin-bottom: 0.4rem; | ||
|
||
font-size: 1.3rem; | ||
font-weight: 500; | ||
line-height: 1.7rem; | ||
color: ${({ theme }) => theme.color.grey600}; | ||
letter-spacing: -0.5px; | ||
`; | ||
|
||
const ErrorCaption = styled.p` | ||
min-height: 1.7rem; | ||
margin-top: 1rem; | ||
|
||
font-size: 1.3rem; | ||
font-weight: 500; | ||
line-height: 1.7rem; | ||
color: ${({ theme }) => theme.color.warning}; | ||
letter-spacing: -0.5px; | ||
`; | ||
|
||
const WeightInputContainer = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const Kg = styled.p` | ||
position: absolute; | ||
top: 1.2rem; | ||
right: 1.2rem; | ||
|
||
font-size: 1.3rem; | ||
font-weight: 500; | ||
line-height: 1.7rem; | ||
color: ${({ theme }) => theme.color.grey600}; | ||
letter-spacing: -0.5px; | ||
`; | ||
|
||
const PetSizeContainer = styled.div` | ||
cursor: pointer; | ||
|
||
display: flex; | ||
gap: 0.8rem; | ||
align-items: center; | ||
|
||
margin-top: 1.2rem; | ||
`; | ||
|
||
const ButtonContainer = styled.div` | ||
position: fixed; | ||
bottom: 4rem; | ||
left: 0; | ||
|
||
display: flex; | ||
gap: 1.6rem; | ||
|
||
width: 100%; | ||
padding: 0 2rem; | ||
`; | ||
|
||
const BasicButton = styled.button<{ $isEditButton: boolean }>` | ||
cursor: pointer; | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
width: ${({ $isEditButton }) => ($isEditButton ? '70%' : '30%')}; | ||
height: 5.1rem; | ||
|
||
font-size: 1.6rem; | ||
font-weight: 700; | ||
line-height: 2.4rem; | ||
color: ${({ theme }) => theme.color.white}; | ||
letter-spacing: 0.02rem; | ||
|
||
background-color: ${({ $isEditButton, theme }) => | ||
$isEditButton ? theme.color.primary : '#E73846'}; | ||
border: none; | ||
border-radius: 16px; | ||
|
||
transition: all 100ms ease-in-out; | ||
|
||
&:active { | ||
scale: 0.98; | ||
} | ||
|
||
&:disabled { | ||
cursor: not-allowed; | ||
|
||
background-color: ${({ theme }) => theme.color.grey300}; | ||
} | ||
`; | ||
|
||
const EditIconImage = styled.img` | ||
margin-right: 0.4rem; | ||
margin-bottom: 0.2rem; | ||
`; |
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
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.
핸들러 함수는 따로 분리하면 어떨까요??