-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: 내 정보 수정 페이지 UI 및 API 연동 구현 #924
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
File renamed without changes.
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
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
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
32 changes: 32 additions & 0 deletions
32
frontend/src/pages/ManagerProfileEdit/ManagerProfileEdit.styles.ts
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,32 @@ | ||
import styled from 'styled-components'; | ||
import { FORM_MAX_WIDTH } from 'constants/style'; | ||
|
||
export const Container = styled.div` | ||
width: 100%; | ||
max-width: ${FORM_MAX_WIDTH}; | ||
margin: 0 auto; | ||
`; | ||
|
||
export const PageTitle = styled.h2` | ||
font-size: 1.5rem; | ||
font-weight: 400; | ||
text-align: center; | ||
margin: 2.125rem auto; | ||
`; | ||
|
||
export const PasswordChangeLinkMessage = styled.p` | ||
margin: 1rem 0; | ||
text-align: center; | ||
font-size: 0.75rem; | ||
color: ${({ theme }) => theme.gray[500]}; | ||
|
||
a { | ||
color: ${({ theme }) => theme.primary[400]}; | ||
text-decoration: none; | ||
margin-left: 0.375rem; | ||
|
||
&:hover { | ||
font-weight: 700; | ||
} | ||
} | ||
`; |
48 changes: 48 additions & 0 deletions
48
frontend/src/pages/ManagerProfileEdit/ManagerProfileEdit.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,48 @@ | ||
import { AxiosError } from 'axios'; | ||
import React from 'react'; | ||
import { useMutation } from 'react-query'; | ||
import { Link, useHistory } from 'react-router-dom'; | ||
import { putMember } from 'api/member'; | ||
import Header from 'components/Header/Header'; | ||
import Layout from 'components/Layout/Layout'; | ||
import MESSAGE from 'constants/message'; | ||
import PATH from 'constants/path'; | ||
import { ErrorResponse } from 'types/response'; | ||
import * as Styled from './ManagerProfileEdit.styles'; | ||
import ProfileEditForm from './units/ProfileEditForm'; | ||
|
||
const ManagerProfileEdit = () => { | ||
const history = useHistory(); | ||
|
||
const editProfile = useMutation(putMember, { | ||
onSuccess: () => { | ||
history.push(PATH.MANAGER_MAP_LIST); | ||
}, | ||
|
||
onError: (error: AxiosError<ErrorResponse>) => { | ||
alert(error?.response?.data.message ?? MESSAGE.MEMBER.EDIT_PROFILE_UNEXPECTED_ERROR); | ||
}, | ||
}); | ||
|
||
const handleSubmit = ({ userName, emoji }: { userName: string; emoji: string }) => { | ||
editProfile.mutate({ userName, emoji }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<Layout> | ||
<Styled.Container> | ||
<Styled.PageTitle>내 정보 수정</Styled.PageTitle> | ||
<ProfileEditForm onSubmit={handleSubmit} /> | ||
<Styled.PasswordChangeLinkMessage> | ||
비밀번호를 변경하고 싶으신가요? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<Link to="/">변경하기</Link> | ||
</Styled.PasswordChangeLinkMessage> | ||
</Styled.Container> | ||
</Layout> | ||
</> | ||
); | ||
}; | ||
|
||
export default ManagerProfileEdit; |
9 changes: 9 additions & 0 deletions
9
frontend/src/pages/ManagerProfileEdit/units/ProfileEditForm.styles.ts
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,9 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Form = styled.form` | ||
margin: 3.75rem 0 1rem; | ||
`; | ||
|
||
export const InputWrapper = styled.div` | ||
margin-bottom: 3rem; | ||
`; |
109 changes: 109 additions & 0 deletions
109
frontend/src/pages/ManagerProfileEdit/units/ProfileEditForm.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,109 @@ | ||
import { AxiosError } from 'axios'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useQuery } from 'react-query'; | ||
import { queryValidateUserName } from 'api/join'; | ||
import Button from 'components/Button/Button'; | ||
import EmojiSelector from 'components/EmojiSelector/EmojiSelector'; | ||
import Input from 'components/Input/Input'; | ||
import MANAGER from 'constants/manager'; | ||
import MESSAGE from 'constants/message'; | ||
import useMember from 'hooks/query/useMember'; | ||
import useInputs from 'hooks/useInputs'; | ||
import { ErrorResponse } from 'types/response'; | ||
import * as Styled from './ProfileEditForm.styles'; | ||
|
||
interface ProfileEditFormProps { | ||
onSubmit: ({ userName, emoji }: { userName: string; emoji: string }) => void; | ||
} | ||
|
||
const ProfileEditForm = ({ onSubmit }: ProfileEditFormProps) => { | ||
const member = useMember(); | ||
const initialUserName = member.data?.data.userName; | ||
const initialEmoji = member.data?.data.emoji.name; | ||
|
||
const [emoji, setEmoji] = useState<string>(''); | ||
const [{ userName }, onChangeForm, setInputs] = useInputs<{ userName: string }>({ | ||
userName: '', | ||
}); | ||
|
||
const [userNameMessage, setUserNameMessage] = useState(''); | ||
|
||
const checkValidateUserName = useQuery( | ||
['checkValidateUserName', userName], | ||
queryValidateUserName, | ||
{ | ||
enabled: false, | ||
retry: false, | ||
|
||
onSuccess: () => { | ||
setUserNameMessage(MESSAGE.JOIN.VALID_USERNAME); | ||
}, | ||
|
||
onError: (error: AxiosError<ErrorResponse>) => { | ||
setUserNameMessage( | ||
error.response?.data.message ?? MESSAGE.JOIN.CHECK_USERNAME_UNEXPECTED_ERROR | ||
); | ||
}, | ||
} | ||
); | ||
|
||
const handleSelectEmoji = (emoji: string) => { | ||
setEmoji(emoji); | ||
}; | ||
|
||
const handleChangeUserName = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
onChangeForm(event); | ||
setUserNameMessage(''); | ||
}; | ||
|
||
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (event) => { | ||
event.preventDefault(); | ||
|
||
onSubmit({ userName, emoji }); | ||
}; | ||
|
||
const isSubmitButtonDisabled = !(emoji && userName); | ||
|
||
useEffect(() => { | ||
if (!initialUserName) return; | ||
|
||
setInputs((prevInputs) => ({ | ||
...prevInputs, | ||
userName: initialUserName, | ||
})); | ||
}, [initialUserName, setInputs]); | ||
|
||
useEffect(() => { | ||
if (!initialEmoji) return; | ||
|
||
setEmoji(initialEmoji); | ||
}, [initialEmoji]); | ||
|
||
return ( | ||
<Styled.Form onSubmit={handleSubmit}> | ||
{initialEmoji && <EmojiSelector initialEmoji={initialEmoji} onSelect={handleSelectEmoji} />} | ||
|
||
{initialUserName && ( | ||
<Styled.InputWrapper> | ||
<Input | ||
type="text" | ||
label="이름" | ||
name="userName" | ||
minLength={MANAGER.USERNAME.MIN_LENGTH} | ||
maxLength={MANAGER.USERNAME.MAX_LENGTH} | ||
value={userName} | ||
onChange={handleChangeUserName} | ||
message={userNameMessage} | ||
status={checkValidateUserName.isSuccess ? 'success' : 'error'} | ||
required | ||
/> | ||
</Styled.InputWrapper> | ||
)} | ||
<Button variant="primary" size="large" fullWidth disabled={isSubmitButtonDisabled}> | ||
수정하기 | ||
</Button> | ||
</Styled.Form> | ||
); | ||
}; | ||
|
||
export default ProfileEditForm; |
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
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.
오타가 있었군요 ㅋㅋㅋㅋ