-
Notifications
You must be signed in to change notification settings - Fork 5
[feat, refactor] #177 ResetPasswordModal, OpenPasswordModal, Modal.tsx, useModalStore: 비밀번호 재설정 모달 구현 / Modal, useModalStore: form 제출 기능 확장 및 IIFE 지원 / 상태 구독 기반 API 호출 처리 #192
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 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d9c55b0
feat: ResetPasswordLinkModal IIFE 로 호출되도록 변경 / options.button 에 formI…
jjanie00 32ef02b
feat: form 태그에 id 추가 / 폼 제출 시 requestBody 설정
jjanie00 ac18ce5
feat: IIFE 호출방식에 따른 타이밍 제어 / Modal 버튼에 formId 기반 form 연결 로직 추가
jjanie00 9db5472
feat: 모달 IIFE 호출 지원을 위한 타입 확장 / formId 처리 로직 추가
jjanie00 c47aaf1
chore(useModalStore): 주석 변경
jjanie00 9bb4e6d
chore: handleEmailValidation 으로 이메일 유효성 검사 함수명 수정
jjanie00 af0f46e
feat: requestBody 설정 및 비밀번호 재설정 이메일 api 호출
jjanie00 dbcdcc4
feat: 비밀번호 재설정 요청 성공 시 토스트 메시지 및 모달 종료 처리
jjanie00 48f626a
feat: 204 error 한글 토스트 메시지로 변환 및 signup 으로 리다이렉트
jjanie00 7479f1e
chore: 불필요한 closeModal import 삭제
jjanie00 41fa164
refactor: PasswordResetRequestModal 로 컴포넌트명 수정
jjanie00 3c585b2
refactor: handleEmailValidation 로직 onRequest 내부로 이동
jjanie00 372717b
refactor: 유효성 검사 함수 이동에 따라 onSubmit 내부에서 해당 함수 호출 삭제
jjanie00 d6b21e3
fix(Modal.tsx): useEffect 내부 로직 handleRequest 내부로 이동시켜 taskList에서 api…
jjanie00 734fa9e
Merge remote-tracking branch 'origin/dev' into feat/#177/reset-passwo…
jjanie00 f758015
feat: subscribe 사용해 requestBody 상태 구독 추가
jjanie00 395f1a8
refactor: OpenPasswordResetModal 로 컴포넌트명 변경에 따른 import 문 수정
jjanie00 205486a
refactor: form 존재 여부에 따른 handleRequest 함수 분기 처리
jjanie00 0be972f
refactor(useModalStore): subscribeWithSelector 미들웨어 도입으로 모달 상태 구독 방식 개선
jjanie00 6c58ff8
feat(ResetPasswordModal): form 내부에서 유효성 검사 및 상태 설정 로직 통합
jjanie00 90b1fc4
feat(OpenPasswordResetModal): useEffect 내 requestBody 구독을 통한 api 호출 트…
jjanie00 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
13 changes: 0 additions & 13 deletions
13
src/app/(auth)/login/_components/LoginForm/ForgotPasswordButton.tsx
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/app/(auth)/login/_components/LoginForm/PasswordResetRequestModal.tsx
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| 'use client'; | ||
|
|
||
| import ResetPasswordLinkModal from '@/components/common/Modal/content/ResetPasswordLinkModal'; | ||
| import { postResetPasswordToEmail } from '@/lib/apis/user'; | ||
| import { ResetPasswordToEmailBody } from '@/lib/apis/user/type'; | ||
| import { useModalStore } from '@/store/useModalStore'; | ||
| import { validateEmail } from '@/utils/inputValidation'; | ||
| import { useRouter } from 'next/navigation'; | ||
| import { useRef } from 'react'; | ||
| import { toast } from 'react-toastify'; | ||
|
|
||
| export default function ForgotPasswordButton({ ...props }) { | ||
| const { openModal } = useModalStore(); | ||
| const router = useRouter(); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const { setRequestBody } = useModalStore(); | ||
|
|
||
| // send reset password link | ||
| const handleSendResetPasswordLink = async ( | ||
| requestBody: ResetPasswordToEmailBody | ||
| ) => { | ||
| try { | ||
| const response = await postResetPasswordToEmail({ body: requestBody }); | ||
|
|
||
| if (!response) { | ||
| throw new Error('204 : No Content'); | ||
| } | ||
| toast.success('비밀번호 재설정 링크가 전송되었습니다.'); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| const errorMessage = error.message; | ||
|
|
||
| // 존재하지 않는 유저 : User not found | ||
| if (errorMessage.includes('User not found')) { | ||
| toast.error('존재하지 않는 이메일입니다. 회원가입을 먼저 해주세요.'); | ||
| router.push('/signup'); | ||
| } else { | ||
| toast.error(`Error : ${error}`); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="mt-3 mb-10 flex justify-end"> | ||
| <button | ||
| className="leading-normal font-medium text-emerald-500 underline" | ||
| type="button" | ||
| onClick={() => { | ||
| openModal( | ||
| { | ||
| title: '비밀번호 재설정', | ||
| description: '비밀번호 재설정 링크를 보내드립니다.', | ||
| button: { | ||
| formId: 'reset-password-form', // formId 연결 | ||
| number: 2, | ||
| text: '링크 보내기', | ||
| onRequest: () => { | ||
| // 이메일 유효성 검사 | ||
| const email = inputRef.current?.value.trim(); | ||
| if (!email) return; | ||
| if (validateEmail(email)) { | ||
| setRequestBody({ email }); | ||
| } | ||
|
|
||
| // const { email } = newBody as { email: string }; | ||
|
|
||
| const requestBodyApi: ResetPasswordToEmailBody = { | ||
| email, | ||
| redirectUrl: `${window.location.origin}/`, | ||
| }; | ||
|
|
||
| console.log('requestBody:', requestBodyApi); // x | ||
| handleSendResetPasswordLink(requestBodyApi); | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| (() => <ResetPasswordLinkModal />)() | ||
| ); | ||
| }} | ||
| {...props} | ||
| > | ||
| 비밀번호를 잊으셨나요? | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
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
20 changes: 17 additions & 3 deletions
20
src/components/common/Modal/content/ResetPasswordLinkModal/index.tsx
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,9 +1,23 @@ | ||
| 'use client'; | ||
|
|
||
| import InputBase from '@/components/common/Input/InputBase'; | ||
| import { useRef } from 'react'; | ||
|
|
||
| export default function ResetPasswordLinkModal() { | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| return ( | ||
| <div> | ||
| <InputBase placeholder="이메일을 입력하세요." /> | ||
| </div> | ||
| <form | ||
| id="reset-password-form" | ||
| onSubmit={(e) => { | ||
| e.preventDefault(); | ||
| }} | ||
| > | ||
| <InputBase | ||
| ref={inputRef} | ||
| placeholder="이메일을 입력하세요." | ||
| defaultValue="" // 초기값 설정 | ||
| /> | ||
| </form> | ||
| ); | ||
| } |
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
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.
수정 이후
<form>태그에서도 해당 ref 는 사용하고 있지 않은 상황이라, 추후 삭제해도 괜찮을 것 같습니다 ~!