-
Notifications
You must be signed in to change notification settings - Fork 2
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 #4 from taejun0/main
feature: api연결 및 로그인 회원가입 페이지 구현
- Loading branch information
Showing
20 changed files
with
477 additions
and
56 deletions.
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
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,53 @@ | ||
import { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { toast } from "react-toastify"; | ||
import { letterService } from "@services/letterService"; | ||
|
||
export const useLetterPost = () => { | ||
const [letterContent, setLetterContent] = useState(""); | ||
const [receiverInfo, setReceiverInfo] = useState({ | ||
year: "", | ||
monthDay: "", | ||
time: "", | ||
phoneNumber: "", | ||
}); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = async () => { | ||
if ( | ||
!letterContent || | ||
!receiverInfo.year || | ||
!receiverInfo.monthDay || | ||
!receiverInfo.time || | ||
!receiverInfo.phoneNumber | ||
) { | ||
toast.error("모든 필수 정보를 입력해 주세요!"); | ||
return; | ||
} | ||
|
||
const sendAt = `${receiverInfo.year}-${receiverInfo.monthDay}T${receiverInfo.time}`; | ||
const letterData = { | ||
letter: letterContent, | ||
receivePhone: receiverInfo.phoneNumber, | ||
sendAt: sendAt, | ||
}; | ||
|
||
try { | ||
const response = await letterService(letterData); | ||
toast.success("편지가 성공적으로 제출되었습니다!"); | ||
navigate("/inventory"); | ||
} catch (error) { | ||
toast.error("편지 제출에 실패했습니다. 다시 시도해 주세요."); | ||
console.error("Letter submission error:", error); | ||
} | ||
}; | ||
|
||
return { | ||
letterContent, | ||
setLetterContent, | ||
receiverInfo, | ||
setReceiverInfo, | ||
handleSubmit, | ||
}; | ||
}; |
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,37 @@ | ||
import { useState } from "react"; | ||
import { loginService } from "@services/loginService"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export const useLogin = () => { | ||
const [loginData, setLoginData] = useState({ | ||
phone: "", | ||
nickname: "", | ||
password: "", | ||
}); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleChange = (e) => { | ||
const { name, value } = e.target; | ||
setLoginData((prevData) => ({ | ||
...prevData, | ||
[name]: value, | ||
})); | ||
}; | ||
|
||
const handleSubmit = async () => { | ||
try { | ||
const response = await loginService(loginData); | ||
console.log("Login successful:", response); | ||
navigate("/homepage"); | ||
} catch (error) { | ||
console.error("Login error:", error); | ||
} | ||
}; | ||
|
||
return { | ||
loginData, | ||
handleChange, | ||
handleSubmit, | ||
}; | ||
}; |
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,46 @@ | ||
import { useState } from "react"; | ||
import { signupService } from "@services/signupService"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export const useSignup = () => { | ||
const [signupData, setSignupData] = useState({ | ||
nickname: "", | ||
password: "", | ||
confirmPassword: "", | ||
phone: "", | ||
}); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleChange = (e) => { | ||
const { name, value } = e.target; | ||
setSignupData((prevData) => ({ | ||
...prevData, | ||
[name]: value, | ||
})); | ||
}; | ||
|
||
const handleSubmit = async () => { | ||
if (signupData.password !== signupData.confirmPassword) { | ||
alert("비밀번호가 일치하지 않습니다."); | ||
return; | ||
} | ||
|
||
const { nickname, password, phone } = signupData; | ||
const signupPayload = { nickname, password, phone }; | ||
|
||
try { | ||
const response = await signupService(signupPayload); | ||
console.log("회원 가입 성공:", response); | ||
navigate("/homepage"); | ||
} catch (error) { | ||
console.error("회원 가입 에러:", error); | ||
} | ||
}; | ||
|
||
return { | ||
signupData, | ||
handleChange, | ||
handleSubmit, | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
// LoginPage.jsx | ||
import React from "react"; | ||
import * as S from "./styled"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useLogin } from "@hooks/useLogin"; | ||
|
||
export const LoginPage = () => { | ||
const { loginData, handleChange, handleSubmit } = useLogin(); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<S.Wrapper> | ||
<S.MainText>내일의 편지</S.MainText> | ||
<S.Login>로그인</S.Login> | ||
<S.Section> | ||
<S.MainText>본인의 별명을 입력해 주세요.</S.MainText> | ||
<S.Rowing> | ||
<input | ||
type="text" | ||
name="nickname" | ||
value={loginData.nickname} | ||
onChange={handleChange} | ||
placeholder="닉네임" | ||
style={{ background: "inherit", outline: "none" }} | ||
/> | ||
</S.Rowing> | ||
</S.Section> | ||
<S.Section> | ||
<S.MainText>본인의 비밀번호를 입력해 주세요.</S.MainText> | ||
<S.Rowing> | ||
<input | ||
type="password" | ||
name="password" | ||
value={loginData.password} | ||
onChange={handleChange} | ||
placeholder="비밀번호" | ||
style={{ background: "inherit", outline: "none" }} | ||
/> | ||
</S.Rowing> | ||
</S.Section> | ||
<S.Buttons> | ||
<S.Button onClick={() => navigate(-1)}>돌아가기</S.Button> | ||
<S.Button onClick={handleSubmit}>완료</S.Button> | ||
</S.Buttons> | ||
</S.Wrapper> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default LoginPage; | ||
export default LoginPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as S from "./styled"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export const IntroPage = () => { | ||
const navigate = useNavigate(); | ||
return ( | ||
<S.Wrapper> | ||
<S.MainText>내일의 편지</S.MainText> | ||
<S.Login onClick={() => navigate("/login")}>로그인</S.Login> | ||
<S.Login onClick={() => navigate("/signup")}>회원가입</S.Login> | ||
</S.Wrapper> | ||
) | ||
} | ||
|
||
export default IntroPage; |
Oops, something went wrong.