-
Notifications
You must be signed in to change notification settings - Fork 6
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
[비밀번호 재설정] api 연결 & 처리 #60
base: feature/login
Are you sure you want to change the base?
Changes from all commits
47d3092
85ef32c
414ac5a
361574c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
import { FormState } from "./authThunk.type"; | ||
import { getUserInfo, signIn } from "./authThunk"; | ||
import { | ||
getUserInfo, | ||
signIn, | ||
resetPassword, | ||
checkCurrentURL, | ||
signInUseCode, | ||
} from "./authThunk"; | ||
import { setAccessTokenInAxiosHeaders } from "customAxios"; | ||
|
||
export interface AuthStateProps { | ||
|
@@ -90,6 +96,16 @@ const authSlice = createSlice({ | |
state.isLogin = true; | ||
setAccessTokenInAxiosHeaders(action.payload); | ||
}) | ||
.addCase(resetPassword.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
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. isLoading값으로 로딩처리해주는 부분을 깜빡했네요. 추가하겠습니다! |
||
state.isLogin = true; | ||
setAccessTokenInAxiosHeaders(action.payload); | ||
}) | ||
.addCase(signInUseCode.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isLogin = true; | ||
setAccessTokenInAxiosHeaders(action.payload); | ||
}) | ||
.addCase(signIn.rejected, (state, action) => { | ||
state.isAsyncReject = true; | ||
state.isLoading = false; | ||
|
@@ -104,6 +120,12 @@ const authSlice = createSlice({ | |
.addCase(getUserInfo.pending, (state) => {}) | ||
.addCase(getUserInfo.fulfilled, (state, action) => { | ||
state.userInfo = action.payload; | ||
}) | ||
.addCase(resetPassword.rejected, (state) => { | ||
state.errorMessage = `전에 사용한 적 없는 새로운 비밀번호를 만드세요.`; | ||
}) | ||
.addCase(checkCurrentURL.rejected, (state) => { | ||
// 유효하지 않은 url ** | ||
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. 비밀번호 재설정 페이지에 들어오자마자, query의 code로 유효한 코드인지 체크해서 만료된 코드일 경우 여기로 넘어오는데요, 여기서상태값을 이용해 잘못된 url이거나 삭제된 페이지라는 화면을 보여주려고 합니다. |
||
}); | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ import ContentBox from "components/Common/ContentBox"; | |
import styled from "styled-components"; | ||
import SubmitButton from "../SubmitButton"; | ||
import useInput from "hooks/useInput"; | ||
import { useEffect, MouseEvent } from "react"; | ||
import { useAppDispatch, useAppSelector } from "app/store/Hooks"; | ||
import { checkCurrentURL, resetPassword } from "app/store/ducks/auth/authThunk"; | ||
|
||
const Container = styled.section` | ||
background-color: #fff; | ||
|
@@ -56,13 +59,25 @@ const Container = styled.section` | |
margin: 20px 52px 60px 52px; | ||
height: 44px; | ||
} | ||
|
||
.error-message { | ||
color: #ed4956; | ||
font-size: 14px; | ||
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. 프로젝트 기본 font-size가 14px 아니었나요? 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. // globalStyle.ts
body, input,textarea ,button {
font-size: 14px;
line-height: 18px;
padding:0;
margin:0;
} globalStyle보니까 그렇네요..!! 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. 네네 저 부분은 중복되서 삭제해도 좋을 것 같아요! |
||
line-height: 18px; | ||
text-align: center; | ||
margin: 10px 40px; | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default function ResetPasswordForm() { | ||
const { search } = useLocation(); | ||
const { username, code } = queryString.parse(search); | ||
const { username, code } = queryString.parse( | ||
search, | ||
) as AuthType.resetPasswordQuery; | ||
const dispatch = useAppDispatch(); | ||
const { errorMessage } = useAppSelector((state) => state.auth); | ||
|
||
const [newPasswordInputProps, newPasswordIsValid] = useInput( | ||
"", | ||
|
@@ -76,8 +91,22 @@ export default function ResetPasswordForm() { | |
(value) => newPasswordInputProps.value === value, | ||
); | ||
|
||
// submit api 연결 | ||
// 들어오자마자, code유효한지 체크 -> 그 전까지, loding (using useEffect) | ||
useEffect(() => { | ||
dispatch(checkCurrentURL({ code, username })); | ||
}, []); | ||
|
||
const resetPasswordClickHandler = ( | ||
event: MouseEvent<HTMLButtonElement>, | ||
) => { | ||
event.preventDefault(); | ||
dispatch( | ||
resetPassword({ | ||
code, | ||
username, | ||
newPassword: newPasswordInputProps.value, | ||
}), | ||
); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
|
@@ -123,9 +152,15 @@ export default function ResetPasswordForm() { | |
reEnterPasswordIsValid | ||
) | ||
} | ||
onClick={resetPasswordClickHandler} | ||
> | ||
비밀번호 재설정 | ||
</SubmitButton> | ||
{errorMessage && ( | ||
<div className="error-message"> | ||
<p>{errorMessage}</p> | ||
</div> | ||
)} | ||
</form> | ||
</ContentBox> | ||
</div> | ||
|
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.
resetPassword,fulfileed에도, signInUseCode.fulfiled에도 동일한 처리를 하게 되는데 리덕스 툴킷 내에서 재사용할 수 있는 방법을 혹시 아시나요?
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.
찾아보니
addMatcher
와isAllOf
등을 사용하는 방법이 있다네요? 정확히 맞는지는 모르겠지만 한 번 확인해보세요!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.
오오 감사합니다. 한번 찾아볼게요!