-
Notifications
You must be signed in to change notification settings - Fork 1
✨ feat: 내 프로필 수정 페이지 구현 #114
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
509d8de
✨feat: 드롭다운과 label 연결을 위해 props에 id를 옵셔널로 추가
Yun-Jinwoo e0a2097
🎨 style: 모바일용 프로필 수정 페이지 구현
Yun-Jinwoo 48665c5
🎨 style: 데스크탑/테블릿용 반응형 페이지 구현
Yun-Jinwoo 1b579f4
Merge branch 'develop' of https://github.com/codeit-6team/The-julge i…
Yun-Jinwoo 165b6f1
✨ feat: 내 프로필 수정 페이지 기능 구현
Yun-Jinwoo 752aad6
✨ feat: 로그인이 안된 상태로 해당 페이지에 접근 시 경고 모달 및 로그인 페이지로 이동, 타입 관련 수정
Yun-Jinwoo 63c5517
✨ feat: dropdown 컴포넌트에 set함수를 전달하기 위해 address 따로 분리
Yun-Jinwoo 79b60ce
✨ feat: 등록 버튼 클릭 시 입력이 안된 부분에 대한 모달 설정
Yun-Jinwoo d50967e
✨ feat: 초기 데이터 불러오지 못할 경우 모달 처리
Yun-Jinwoo 2da618e
📝 dics: 코드에 대한 주석 추가
Yun-Jinwoo e6de94d
✨ feat: 테스트용으로 링크 추가
Yun-Jinwoo 6c99c52
✨ feat: AuthContext의 isLoggedIn 속성을 활용해 로그인 상태 확인
Yun-Jinwoo 2675e67
Merge branch 'develop' of https://github.com/codeit-6team/The-julge i…
Yun-Jinwoo 7fbbbe0
♻️ refactor: 피드백 반영 수정
Yun-Jinwoo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| import { Link } from 'react-router-dom'; | ||
| export default function Profile() { | ||
| return <div>내 프로필 상세 (알바님)</div>; | ||
| return ( | ||
| <> | ||
| <Link to="/profile/edit">등록하기</Link> | ||
| </> | ||
| ); | ||
| } |
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 |
|---|---|---|
| @@ -1,3 +1,207 @@ | ||
| import { useState, useEffect, useCallback, useContext } from 'react'; | ||
| import { Link, useNavigate } from 'react-router-dom'; | ||
| import { AuthContext } from '@/context/AuthContext'; | ||
| import { getUser, putUser, type SeoulDistrict } from '@/api/userApi'; | ||
| import Dropdown from '@/components/common/Dropdown'; | ||
| import Input from '@/components/common/Input'; | ||
| import Button from '@/components/common/Button'; | ||
| import Modal from '@/components/common/Modal'; | ||
| import close from '@/assets/icons/close.svg'; | ||
| import { ADDRESS_OPTIONS } from '@/constants/dropdownOptions'; | ||
|
|
||
| export default function ProfileForm() { | ||
| return <div>내 프로필 등록/편집 (알바님)</div>; | ||
| const navigate = useNavigate(); | ||
| const { isLoggedIn } = useContext(AuthContext); | ||
| // 사용자 입력값 상태 (이름, 전화번호, 소개글) | ||
| const [profileInfo, setProfileInfo] = useState({ | ||
| name: '', | ||
| phone: '', | ||
| bio: '', | ||
| }); | ||
|
|
||
| // dropdown 컴포넌트에 set함수를 전달하기 위해 address는 따로 분리 | ||
| const [selectedAddress, setSelectedAddress] = useState<SeoulDistrict | null>( | ||
| null, | ||
| ); | ||
|
|
||
| const [modal, setModal] = useState({ | ||
| isOpen: false, | ||
| message: '', | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (isLoggedIn) { | ||
| const userId = localStorage.getItem('userId'); | ||
|
|
||
| if (!userId) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '사용자 정보를 가져올 수 없습니다. 다시 로그인해주세요.', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const fetchUserInfo = async () => { | ||
| try { | ||
| const userInfo = await getUser(userId); | ||
| setProfileInfo({ | ||
| name: userInfo.item.name ?? '', | ||
| phone: userInfo.item.phone ?? '', | ||
| bio: userInfo.item.bio ?? '', | ||
| }); | ||
| setSelectedAddress((userInfo.item.address as SeoulDistrict) ?? ''); | ||
| } catch (error) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: (error as Error).message, | ||
| }); | ||
| } | ||
| }; | ||
| fetchUserInfo(); | ||
| } else { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '로그인이 필요합니다.', | ||
| }); | ||
| } | ||
| }, [isLoggedIn]); | ||
|
|
||
| function handleChange( | ||
| e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, | ||
| ) { | ||
| const { name, value } = e.target; | ||
| const sanitized = name === 'phone' ? value.replace(/[^0-9]/g, '') : value; // phone은 숫자만 입력 가능하도록 설정 | ||
|
|
||
| setProfileInfo((prev) => ({ | ||
| ...prev, | ||
| [name]: sanitized, | ||
| })); | ||
| } | ||
|
|
||
| async function handleSubmit(e: React.FormEvent<HTMLFormElement>) { | ||
| e.preventDefault(); | ||
| const { name, phone, bio } = profileInfo; | ||
| const userId = localStorage.getItem('userId'); | ||
| // 로그인이 안된 상태에 대한 처리 | ||
| if (!isLoggedIn || !userId) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '로그인이 필요합니다.', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // 이름이 입력되지 않은 경우 | ||
| if (!name.trim()) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '이름을 입력해주세요.', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // 지역이 선택되지 않은 경우 | ||
| if (!selectedAddress) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '선호 지역을 선택해주세요', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await putUser(userId, { | ||
| name, | ||
| phone, | ||
| address: selectedAddress, | ||
| bio, | ||
| }); | ||
| setModal({ | ||
| isOpen: true, | ||
| message: '등록이 완료되었습니다.', | ||
| }); | ||
| } catch (error) { | ||
| setModal({ | ||
| isOpen: true, | ||
| message: (error as Error).message, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const handleModalConfirm = useCallback(() => { | ||
| if (modal.message === '등록이 완료되었습니다.') { | ||
| setModal({ isOpen: false, message: '' }); | ||
| navigate('/profile'); | ||
| } else if (modal.message.includes('로그인')) { | ||
| setModal({ isOpen: false, message: '' }); | ||
| navigate('/login'); | ||
| } else { | ||
| setModal({ isOpen: false, message: '' }); | ||
| } | ||
| }, [modal.message, navigate]); | ||
|
|
||
| return ( | ||
| <div className="min-h-[calc(100vh-102px)] bg-gray-5 md:min-h-[calc(100vh-70px)]"> | ||
| <div className="mx-12 flex flex-col gap-24 pt-40 pb-80 md:mx-32 md:gap-32 md:py-60 lg:mx-auto lg:w-964"> | ||
| <div className="flex items-center justify-between"> | ||
| <h1 className="text-h3/24 font-bold md:text-h1/34">내 프로필</h1> | ||
| <Link to="/profile"> | ||
| <img src={close} alt="닫기" className="md:size-32" /> | ||
| </Link> | ||
| </div> | ||
| <form | ||
| className="flex flex-col gap-24 md:gap-32" | ||
| onSubmit={handleSubmit} | ||
| > | ||
| <div className="flex flex-col gap-20 md:gap-24"> | ||
| <div className="grid grid-cols-1 gap-20 md:grid-cols-2 md:gap-y-24 lg:grid-cols-3"> | ||
| <Input | ||
| label="이름*" | ||
| name="name" | ||
| value={profileInfo.name} | ||
| onChange={handleChange} | ||
| /> | ||
| <Input | ||
| label="연락처*" | ||
| type="tel" | ||
| name="phone" | ||
| maxLength={11} | ||
| value={profileInfo.phone} | ||
| onChange={handleChange} | ||
| /> | ||
| <div className="flex flex-col gap-8 text-body1/26 font-regular"> | ||
| <label htmlFor="region">선호 지역*</label> | ||
| <Dropdown | ||
| id="region" | ||
| variant="form" | ||
| options={ADDRESS_OPTIONS} | ||
| selected={selectedAddress} | ||
| setSelect={setSelectedAddress} | ||
| /> | ||
| </div> | ||
| </div> | ||
| <div className="flex flex-col gap-8 text-body1/26 font-regular"> | ||
| <label htmlFor="bio">소개</label> | ||
| <textarea | ||
| name="bio" | ||
| id="bio" | ||
| className="h-153 resize-none rounded-[5px] border border-gray-30 bg-white px-20 py-16 placeholder-gray-40" | ||
| placeholder="입력" | ||
| value={profileInfo.bio} | ||
| onChange={handleChange} | ||
| ></textarea> | ||
| </div> | ||
| </div> | ||
| <Button type="submit" className="md:mx-auto md:w-312"> | ||
| 등록하기 | ||
| </Button> | ||
| </form> | ||
| </div> | ||
| {modal.isOpen && ( | ||
| <Modal onClose={handleModalConfirm} onButtonClick={handleModalConfirm}> | ||
| {modal.message} | ||
| </Modal> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
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.
별로 좋은 방식은 아닌 것 같지만... 일단 확인했습니다
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.
혹시 어떤 방식이 또 있을까요?? 전 저거밖에 생각이 안나서 저렇게 작성했습니다
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.
저도 마땅히 떠오르진 않네요? 초기에 말한 것처럼 Nav 컴포넌트를 page 컴포넌트 내에 넣고 h-screen으로 활용하는 게 제일 좋지 않나 생각하지만 일단 밖으로 빼서 더 좋은 방법이 생각 나지는 않네요
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.
으흠 알겠습니다 일단 이렇게 가겠습니다~!