diff --git a/src/common/apis/member.tsx b/src/common/apis/member.tsx index a05ce40..53dc735 100644 --- a/src/common/apis/member.tsx +++ b/src/common/apis/member.tsx @@ -33,4 +33,9 @@ export const handleKakaoLogin = () => location.href = `${import.meta.env.VITE_SERVER_URL}/oauth2/authorization/kakao`; export const getProfile = async () => - await axiosApi.get("/member/profile"); \ No newline at end of file + await axiosApi.get("/member/profile"); + +export const updateUsername = async (username: string) => + await axiosApi.post("/member/username", { + username: username, + }); \ No newline at end of file diff --git a/src/common/slices/loginSlice.tsx b/src/common/slices/loginSlice.tsx index 6b84a14..5e2ec99 100644 --- a/src/common/slices/loginSlice.tsx +++ b/src/common/slices/loginSlice.tsx @@ -1,11 +1,11 @@ import {createSlice} from "@reduxjs/toolkit"; const initialState = { - isLogin: true, - accessToken: "token", - email: "diglog@example.com", - username: "diglog", - roles: ["ROLE_USER"], + isLogin: false, + accessToken: "", + email: "", + username: "", + roles: [], } const loginSlice = createSlice({ diff --git a/src/common/util/regex.tsx b/src/common/util/regex.tsx index fc95398..a66be20 100644 --- a/src/common/util/regex.tsx +++ b/src/common/util/regex.tsx @@ -1,10 +1,11 @@ export const checkEmail = (email: string) => { const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - return email !== "" && email.match(regex); + + return !!(email !== "" && email.match(regex)); } export const checkPassword = (password: string) => { const regex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d\W_]{8,16}$/; - return password !== "" && password.match(regex); + return !!(password !== "" && password.match(regex)); } \ No newline at end of file diff --git a/src/components/member/LoginButton.tsx b/src/components/member/LoginButton.tsx index 3167e69..640398f 100644 --- a/src/components/member/LoginButton.tsx +++ b/src/components/member/LoginButton.tsx @@ -1,17 +1,17 @@ import {ReactNode} from "react"; -function LoginButton({text, onClick, bgColor, icon}: { +function LoginButton({text, onClick, bgColor, disable, icon}: { text: string, onClick: () => void, bgColor: string, + disable?: boolean, icon?: ReactNode }) { return ( ); } diff --git a/src/components/member/LoginTextField.tsx b/src/components/member/LoginTextField.tsx index e41c4d2..7ac5131 100644 --- a/src/components/member/LoginTextField.tsx +++ b/src/components/member/LoginTextField.tsx @@ -1,11 +1,13 @@ import * as React from "react"; -function LoginTextField({label, type, placeholder, value, setValue, onKeyDown}: { +function LoginTextField({label, type, placeholder, value, setValue, error, isError, onKeyDown}: { label?: string, type: string, placeholder: string, value: string, setValue: (value: string) => void, + error?: string, + isError?: boolean, onKeyDown?: (event: React.KeyboardEvent) => void, }) { return ( @@ -19,6 +21,11 @@ function LoginTextField({label, type, placeholder, value, setValue, onKeyDown}: value={value} onChange={(event => setValue(event.target.value))} onKeyDown={onKeyDown}/> + {(error) && ( + isError ? +

{error}

+ :
+ )}
); } diff --git a/src/layout/LoadingLayout.tsx b/src/layout/LoadingLayout.tsx index 36509ef..0dfa856 100644 --- a/src/layout/LoadingLayout.tsx +++ b/src/layout/LoadingLayout.tsx @@ -3,7 +3,7 @@ function LoadingLayout({loading}: { loading: boolean }) { return ( loading &&
+ className="fixed inset-0 flex items-center justify-center bg-gray-300 opacity-50 z-1000 dark:bg-gray-100 dark:bg-opacity-50">
+ ); } diff --git a/src/pages/member/SignupPage.tsx b/src/pages/member/SignupPage.tsx index b5aa726..75a0f7a 100644 --- a/src/pages/member/SignupPage.tsx +++ b/src/pages/member/SignupPage.tsx @@ -6,6 +6,7 @@ import {checkPassword} from "../../common/util/regex.tsx"; import LoadingLayout from "../../layout/LoadingLayout.tsx"; import * as React from "react"; import LoginButton from "../../components/member/LoginButton.tsx"; +import {signup} from "../../common/apis/member.tsx"; function SignupPage() { @@ -25,17 +26,29 @@ function SignupPage() { } const handleSignup = () => { - setLoading(true); - console.log(email, code); - - if (!checkPassword(passwordInfo.password) || passwordInfo.password !== passwordInfo.confirmPassword) { - setLoading(false); + if (!checkPassword(passwordInfo.password)) { + alert("비밀번호가 영문, 숫자 포함 8-16자리가 되도록 입력해주세요."); + return; + } + + if (passwordInfo.password !== passwordInfo.confirmPassword) { + alert("비밀번호 확인이 일치하지 않습니다."); return; } - alert("회원가입 되었습니다."); + setLoading(true); + + signup(email, passwordInfo.password, code) + .then(() => { + alert("회원가입 되었습니다."); + navigate("/login"); + }) + .catch((error) => alert(error.response.data.message)) + .finally(() => setLoading(false)); + } - navigate("/login"); + const disableSignupButton = () => { + return !checkPassword(passwordInfo.password) || (passwordInfo.password !== passwordInfo.confirmPassword); } return ( @@ -58,12 +71,11 @@ function SignupPage() { setValue={(value) => setPasswordInfo({...passwordInfo, confirmPassword: value})} onKeyDown={handlePasswordEnter}/>
- + - ) - ; + ); } export default SignupPage; \ No newline at end of file diff --git a/src/pages/setting/ProfileSettingPage.tsx b/src/pages/setting/ProfileSettingPage.tsx index 3c382d8..92942d4 100644 --- a/src/pages/setting/ProfileSettingPage.tsx +++ b/src/pages/setting/ProfileSettingPage.tsx @@ -6,6 +6,7 @@ import {ChangeEvent, useRef, useState} from "react"; import {FillButton} from "../../components/common/FillButton.tsx"; import {setUsername} from "../../common/slices/loginSlice.tsx"; import {TextButton} from "../../components/common/TextButton.tsx"; +import {updateUsername} from "../../common/apis/member.tsx"; function ProfileSettingPage() { @@ -13,7 +14,7 @@ function ProfileSettingPage() { const dispatch = useDispatch(); const fileInputRef = useRef(null); - const [input, setInput] = useState(""); + const [input, setInput] = useState(loginState.username); const [image, setImage] = useState(null); const [isUsernameEdit, setIsUsernameEdit] = useState(false); const [isImageEdit, setIsImageEdit] = useState(false); @@ -27,11 +28,18 @@ function ProfileSettingPage() { } const handleUsernameSubmit = () => { - alert("변경되었습니다."); - dispatch(setUsername({ - username: input, - })); - setIsUsernameEdit(false); + + updateUsername(input) + .then(() => { + alert("변경되었습니다."); + dispatch(setUsername({ + username: input, + })); + setIsUsernameEdit(false); + }) + .catch((error) => alert(error.response.data.message)) + .finally(() => { + }); } const handleImageEdit = () => {