-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from softeerbootcamp4th/feature/12-commentary
[feat] 기대평 작성 기능 추가
- Loading branch information
Showing
38 changed files
with
810 additions
and
119 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion
7
src/auth/InputWithTimer.jsx → src/auth/AuthCode/InputWithTimer.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useState } from "react"; | ||
import InputWithTimer from "./InputWithTimer.jsx"; | ||
import useTimer from "./useTimer.js"; | ||
import submitAuthCode from "./submitAuthCode.js"; | ||
import requestAuthCode from "../requestAuthCode.js"; | ||
import Button from "@/common/Button.jsx"; | ||
|
||
const AUTH_MAX_DURATION = 5 * 60; | ||
|
||
function AuthSecondSection({ name, phone, onComplete }) { | ||
// 상태 | ||
const [authCode, setAuthCode] = useState(""); | ||
const [timer, resetTimer] = useTimer(AUTH_MAX_DURATION); | ||
const [errorMessage, setErrorMessage] = useState(""); | ||
|
||
// 인증코드 재전송 동작 | ||
function retryAuthCode() { | ||
requestAuthCode(name, phone) | ||
.then(() => { | ||
setErrorMessage(""); | ||
setAuthCode(""); | ||
resetTimer(); | ||
}) | ||
.catch((error) => setErrorMessage(error.message)); | ||
} | ||
|
||
// 인증코드 전송 동작 | ||
function onSubmit(e) { | ||
e.preventDefault(); | ||
submitAuthCode(name, phone, authCode) | ||
.then(() => { | ||
setErrorMessage(""); | ||
onComplete(true); | ||
}) | ||
.catch((error) => { | ||
setErrorMessage(error.message); | ||
}); | ||
} | ||
|
||
const josa = "013678".includes(phone[phone.length - 1]) ? "으" : ""; | ||
return ( | ||
<div className="w-full h-[calc(100svh-2rem)] max-h-[40.625rem] p-6 min-[520px]:px-20 py-10 relative flex flex-col gap-14"> | ||
<p className="text-body-l font-bold text-neutral-700"> | ||
{phone} | ||
{josa}로<br /> | ||
인증번호를 전송했어요. | ||
</p> | ||
<form | ||
className="flex flex-col flex-grow w-full relative pb-4 gap-4 group" | ||
onSubmit={onSubmit} | ||
> | ||
<div className="flex flex-col flex-grow justify-center items-center gap-7 px-0.5 relative h-0"> | ||
<InputWithTimer | ||
text={authCode} | ||
setText={setAuthCode} | ||
timer={timer} | ||
required | ||
minLength="6" | ||
maxLength="6" | ||
placeholder="인증번호를 입력해주세요" | ||
isError={errorMessage !== "" || timer === 0} | ||
/> | ||
<span className="absolute bottom-5 text-detail-l font-bold text-red-400"> | ||
{errorMessage || (timer === 0 ? "입력시간이 종료되었습니다." : "")} | ||
</span> | ||
</div> | ||
<div className="w-full flex flex-wrap justify-center gap-5"> | ||
<Button | ||
styleType="filled" | ||
type="submit" | ||
className="w-36 min-h-14" | ||
disabled={timer === 0} | ||
> | ||
인증 완료하기 | ||
</Button> | ||
<Button | ||
styleType="ghost" | ||
type="button" | ||
className="min-h-14" | ||
onClick={retryAuthCode} | ||
> | ||
재전송 | ||
</Button> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
|
||
export default AuthSecondSection; |
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,29 @@ | ||
import { fetchServer, handleError } from "@/common/fetchServer.js"; | ||
import { EVENT_ID } from "@/common/constants.js"; | ||
import tokenSaver from "../tokenSaver.js"; | ||
|
||
async function submitAuthCode(name, phoneNumber, authCode) { | ||
try { | ||
const body = { | ||
name, | ||
phoneNumber: phoneNumber.replace(/\D+/g, ""), | ||
authCode, | ||
}; | ||
const { token } = await fetchServer( | ||
`/api/v1/event-user/check-auth/${EVENT_ID}`, | ||
{ | ||
method: "post", | ||
body, | ||
}, | ||
); | ||
tokenSaver.set(token); | ||
return ""; | ||
} catch (e) { | ||
return handleError({ | ||
400: "잘못된 요청 형식입니다.", | ||
401: "인증번호가 틀렸습니다. 다시 입력하세요.", | ||
})(e); | ||
} | ||
} | ||
|
||
export default submitAuthCode; |
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 { useState, useRef, useEffect, useCallback } from "react"; | ||
import IntervalController from "@/common/IntervalController.js"; | ||
|
||
function useTimer(remainTime) { | ||
const [timer, setTimer] = useState(remainTime); | ||
const intervalController = useRef(new IntervalController(1000)); | ||
|
||
useEffect(() => { | ||
const ticker = intervalController.current; | ||
|
||
function decreaseTime() { | ||
setTimer((timer) => (timer > 0 ? timer - 1 : 0)); | ||
} | ||
ticker.addEventListener("interval", decreaseTime); | ||
ticker.start(); | ||
|
||
return () => { | ||
ticker.end(); | ||
ticker.removeEventListener("interval", decreaseTime); | ||
}; | ||
}, []); | ||
|
||
const resetTimer = useCallback(() => { | ||
setTimer(remainTime); | ||
intervalController.current.end(); | ||
intervalController.current.start(); | ||
}, [remainTime]); | ||
|
||
return [timer, resetTimer]; | ||
} | ||
|
||
export default useTimer; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.