Skip to content
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: Discord Webhook 통신 구현 #56

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/api/postRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export interface postRegisterProps {
email: string
password: string
nickname: string
discord: string
}

const postRegister = async({ email, password, nickname }: postRegisterProps) => {
const postRegister = async({ email, password, nickname, discord }: postRegisterProps) => {
const response = await axiosInstance.post('/auth/register', {
email,
password,
nickname
nickname,
discord
})
return response.data
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수 postRegister가 수정되어서 discord라는 추가적인 속성을 인자로 받도록 변경되었습니다. 이 변경은 인터페이스 postRegisterProps에 discord 속성을 추가하여 반영되었습니다. 그러나 기존 코드의 에러는 종종 간과되며 누락될 수 있습니다. 따라서 discord 속성을 지정한 경우 오류가 발생할 수 있습니다. 따라서 변경된 함수 내에서 discord 속성을 사용하기 전에 discord 속성이 null 또는 undefined인지 확인하는 방어적 코딩의 추가가 필요합니다. 또한 axiosInstance.post 호출 후 응답을 처리하기 전에 응답에 대한 오류 처리를 추가하는 것이 좋습니다. 마지막으로 코드 리뷰 후에는 단위 테스트를 통해 변경된 로직이 예상대로 작동하는지 확인하는 것이 좋습니다.

Expand Down
26 changes: 23 additions & 3 deletions src/pages/Join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Join = () => {
const [email, setEmail] = useState('')
const [pw, setPw] = useState('')
const [pwCheck, setPwCheck] = useState('')
const [discord, setDiscord] = useState('')
const [idError, setIdError] = useState('')
const [isPwVisible, setIsPwVisible] = useState(false)
const [isPwCheckVisible, setIsPwCheckVisible] = useState(false)
Expand All @@ -20,7 +21,8 @@ const Join = () => {
nickname: '',
email: '',
pw: '',
pwCheck: ''
pwCheck: '',
discord: ''
})

const postJoin = useMutation({
Expand Down Expand Up @@ -57,6 +59,11 @@ const Join = () => {
setErrorMessages((prev) => ({ ...prev, pwCheck: '' }))
}

const handleDiscordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setDiscord(e.target.value)
setErrorMessages((prev) => ({ ...prev, discord: '' }))
}

const handleJoinSubmit = async (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault()

Expand All @@ -65,6 +72,7 @@ const Join = () => {
email: !email ? '* 이메일을 입력해주세요' : '',
pw: !pw ? '* 비밀번호를 입력해주세요' : '',
pwCheck: !pwCheck ? '* 비밀번호 확인을 입력해주세요' : '',
discord: !discord ? '* 디스코드 Webhook url을 입력해주세요' : ''
}

// 회원가입 통신 코드
Expand All @@ -79,7 +87,7 @@ const Join = () => {

if (Object.values(errors).some((msg) => msg)) return

await postJoin.mutateAsync({email, password: pw, nickname})
await postJoin.mutateAsync({email, password: pw, nickname, discord})
alert('회원가입에 성공하였습니다! 로그인해주세요')
navigate('/login')
}
Expand Down Expand Up @@ -149,6 +157,18 @@ const Join = () => {
</Line>
{errorMessages.pwCheck && <ErrorMessage>{errorMessages.pwCheck}</ErrorMessage>}
</InputWrapper>
<InputWrapper>
<Line>
<Label>디스코드 URL</Label>
<Input
type="text"
placeholder="디스코드 Webhook URL을 입력하세요"
value={discord}
onChange={handleDiscordChange}
/>
</Line>
{errorMessages.discord && <ErrorMessage>{errorMessages.discord}</ErrorMessage>}
</InputWrapper>
<Button onClick={handleJoinSubmit}>회원가입</Button>
<Login>
이미 계정이 있으신가요? <StyledLink to={'/login'}>로그인</StyledLink>
Expand Down Expand Up @@ -196,7 +216,7 @@ const InputWrapper = styled.div`
`

const Label = styled.div`
width: 5.5rem;
width: 5.7rem;
margin-right: 2rem;
`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경 사항:

  1. discord 상태 값 및 입력 핸들러를 추가하여 디스코드 Webhook URL을 수집할 수 있도록 지원
  2. discord 상태 값에 대한 유효성 검사를 수행하고 오류 메시지를 표시하여 사용자가 올바른 값을 입력하도록 유도
  3. 디스코드 URL 입력란을 UI에 추가하여 사용자가 입력할 수 있도록 함
  4. 디스코드 URL 입력란에 대한 오류 메시지를 출력하고 올바른 형식의 입력을 유도
  5. Label 스타일의 너비를 조정하여 디자인을 더 균형있게 수정함

개선점:

  1. 디스코드 URL 입력란에 대한 입력값이 올바른 형식인지 검증하는 추가적인 유효성 검사를 구현할 수 있음
  2. 코드 내에 주석을 추가하여 각 부분의 역할과 기능을 명확히 설명할 수 있음
  3. 중복되는 CSS 속성을 최적화하여 코드를 더 간결하게 유지할 수 있음.

Expand Down
Loading