diff --git a/FE/issue-tracker/src/components/login/LoginMain.tsx b/FE/issue-tracker/src/components/login/LoginMain.tsx index 86bbbb2b7..4cf34b93b 100644 --- a/FE/issue-tracker/src/components/login/LoginMain.tsx +++ b/FE/issue-tracker/src/components/login/LoginMain.tsx @@ -1,31 +1,88 @@ +import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import styled from 'styled-components'; +import queryString from 'query-string'; import { Button } from '@chakra-ui/button'; import { Stack } from '@chakra-ui/layout'; import { Input } from '@chakra-ui/input'; +import { LinkBox, LinkOverlay } from '@chakra-ui/react'; import { ReactComponent as LogoLarge } from '@assets/LogotypeLarge.svg'; -import { gitLoginStyle, idLoginStyle, inputStyle } from './style'; +import { LOGIN_URL } from '@const/var'; +import fetchToken from './getAccessToken'; +import { + gitLoginStyle, + activeLoginStyle, + inactiveLoginStyle, + inputStyle, +} from './style'; function LoginMain() { + const [isLoginActive, setIsActiveLogin] = useState(false); + const [isInputtedID, setIsInputtedID] = useState(false); + const [isInputtedPW, setIsInputtedPW] = useState(false); + const [isLogin, setIsLogin] = useState(false); + const [password, setPassword] = useState(''); + + const handleChangeID = (e: React.ChangeEvent) => { + const target = e.target as HTMLInputElement; + if (!isInputtedID && target.value.length > 0) setIsInputtedID(true); + else if (isInputtedID && target.value.length === 0) setIsInputtedID(false); + }; + + const handleChangePW = (e: React.ChangeEvent) => { + const target = e.target as HTMLInputElement; + target.value.length > 0 ? setPassword(target.value) : setPassword(''); + if (!isInputtedPW && target.value.length > 0) setIsInputtedPW(true); + else if (isInputtedPW && target.value.length === 0) setIsInputtedPW(false); + }; + + useEffect(() => { + if (isInputtedID && isInputtedPW) setIsActiveLogin(true); + else setIsActiveLogin(false); + }, [isInputtedID, isInputtedPW]); + + useEffect(() => { + const { code } = queryString.parse(window.location.search); + if (!code) return; + else if (typeof code === 'string') { + fetchToken({ isLogin, setIsLogin, code }); + } + }, []); + return ( - + + + or - - + + - + {isLoginActive ? ( + + ) : ( + + )} 회원가입 ); } +export default LoginMain; + const MainWrap = styled.div` display: flex; flex-direction: column; @@ -50,5 +107,3 @@ const Register = styled.button` font-size: ${({ theme }) => theme.fontSizes.xs}; font-weight: ${({ theme }) => theme.fontWeights.bold}; `; - -export default LoginMain;