diff --git a/src/components/UserProfile/index.tsx b/src/components/UserProfile/index.tsx index a8bcc3e..b4d3c77 100644 --- a/src/components/UserProfile/index.tsx +++ b/src/components/UserProfile/index.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import history from '../../utils/browserHistory'; import { ProfileBox, @@ -8,7 +9,8 @@ import { FieldBox, Field, FieldA, - Star, + FieldLink, + Btn, } from './style'; type userProfileProps = { @@ -24,9 +26,9 @@ function UserProfile({ _id, id, nickname }: userProfileProps) { - + history.push(`/users/${_id}`)}> {id} - + {nickname ? ( πŸŽ™οΈ : ?? 성별 : ?? - alert('아직 κ΅¬ν˜„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.')}>β˜… + alert('아직 κ΅¬ν˜„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.')}>β˜… + alert('아직 κ΅¬ν˜„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.')} + isChcek + > + ↻ + ); } diff --git a/src/components/UserProfile/style.ts b/src/components/UserProfile/style.ts index 385295f..e247ed7 100644 --- a/src/components/UserProfile/style.ts +++ b/src/components/UserProfile/style.ts @@ -1,5 +1,4 @@ import styled from 'styled-components'; -import {Link} from 'react-router-dom'; export const ProfileBox = styled.div` display: flex; @@ -25,11 +24,11 @@ export const Image = styled.div` display: flex; justify-content: center; align-items: center; - - background-color: #8429F0; + + background-color: #8429f0; border-radius: 150px; - + width: 100px; height: 100px; @@ -39,8 +38,8 @@ export const Image = styled.div` export const BoxDivider = styled.div` width: 1px; height: 80%; - - background-color: #FFFAFA; + + background-color: #fffafa; `; export const FieldBox = styled.div` @@ -48,31 +47,33 @@ export const FieldBox = styled.div` display: flex; flex-direction: column; - align-items: flex-start; + align-items: flex-start; padding: 10px; `; export const Field = styled.div` font-size: 16px; - color: #FFFAFA; + color: #fffafa; `; export const FieldA = styled.a` - font-size: 18px; - color: #FFFAFA; + color: #fffafa; `; -export const FieldLink = styled(Link)` - font-size: 18px; +export const FieldLink = styled.div` + font-size: 16px; + color: #fffafa; + + cursor: pointer; `; -export const Star = styled.div<{isChcek?: boolean}>` +export const Btn = styled.div<{ isChcek?: boolean }>` position: absolute; top: 2px; right: 5px; font-size: 25px; - color: ${(props) => (props.isChcek ? "#FEB82E":"#000")}; + color: ${(props) => (props.isChcek ? '#FEB82E' : '#000')}; opacity: 0.3; cursor: pointer; -`; \ No newline at end of file +`; diff --git a/src/container/riot/index.ts b/src/container/riot/index.ts index 5fa4af9..16f28d6 100644 --- a/src/container/riot/index.ts +++ b/src/container/riot/index.ts @@ -1,17 +1,16 @@ import callApi from '../../utils/api'; -// [bad] - -export type getSummonerRes = { - id: string, - accountId: string, - puuid: string, - name: string, - profileIconId: number, - revisionDate: number, - summonerLevel: number +export type updateLolInfoProps = { + result: 1 | -1; + idx: string; + id: string; + nickname: string; + profileImageUrl: string; + lolTear: string; + lolLevel: string; + lolLane: string; + lolChampion: string; }; -export const getSummoner = function(nickname: string) { - const url = `https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/${nickname}?api_key=${process.env.REACT_APP_RIOT_API_KEY}`; - return callApi.get<{}, getSummonerRes>(url); +export const updateLolInfo = function (idx: string) { + return callApi.get<{}, updateLolInfoProps>(`users/lolInfo/${idx}`); }; diff --git a/src/container/users/index.ts b/src/container/users/index.ts index 2eb2628..3d2b7c1 100644 --- a/src/container/users/index.ts +++ b/src/container/users/index.ts @@ -1,6 +1,7 @@ import callApi from '../../utils/api'; import callCookie from '../../utils/cookie'; +// login export type loginReq = { id: string; password: String; @@ -21,10 +22,22 @@ export const login = async function (req: loginReq) { return res; }; -export type signupReq = {}; -export type signupRes = {}; -export const signup = function () {}; +// signup +export type signupReq = { + id: string; + password: string; + nickname: string; +}; +export type signupRes = { + result: 1 | -1; + message: string; +}; +export const signup = async function (req: signupReq) { + const res = await callApi.post('users/signup', req); + return res; +}; +// confirmEmail export type confirmEmailRes = { result: 1 | -1; message: string; @@ -36,6 +49,7 @@ export const confirmEmail = async function (key: string) { return res; }; +// allget export type allgetRes = { _id: string; id: string; @@ -47,6 +61,7 @@ export const allget = function () { return callApi.get<{}, [allgetRes]>('users/test'); }; +// getByIdx export type getByIdxRes = { result: 1 | -1; idx: string; diff --git a/src/container/users/verify.ts b/src/container/users/verify.ts new file mode 100644 index 0000000..566fe2d --- /dev/null +++ b/src/container/users/verify.ts @@ -0,0 +1,41 @@ +import { loginReq, signupReq } from '.'; + +interface signupVerifyProps extends signupReq { + rPassword: string; +} +export const signupVerify = (req: signupVerifyProps) => { + if (req.id && req.password && req.nickname && req.rPassword) + return { result: -1, message: 'ν•„μˆ˜ μž…λ ₯칸이 λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€.' }; + if ( + !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test( + req.id, + ) + ) + return { result: -1, message: '이메일 ν˜•μ‹μ΄ μ•„λ‹™λ‹ˆλ‹€.' }; + if ( + !/(?=.*\d{1,50})(?=.*[~`!@#$%&*()-+=]{1,50})(?=.*[a-zA-Z]{1,50}).{8,50}$/.test( + req.password, + ) + ) + return { + result: -1, + message: + 'λΉ„λ°€λ²ˆν˜ΈλŠ” 숫자, 영문, 특수문자λ₯Ό ν¬ν•¨ν•˜λ©°, 8자리 이상 이여야 ν•©λ‹ˆλ‹€.', + }; + if (req.password !== req.rPassword) + return { result: -1, message: 'λΉ„λ°€λ²ˆν˜Έ λ‘κ°œκ°€ λ‹€λ¦…λ‹ˆλ‹€.' }; + + return { result: 1, message: '' }; +}; + +export const loginVerify = (req: loginReq) => { + if (req.id && req.password) + return { result: -1, message: 'ν•„μˆ˜ μž…λ ₯칸이 λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€.' }; + if ( + !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test( + req.id, + ) + ) + return { result: -1, message: '이메일 ν˜•μ‹μ΄ μ•„λ‹™λ‹ˆλ‹€.' }; + return { result: 1, message: '' }; +}; diff --git a/src/pages/ConfirmEmail/style.ts b/src/pages/ConfirmEmail/style.ts index 3b15b9e..878bc5e 100644 --- a/src/pages/ConfirmEmail/style.ts +++ b/src/pages/ConfirmEmail/style.ts @@ -44,14 +44,14 @@ export const SlothVideo = styled.video` export const Btn = styled.div` color: #fff; font-size: 20px; - + height: 40px; transition: all 0.2s; cursor: pointer; - - &:hover{ + + &:hover { font-size: 22px; - } -`; \ No newline at end of file + } +`; diff --git a/src/pages/Enpty/style.ts b/src/pages/Enpty/style.ts index 2823363..b8ff713 100644 --- a/src/pages/Enpty/style.ts +++ b/src/pages/Enpty/style.ts @@ -4,21 +4,20 @@ import Page from '../pageStyle'; export const EnptyPage = styled.div` ${Page} - + display: flex; flex-direction: column; justify-content: space-around; align-items: center; `; - export const ErrorCodeText = styled.div` - color: #F2A663; + color: #f2a663; font-size: 30px; `; export const HmmText = styled.div` - color: #F2A663; + color: #f2a663; font-size: 300px; - font-weight: bold + font-weight: bold; `; diff --git a/src/pages/Login/LoginForm/index.tsx b/src/pages/Login/LoginForm/index.tsx index ad55cd8..c9cdcb4 100644 --- a/src/pages/Login/LoginForm/index.tsx +++ b/src/pages/Login/LoginForm/index.tsx @@ -11,6 +11,7 @@ import { import Illusion from '../../../utils/Illusion'; import { login } from '../../../container/users'; +import { loginVerify } from '../../../container/users/verify'; import callCookie from '../../../utils/cookie'; import history from '../../../utils/browserHistory'; @@ -47,25 +48,26 @@ const LoginForm = ({ onTyping }: loginFormProps) => { target.disabled = true; target.classList.add('on'); - const res = await login({ id: email, password }); - - if (res?.result === -1) { - setLoginField({ - email: '', - password: '', - }); - - alert('νšŒμ›μ΄ μ•„λ‹Œ μ΄λ©”μΌμ΄κ±°λ‚˜, λΉ„λ°€λ²ˆν˜Έκ°€ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.'); + const verify = loginVerify({ id: email, password }); + if (verify.result === -1) { + alert(verify.message); target.disabled = false; target.classList.remove('on'); - return; } + const res = await login({ id: email, password }); setLoginField({ email: '', password: '', }); + target.disabled = false; + target.classList.remove('on'); + + if (res?.result === -1) { + alert('νšŒμ›μ΄ μ•„λ‹Œ μ΄λ©”μΌμ΄κ±°λ‚˜, λΉ„λ°€λ²ˆν˜Έκ°€ ν‹€λ ΈμŠ΅λ‹ˆλ‹€.'); + return; + } history.push('/main'); }; @@ -100,10 +102,14 @@ const LoginForm = ({ onTyping }: loginFormProps) => { - νšŒμ›κ°€μž… + history.push('/signup')}> + νšŒμ›κ°€μž… + - 아이디 / λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ° + history.push('/find')}> + 아이디 / λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ° + diff --git a/src/pages/Login/LoginForm/style.ts b/src/pages/Login/LoginForm/style.ts index aedf58a..6af3a30 100644 --- a/src/pages/Login/LoginForm/style.ts +++ b/src/pages/Login/LoginForm/style.ts @@ -1,5 +1,4 @@ import styled from 'styled-components'; -import { Link }from 'react-router-dom' export const Container = styled.div` display: flex; @@ -9,7 +8,6 @@ export const Container = styled.div` border-radius: 12px; - width: 420px; // background-color: #FFF; @@ -17,7 +15,7 @@ export const Container = styled.div` export const Input = styled.input` margin-bottom: 8px; - + border: solid 1px #dadada; border-radius: 6px; @@ -25,12 +23,12 @@ export const Input = styled.input` width: 90%; height: 45px; - + font-size: 16px; - background: #FFFAFA; + background: #fffafa; - &:focus{ + &:focus { outline: none; } `; @@ -41,10 +39,9 @@ export const InputName = styled.div` width: 15%; margin-right: 3%; - color: #FFFAFA; + color: #fffafa; `; - export const LinkContainer = styled.div` display: flex; @@ -59,23 +56,24 @@ export const LinkContainer = styled.div` box-sizing: border-box; `; -export const SignupLink = styled(Link)` - color: #0C0000; +export const SignupLink = styled.div` + color: #0c0000; opacity: 0.6; text-decoration: none; + cursor: pointer; `; -export const FindLink = styled(Link)` +export const FindLink = styled.div` margin-left: auto; - color: #0C0000; + color: #0c0000; opacity: 0.6; - + text-decoration: none; + cursor: pointer; `; - export const LoginBtn = styled.button` margin-top: 60px; @@ -85,16 +83,16 @@ export const LoginBtn = styled.button` width: 420px; height: 100px; - color: #FFFAFA; + color: #fffafa; font-size: 50px; font-weight: bold; - background-color: #F2A663; + background-color: #f2a663; cursor: pointer; - &.on{ - background-color: #D99559; - color: #E6E1E1; + &.on { + background-color: #d99559; + color: #e6e1e1; } -`; \ No newline at end of file +`; diff --git a/src/pages/Login/style.ts b/src/pages/Login/style.ts index 673c987..c829574 100644 --- a/src/pages/Login/style.ts +++ b/src/pages/Login/style.ts @@ -18,7 +18,7 @@ export const ForwardPage = styled.div` width: 100%; height: 100%; - + z-index: 1; `; @@ -28,19 +28,17 @@ export const DuoTitle = styled.div` font-size: 15vw; font-weight: bold; - color: #944E61; + color: #944e61; `; - const fadeinAnimation = keyframes` from { opacity: 0; } to { opacity: 1; } -` +`; export const Fadein = styled.div` width: 100%; height: 100%; animation: ${fadeinAnimation} 2s; animation-fill-mode: forwards; -` - +`; diff --git a/src/pages/Signup/SignupForm/index.tsx b/src/pages/Signup/SignupForm/index.tsx index 019a9fa..160847b 100644 --- a/src/pages/Signup/SignupForm/index.tsx +++ b/src/pages/Signup/SignupForm/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from 'react'; +import React, { useState } from 'react'; import { Container, Input, @@ -8,18 +8,10 @@ import { SignupBtn, } from './style'; -import callApi from '../../../utils/api'; -import history from '../../../utils/browserHistory'; +import { signup } from '../../../container/users'; +import { signupVerify } from '../../../container/users/verify'; -type signupReq = { - id: string; - password: string; - nickname: string; -}; -type signupRes = { - result: 1 | -1; - message: string; -}; +import history from '../../../utils/browserHistory'; function SignupForm() { const [signupField, setSignupField] = useState({ @@ -29,8 +21,6 @@ function SignupForm() { nickname: '', }); - const signupBtn = useRef({} as HTMLButtonElement); - const { email, password, rPassword, nickname } = signupField; const changeState = (e: React.ChangeEvent) => { @@ -42,61 +32,45 @@ function SignupForm() { }); }; - const signup = async function () { - signupBtn.current.disabled = true; - signupBtn.current.classList.add('on'); - // console.log(res); + const onClickSignupBtn = async function ( + e: React.MouseEvent, + ) { + const target = e.currentTarget; + target.disabled = true; + target.classList.add('on'); - if (!(email && password && nickname && rPassword)) { - alert('ν•„λ“œκ°€ λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€.'); - signupBtn.current.disabled = false; - signupBtn.current.classList.remove('on'); - return; - } - if (password !== rPassword) { - alert('λΉ„λ°€λ²ˆν˜Έκ°€ λ‹€λ¦…λ‹ˆλ‹€.'); - signupBtn.current.disabled = false; - signupBtn.current.classList.remove('on'); + const verify = signupVerify({ + id: email, + password, + rPassword, + nickname, + }); + if (verify.result === -1) { + alert(verify.message); + target.disabled = false; + target.classList.remove('on'); return; } - if ( - !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test( - email, - ) - ) { - alert('이메일 ν˜•μ‹μ΄ μ•„λ‹™λ‹ˆλ‹€.'); - signupBtn.current.disabled = false; - signupBtn.current.classList.remove('on'); - } - const res = await callApi.post('users/signup', { + const res = await signup({ id: email, password, nickname, }); - if (res?.result === -1) { - setSignupField({ - email: '', - password: '', - rPassword: '', - nickname: '', - }); - - alert('이미 μžˆλŠ” μ΄λ©”μΌμž…λ‹ˆλ‹€.'); - - signupBtn.current.disabled = false; - signupBtn.current.classList.remove('on'); - - return; - } - setSignupField({ email: '', password: '', rPassword: '', nickname: '', }); + target.disabled = false; + target.classList.remove('on'); + + if (res?.result === -1) { + alert('이미 μžˆλŠ” μ΄λ©”μΌμž…λ‹ˆλ‹€.'); + return; + } alert('νšŒμ›κ°€μž…μ΄ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.'); @@ -138,10 +112,12 @@ function SignupForm() { /> - 둜그인 - 아이디 / λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ° + history.push('/login')}>둜그인 + history.push('/find')}> + 아이디 / λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ° + - + Signup ! diff --git a/src/pages/Signup/SignupForm/style.ts b/src/pages/Signup/SignupForm/style.ts index 5bca4e7..66c2f49 100644 --- a/src/pages/Signup/SignupForm/style.ts +++ b/src/pages/Signup/SignupForm/style.ts @@ -1,5 +1,4 @@ import styled from 'styled-components'; -import { Link }from 'react-router-dom' export const Container = styled.div` display: flex; @@ -9,7 +8,6 @@ export const Container = styled.div` border-radius: 12px; - width: 420px; // background-color: #FFF; @@ -17,7 +15,7 @@ export const Container = styled.div` export const Input = styled.input` margin-bottom: 8px; - + border: solid 1px #dadada; border-radius: 6px; @@ -25,12 +23,12 @@ export const Input = styled.input` width: 90%; height: 45px; - + font-size: 16px; - background: #FFFAFA; + background: #fffafa; - &:focus{ + &:focus { outline: none; } `; @@ -41,10 +39,9 @@ export const InputName = styled.div` width: 15%; margin-right: 3%; - color: #FFFAFA; + color: #fffafa; `; - export const LinkContainer = styled.div` display: flex; @@ -59,23 +56,24 @@ export const LinkContainer = styled.div` box-sizing: border-box; `; -export const LoginLink = styled(Link)` - color: #0C0000; +export const LoginLink = styled.div` + color: #0c0000; opacity: 0.6; text-decoration: none; + cursor: pointer; `; -export const FindLink = styled(Link)` +export const FindLink = styled.div` margin-left: auto; - color: #0C0000; + color: #0c0000; opacity: 0.6; - + text-decoration: none; + cursor: pointer; `; - export const SignupBtn = styled.button` margin-top: 60px; @@ -85,16 +83,16 @@ export const SignupBtn = styled.button` width: 420px; height: 100px; - color: #FFFAFA; + color: #fffafa; font-size: 50px; font-weight: bold; - background-color: #F2A663; + background-color: #f2a663; cursor: pointer; - &.on{ - background-color: #D99559; - color: #E6E1E1; + &.on { + background-color: #d99559; + color: #e6e1e1; } -`; \ No newline at end of file +`; diff --git a/src/pages/Signup/style.ts b/src/pages/Signup/style.ts index 7c4e14d..95e19a0 100644 --- a/src/pages/Signup/style.ts +++ b/src/pages/Signup/style.ts @@ -10,13 +10,11 @@ export const SignupPage = styled.div` align-items: center; `; - export const DuoTitle = styled.div` margin-bottom: 50px; font-size: 30vh; font-weight: bold; - color: #F2A663; + color: #f2a663; `; - diff --git a/src/pages/Studio/style.ts b/src/pages/Studio/style.ts index bcc584f..21882a4 100644 --- a/src/pages/Studio/style.ts +++ b/src/pages/Studio/style.ts @@ -9,7 +9,6 @@ export const StudioPage = styled.div` overflow: hidden; `; - export const WaitingBnt = styled.div` position: absolute; diff --git a/src/utils/api.ts b/src/utils/api.ts index e18e2e2..ef0767e 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -3,9 +3,7 @@ import callCookie from './cookie'; type fetchMethod = 'get' | 'post' | 'put' | 'delete'; -const errorHandling = async function ( - response: Response, -): Promise { +const errorHandling = async function (response: Response): Promise { const { text, ok, status } = response; if (!ok) { @@ -55,10 +53,10 @@ const callApiBase = async function ( method: fetchMethod, body: I | undefined = undefined, ): Promise { - let serverUrl = process.env.REACT_APP_API_URL || 'http://localhost:5000'; - if(url.indexOf("http://") !== -1 || url.indexOf("https://") !== -1) serverUrl = ""; + if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) + serverUrl = ''; const response: Response = await callFetch( `${serverUrl}${url}`, @@ -75,7 +73,8 @@ const callApiBase = async function ( }; export default { - get: (url: string): Promise => callApiBase(url, 'get'), + get: (url: string): Promise => + callApiBase(url, 'get'), post: (url: string, body: I): Promise => callApiBase(url, 'post', body), put: (url: string, body: I): Promise => diff --git a/src/utils/browserHistory.ts b/src/utils/browserHistory.ts index c0ac126..dc8a432 100644 --- a/src/utils/browserHistory.ts +++ b/src/utils/browserHistory.ts @@ -1,5 +1,5 @@ import { createBrowserHistory } from 'history'; export default createBrowserHistory({ - basename: process.env.PUBLIC_URL -}); \ No newline at end of file + basename: process.env.PUBLIC_URL, +}); diff --git a/src/utils/sessionStorage.ts b/src/utils/sessionStorage.ts index b4827b9..47818cf 100644 --- a/src/utils/sessionStorage.ts +++ b/src/utils/sessionStorage.ts @@ -1,8 +1,6 @@ - - - export default { delete: (name: string): void => sessionStorage.removeItem(name), - set: (name: string, value: string): void => sessionStorage.setItem(name, value), - get: (name: string): string => sessionStorage.getItem(name) || '' -}; \ No newline at end of file + set: (name: string, value: string): void => + sessionStorage.setItem(name, value), + get: (name: string): string => sessionStorage.getItem(name) || '', +};