Commit aa804067 authored by KangMin An's avatar KangMin An
Browse files

Merge branch 'who' into premaster

parents a7798fea 8d02df63
...@@ -74,7 +74,7 @@ body { ...@@ -74,7 +74,7 @@ body {
} }
#logpng { #logpng {
width: 50%; width: 100%;
height: 6em; height: 6em;
object-fit: cover; object-fit: cover;
} }
......
import React from 'react'; import React, { useEffect } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import './App.css'; import './App.css';
import Home from './pages/Home'; import Home from './pages/Home';
...@@ -8,9 +8,13 @@ import EditPage from './pages/EditPage'; ...@@ -8,9 +8,13 @@ import EditPage from './pages/EditPage';
import PrivateRoute from './utils/PrivateRoutes'; import PrivateRoute from './utils/PrivateRoutes';
import PageNotFound from './components/PageNotFound'; import PageNotFound from './components/PageNotFound';
import Footer from './components/Footer'; import Footer from './components/Footer';
import { checkCookies } from './utils/CheckDB';
function App() { function App() {
useEffect(() => {
localStorage.setItem('login', false)
}, [checkCookies()])
return ( return (
<Router> <Router>
......
import axios from 'axios'; import axios from 'axios';
import { checkCookies } from './CheckDB'; import { callUserInfo, checkCookies } from './CheckDB';
export function handleLogin({ userId, role, name, tel, email }) { export function haveLogined() {
localStorage.setItem('id', userId) callUserInfo().then((res) => {
localStorage.setItem('role', role) if (res && checkCookies()) {
localStorage.setItem('name', name) return true
localStorage.setItem('tel', tel) }
localStorage.setItem('email', email) else {
console.log('object')
console.log(res)
}
})
} }
export async function handleLogout() { export function isOauth(value) {
localStorage.clear() const TFoauth = value
await axios.get('/api/auth/logout') return TFoauth;
window.location.href = '/'
} }
export function isLogined() { export function isLogined() {
const userId = checkCookies() const whetherlogin = localStorage.getItem('login')
if (userId) { if (whetherlogin === 'false') {
return userId
} else {
return false return false
} }
} else {
export function isAdmin() {
const role = localStorage.getItem('role')
if (role === 'admin') {
return true return true
} else {
return false
} }
} }
export function logout() {
export function isOauth(value) { localStorage.setItem('login', false)
const TFoauth = value
return TFoauth;
} }
\ No newline at end of file
// export async function doeCode() {
// const response = await axios.get('http://175.125.254.72:8090/api/data/loccode')
// // console.log('res::', response.data.locCodes)
// const resData = response.data.locCodes
// const doe = resData.DOE
// // console.log('dd', doe) //object
// // console.log('dd::', doe[doe.length-1])
// // console.log('values::', Object.values(doe))
// const doeValue = Object.values(doe)
// // console.log('@@@11', doeValue[0]['code_doe'], typeof(doeValue[0]['code_doe']))
// // console.log('@@@22', doeValue[0]['name_doe'], typeof(doeValue[0]['name_doe']))
// return doeValue
// }
\ No newline at end of file
...@@ -38,96 +38,92 @@ function LocCodeChange() { ...@@ -38,96 +38,92 @@ function LocCodeChange() {
borderColor: 'rgba(195, 195, 195, 0.753)', borderColor: 'rgba(195, 195, 195, 0.753)',
} }
const [does, setDoes] = useState([]) const [does, setDoes] = useState([]) // DOE
const [sggs, setSggs] = useState([]) const [sggs, setSggs] = useState([]) // SGG
const [emds, setEmds] = useState([]) const [emds, setEmds] = useState([]) // EMD
const [sggsArray, setSggsArray] = useState([]) const [sggsArray, setSggsArray] = useState([]) // DOE 와 SGG 내의 code_doe 같을 때 => sgg 값
const [emdsArray, setEmdsArray] = useState([]) const [emdsArray, setEmdsArray] = useState([]) // SGG 과 EMD 내의 code_sgg && DOE 와 EMD 내의 code_doe => emd 값
const doeSelect = document.getElementById('select-doe') const doeSelect = document.getElementById('select-doe')
const sggSelect = document.getElementById('select-sgg') const sggSelect = document.getElementById('select-sgg')
const emdSelect = document.getElementById('select-emd') const emdSelect = document.getElementById('select-emd')
const saveCodeEmd = localStorage.getItem('code_emd') // Local code 받아오기
useEffect(() => {
async function handleClickLoc() {
if (doeSelect.options[doeSelect.selectedIndex].text !== '' && sggSelect.options[sggSelect.selectedIndex].text !== '시군구' && emdSelect.options[emdSelect.selectedIndex].text !== '읍면동') {
await axios.post('/api/edit-profile', { loc_code: saveCodeEmd })
.then(function (response) {
console.log('loc', response);
})
callUserInfo().then((res) => {
console.log('11', res[0])
})
localStorage.setItem('code_doe', doeSelect.value)
localStorage.setItem('name_doe', doeSelect.options[doeSelect.selectedIndex].text)
localStorage.setItem('code_sgg', sggSelect.value)
localStorage.setItem('name_sgg', sggSelect.options[sggSelect.selectedIndex].text)
localStorage.setItem('code_emd', emdSelect.value)
localStorage.setItem('name_emd', emdSelect.options[emdSelect.selectedIndex].text)
// if (localStorage.getItem('name_emd')) {
// Swal.fire({
// title: '변경되었습니다.',
// text: '축하드립니다!👏',
// icon: 'success',
// customClass: 'swal-wide',
// confirmButtonText: '확인',
// }).then((res) => {
// if (res.isConfirmed) {
// window.location.reload()
// }
// else {
// window.location.reload()
// }
// })
// }
}
// else {
// Swal.fire({
// title: '실패',
// text: '전부 선택해주세요',
// icon: 'error',
// customClass: 'swal-wide',
// confirmButtonText: '확인'
// })
// }
}
async function getLocCode() { async function getLocCode() {
const res = await axios.get("/api/data/loccode") const res = await axios.get("/api/data/loccode")
const local_codes = res.data.locCodes const local_codes = res.data.contents.loc_code
setDoes(local_codes.DOE) setDoes(local_codes.DOE)
setSggs(local_codes.SGG) setSggs(local_codes.SGG)
setEmds(local_codes.EMD) setEmds(local_codes.EMD)
} }
useEffect(() => {
getLocCode() getLocCode()
}, []) }, [])
function selectLocal() { function selectLocal() {
sggs.map(function (sggvalue) { sggs.map(function (sggvalue) {
if (doeSelect.value == sggvalue['code_doe']) { if (Number(doeSelect.value) === sggvalue['code_doe']) {
setSggsArray(sggvalue['sgg']) setSggsArray(sggvalue['sgg'])
} }
}) })
emds.map(function (emdvalue) { emds.map(function (emdvalue) {
if (sggSelect.value == emdvalue['code_sgg'] && doeSelect.value == emdvalue['code_doe']) { if ((Number(sggSelect.value) === emdvalue['code_sgg'])
&& (Number(doeSelect.value) === emdvalue['code_doe'])) {
setEmdsArray(emdvalue['emd']) setEmdsArray(emdvalue['emd'])
} }
})
}
async function handleSubmit(event) {
event.preventDefault()
if (doeSelect.options[doeSelect.selectedIndex].text !== ''
&& sggSelect.options[sggSelect.selectedIndex].text !== '시군구'
&& emdSelect.options[emdSelect.selectedIndex].text !== '읍면동') {
const saveCodeEmd = emdSelect.value
console.log(saveCodeEmd)
await axios.post('/api/edit-profile', { loc_code: saveCodeEmd }) // loccal code 수정
callUserInfo().then((res) => {
console.log('loc_code', res[0].loc_code)
if (res[0].loc_code) {
Swal.fire({
title: '변경되었습니다.',
text: '축하드립니다!👏',
icon: 'success',
customClass: 'swal-wide',
confirmButtonText: '확인',
}).then((res) => {
if (res.isConfirmed) {
window.location.reload()
}
else { else {
return false window.location.reload()
}
})
}
})
} }
else {
Swal.fire({
title: '실패',
text: '전부 선택해주세요',
icon: 'error',
customClass: 'swal-wide',
confirmButtonText: '확인'
}) })
} }
}
return ( return (
...@@ -141,13 +137,13 @@ function LocCodeChange() { ...@@ -141,13 +137,13 @@ function LocCodeChange() {
</Card.Subtitle> </Card.Subtitle>
<hr /> <hr />
<Card.Text className='m-0'> <Card.Text className='m-0'>
<Form style={inboxstyled} onChange={selectLocal}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<Row md={12} xs={12} className='m-auto w-100 d-flex justify-content-center' style={{ padding: '0', display: 'flex', justifyContent: 'center', width: '100%' }}> <Row md={12} xs={12} className='m-auto w-100 d-flex justify-content-center' style={{ padding: '0', display: 'flex', justifyContent: 'center', width: '100%' }}>
<Form.Group className='m-auto w-100' style={btnstyled2}> <Form.Group className='m-auto w-100' style={btnstyled2} onChange={selectLocal}>
<Row className='m-auto pb-3'> <Row className='m-auto pb-3'>
<Col md={4} xs={4} style={{ padding: '2px' }}> <Col md={4} xs={4} style={{ padding: '2px' }}>
<Form.Control as='select' size="sm" id='select-doe'> <Form.Control as='select' size="sm" id='select-doe' required>
<option selected disabled></option> <option selected disabled></option>
{ {
does.map((doevalue) => ( does.map((doevalue) => (
...@@ -160,7 +156,7 @@ function LocCodeChange() { ...@@ -160,7 +156,7 @@ function LocCodeChange() {
</Col> </Col>
<Col md={4} xs={4} style={{ padding: '2px' }}> <Col md={4} xs={4} style={{ padding: '2px' }}>
<Form.Control as='select' size="sm" id='select-sgg'> <Form.Control as='select' size="sm" id='select-sgg' required>
<option selected disabled>시군구</option> <option selected disabled>시군구</option>
{ {
sggsArray.map((sggvalue) => ( sggsArray.map((sggvalue) => (
...@@ -173,7 +169,7 @@ function LocCodeChange() { ...@@ -173,7 +169,7 @@ function LocCodeChange() {
</Col> </Col>
<Col md={4} xs={4} style={{ padding: '2px' }}> <Col md={4} xs={4} style={{ padding: '2px' }}>
<Form.Control as='select' size="sm" id='select-emd'> <Form.Control as='select' size="sm" id='select-emd' required>
<option selected disabled>읍면동</option> <option selected disabled>읍면동</option>
{ {
emdsArray.map((emdvalue) => ( emdsArray.map((emdvalue) => (
...@@ -186,14 +182,12 @@ function LocCodeChange() { ...@@ -186,14 +182,12 @@ function LocCodeChange() {
</Col> </Col>
</Row> </Row>
</Form.Group> </Form.Group>
</Row>
</Form>
<Row className='d-flex justify-content-center'>
<Button <Button
variant='light' style={btnstyled2} onClick={handleClickLoc}> variant='light' style={btnstyled2} type='submit'>
확인 확인
</Button> </Button>
</Row> </Row>
</Form>
</Card.Text> </Card.Text>
</Card> </Card>
</Row> </Row>
......
...@@ -28,31 +28,18 @@ function LoginComp() { ...@@ -28,31 +28,18 @@ function LoginComp() {
color: 'black' color: 'black'
} }
const [emailSentAlert, setEmailSentAlert] = useState(false)
const [alertShow, setAlertShow] = useState(false) const [alertShow, setAlertShow] = useState(false)
const [emailAddress, setEmailAddress] = useState('') const [emailAddress, setEmailAddress] = useState('')
function CheckEmailSend() { const [mailSend, setMailSend] = useState(false)
localStorage.setItem('login_email_Address', emailAddress)
const emailIs = localStorage.getItem('login_email_Address').split('@')[1]
if (emailIs) {
setAlertShow(true)
setEmailSentAlert(false)
}
else {
setAlertShow(true)
setEmailSentAlert(true)
}
}
function addressUrl() { function addressUrl() {
const afterAt = localStorage.getItem('login_email_Address').split('@')[1] const afterAt = emailAddress.split('@')[1]
if (afterAt == ('naver.com' || 'gmail.com' || 'daum.net')) { if (afterAt == ('naver.com' || 'gmail.com' || 'daum.net')) {
const newLink = 'https://www.' + afterAt; const newLink = 'https://www.' + afterAt;
window.open(newLink); window.open(newLink);
} }
if (afterAt == 'korea.ac.kr' ) { if (afterAt == 'korea.ac.kr') {
window.open('https://www.gmail.com'); window.open('https://www.gmail.com');
} }
else { else {
...@@ -64,12 +51,13 @@ function LoginComp() { ...@@ -64,12 +51,13 @@ function LoginComp() {
setEmailAddress(event.target.value) setEmailAddress(event.target.value)
} }
console.log(emailAddress)
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
const res = await axios.post("/api/login", { email: emailAddress }) const res = await axios.post("/api/login", { email: emailAddress })
console.log(res) console.log('mail_sending : ', res.data.contents.mail_sending)
setMailSend(res.data.contents.mail_sending)
setAlertShow(true)
localStorage.setItem('login', true)
} }
...@@ -85,7 +73,7 @@ function LoginComp() { ...@@ -85,7 +73,7 @@ function LoginComp() {
<hr /> <hr />
<Card.Text> <Card.Text>
<Row className='m-auto d-flex justify-content-center' style={{ width: '80%' }}> <Row className='m-auto d-flex justify-content-center' style={{ width: '80%' }}>
{!emailSentAlert ? {mailSend ?
<Alert show={alertShow} variant={'success'}> <Alert show={alertShow} variant={'success'}>
<Col> <Col>
😍 이메일 전송이 완료 되었습니다. 😍 이메일 전송이 완료 되었습니다.
...@@ -107,13 +95,10 @@ function LoginComp() { ...@@ -107,13 +95,10 @@ function LoginComp() {
</Row> </Row>
<Form style={inboxstyled} onSubmit={handleSubmit}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<FloatingLabel <FloatingLabel label="Email">
label="Email" <Form.Control type="email" placeholder="Email" onChange={handleChange} required/>
>
<Form.Control type="email" placeholder="Email" onChange={handleChange} />
</FloatingLabel> </FloatingLabel>
<Button variant='light' className='mt-3' id='formbtn' onClick={CheckEmailSend} type='submit'> <Button variant='light' className='mt-3' id='formbtn' type='submit'>
LOGIN LOGIN
</Button> </Button>
</Form> </Form>
......
import React, { useEffect, useState } from 'react' import React from 'react'
import { Button, Image, Row, ButtonGroup, Form, Col } from 'react-bootstrap'; import { Button, Image, Row, ButtonGroup, Form, Col } from 'react-bootstrap';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import '../App.css' import '../App.css'
import UserInfo from './UserInfo'; import UserInfo from './UserInfo';
import { kakaoLogout } from '../utils/Oauth'; import { kakaoLogout } from '../utils/Oauth';
import axios from 'axios'; import UsingAircon from './UsingAircon';
import { callUserInfo, deleteCookie } from '../utils/CheckDB'; import { isLogined } from '../utils/Auth';
import { checkCookies } from '../utils/CheckDB';
function MainLayer() { function MainLayer() {
...@@ -36,42 +35,9 @@ function MainLayer() { ...@@ -36,42 +35,9 @@ function MainLayer() {
} }
const [airUsing, setAirUsing] = useState(false)
useEffect(() => {
callUserInfo().then((res) => {
if (res !== []) {
console.log(res[0])
}
else {
console.log(res)
}
})
}, [])
async function airChange() {
setAirUsing(!airUsing)
await axios.post('/api/edit-profile', { using_aircon: !airUsing })
.then(function (response) {
console.log('res', response);
callUserInfo().then((res) => {
if (res !== []) {
console.log(res[0])
}
else {
console.log(res)
}
})
})
.catch(function (error) {
console.log('err', error);
});
}
return ( return (
<Col> <Col>
<Row className='d-flex align-items-center m-auto w-100 p-0'> <Row className='d-flex align-items-center m-auto w-100 p-0'>
<Link to='/' className='p-0 m-auto'> <Link to='/' className='p-0 m-auto'>
...@@ -83,26 +49,16 @@ function MainLayer() { ...@@ -83,26 +49,16 @@ function MainLayer() {
<UserInfo /> <UserInfo />
</Row> </Row>
{checkCookies() && {isLogined() &&
<Form <UsingAircon/>
key='checkbox' className="d-flex justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}>
<Form.Check
type='switch'
id='airconditioner'
label='에어컨 사용중'
onChange={airChange}
checked={airUsing}
/>
</Form>
} }
<Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'> <Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'>
<ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}> <ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}>
{checkCookies() ? {isLogined() ?
//true //true
<Button variant='light' style={btnstyled} onClick={kakaoLogout}> <Button variant='light' style={btnstyled} onClick={kakaoLogout}>
{/* || deleteCookie('acs_token') */}
로그아웃 로그아웃
</Button> </Button>
: :
...@@ -114,7 +70,7 @@ function MainLayer() { ...@@ -114,7 +70,7 @@ function MainLayer() {
</Button> </Button>
} }
{!checkCookies() && {!isLogined() &&
<Button variant='light' style={btnstyled}> <Button variant='light' style={btnstyled}>
<Link to='/signup' id='btnlink'> <Link to='/signup' id='btnlink'>
회원가입 회원가입
......
import axios from 'axios'; import axios from 'axios';
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { Row, Card, Col, Form, Button, FloatingLabel } from 'react-bootstrap'; import { Row, Card, Col, Form, Button, FloatingLabel } from 'react-bootstrap';
import { callUserInfo } from '../utils/CheckDB'; import Swal from 'sweetalert2';
function NicknameChange() { function NicknameChange() {
...@@ -32,17 +32,31 @@ function NicknameChange() { ...@@ -32,17 +32,31 @@ function NicknameChange() {
function handleChange({ target: { value } }) { function handleChange({ target: { value } }) {
setInputname(value) setInputname(value)
} }
console.log(inputname)
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
if (inputname !== '') {
await axios.post('/api/edit-profile', { nick_name: inputname }) await axios.post('/api/edit-profile', { nick_name: inputname })
.then(function (response) { .then(function (response) {
console.log(response); console.log(response.data.msg);
if (response.data.msg === 'OK!') {
Swal.fire({
title: '변경되었습니다.',
text: '축하드립니다!👏',
icon: 'success',
customClass: 'swal-wide',
confirmButtonText: '확인',
}).then(function (response) {
if (response.isConfirmed) {
window.location.reload()
}
}) })
callUserInfo().then((res) => { }
console.log('11', res[0]) else {
console.log('ERROR')
}
}) })
}
// window.location.reload(); // window.location.reload();
}; };
...@@ -62,7 +76,7 @@ function NicknameChange() { ...@@ -62,7 +76,7 @@ function NicknameChange() {
<Card.Text className='m-0'> <Card.Text className='m-0'>
<Form style={inboxstyled} onSubmit={handleSubmit}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<FloatingLabel label="Nickname"> <FloatingLabel label="Nickname">
<Form.Control type="text" placeholder="닉네임 변경" id='nickname' onChange={handleChange} /> <Form.Control type="text" placeholder="닉네임 변경" id='nickname' onChange={handleChange} required/>
</FloatingLabel> </FloatingLabel>
<Button variant='light' className='mt-3' id='formbtn' type='submit'> <Button variant='light' className='mt-3' id='formbtn' type='submit'>
......
...@@ -3,7 +3,6 @@ import '../App.css' ...@@ -3,7 +3,6 @@ import '../App.css'
import { Form, Button, Row, Col, Card, Alert, FloatingLabel } from 'react-bootstrap'; import { Form, Button, Row, Col, Card, Alert, FloatingLabel } from 'react-bootstrap';
import { LoginWithKakao } from '../utils/Oauth'; import { LoginWithKakao } from '../utils/Oauth';
import axios from 'axios'; import axios from 'axios';
import { callUserInfo } from '../utils/CheckDB';
function SignupComp() { function SignupComp() {
...@@ -43,30 +42,22 @@ function SignupComp() { ...@@ -43,30 +42,22 @@ function SignupComp() {
const { name, value } = event.target const { name, value } = event.target
setFormValues({ ...formValues, [name]: value }) setFormValues({ ...formValues, [name]: value })
} }
// console.log('???', formValues)
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
await axios.post("/api/signup", formValues) const res = await axios.post("/api/signup", formValues)
} console.log('existing_user : ', res.data.contents.existing_user)
setUserExist(res.data.contents.existing_user)
const [userInfo, setUserInfo] = useState([])
function CheckUserExist() {
setUserInfo(callUserInfo())
setAlertShow(true) setAlertShow(true)
if (userInfo) {
setUserExist(true)
// 기존회원
} }
if (callUserInfo() === undefined) {
setUserExist(false) useEffect(() => {
// 신규회원 async function test() {
} const res = await axios.get('/api/signup')
console.log(res.contents)
} }
console.log(callUserInfo()) test()
console.log(userExist) }, [])
return ( return (
...@@ -128,7 +119,7 @@ function SignupComp() { ...@@ -128,7 +119,7 @@ function SignupComp() {
/> />
</FloatingLabel> </FloatingLabel>
<Button variant='light' className='mt-3' id='formbtn' type='submit' onClick={CheckUserExist}> <Button variant='light' className='mt-3' id='formbtn' type='submit'>
Sign Up Sign Up
</Button> </Button>
</Form> </Form>
......
...@@ -4,10 +4,13 @@ import '../App.css' ...@@ -4,10 +4,13 @@ import '../App.css'
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { callUserInfo, checkCookies } from '../utils/CheckDB'; import { callUserInfo, checkCookies } from '../utils/CheckDB';
import axios from 'axios'; import axios from 'axios';
import { isLogined } from '../utils/Auth';
function UserInfo() { function UserInfo() {
const islogin = localStorage.getItem('login')
const cardstyled = { const cardstyled = {
margin: 'auto', margin: 'auto',
padding: '1em 0.5em 1em 0.5em', padding: '1em 0.5em 1em 0.5em',
...@@ -17,56 +20,38 @@ function UserInfo() { ...@@ -17,56 +20,38 @@ function UserInfo() {
borderWidth: '3px', borderWidth: '3px',
borderRadius: '20px', borderRadius: '20px',
borderColor: 'rgba(195, 195, 195, 0.753)', borderColor: 'rgba(195, 195, 195, 0.753)',
color: 'rgb(110, 189, 142)', color: 'rgb(110, 189, 142)',
} }
const btnstyled2 = { const btnstyled2 = {
background: 'white', background: 'white',
margin: 'auto', margin: 'auto',
borderWidth: '2px', borderWidth: '2px',
// padding: '0',
fontSize: '0.7em', fontSize: '0.7em',
color: 'rgb(110, 189, 142)', color: 'rgb(110, 189, 142)',
borderColor: 'rgba(195, 195, 195, 0.753)', borderColor: 'rgba(195, 195, 195, 0.753)',
// borderRadius: '20px',
width: '50%' width: '50%'
} }
const localname_doe = localStorage.getItem('name_doe')
const localname_sgg = localStorage.getItem('name_sgg')
const localname_emd = localStorage.getItem('name_emd')
const localcode_emd = localStorage.getItem('code_emd')
const [userNick, setUserNick] = useState('') const [userNick, setUserNick] = useState('')
const [createdTime, setCreatedTime] = useState('') const [createdTime, setCreatedTime] = useState('')
useEffect(() => { useEffect(() => {
callUserInfo().then((res) => { callUserInfo().then((res) => {
if (res !== []) { if (isLogined()) {
setUserNick(res[0]['nick_name']) setUserNick(res[0]['nick_name'])
const dateStr = res[0]['created_at'].split('T')[0].split('-') const dateStr = res[0]['created_at'].split('T')[0].split('-')
console.log(dateStr)
const now = new Date(); const now = new Date();
const year = now.getFullYear(); // 년 const year = now.getFullYear(); // 년
const month = now.getMonth() + 1; // 월 0부터 시작 const month = now.getMonth() + 1; // 월 0부터 시작
const day = now.getDate(); // 일 const day = now.getDate(); // 일
const stDate = new Date(dateStr[0], dateStr[1], dateStr[2]) const stDate = new Date(dateStr[0], dateStr[1], dateStr[2]) // 가입 날짜
console.log(stDate) const endDate = new Date(year, month, day) // 현재 시간
const endDate = new Date(year, month, day)
console.log(endDate)
const btMs = endDate.getTime() - stDate.getTime() // 주어진 날짜 사이의 경과 시간 (밀리 초) const btMs = endDate.getTime() - stDate.getTime() // 주어진 날짜 사이의 경과 시간 (밀리 초)
console.log(btMs / 1000) const btDay = btMs / (1000 * 60 * 60 * 24) // 초 -> 일
const btDay = btMs / (1000 * 60 * 60 * 24)
console.log(btDay)
setCreatedTime(btDay) setCreatedTime(btDay)
} }
...@@ -74,6 +59,39 @@ function UserInfo() { ...@@ -74,6 +59,39 @@ function UserInfo() {
console.log('Not Logined') console.log('Not Logined')
} }
}) })
}, [checkCookies()])
const codeInit = {
code_doe: '',
code_sgg: '',
code_emd: ''
}
const [codeValue, setCodeValue] = useState(codeInit)
useEffect(() => {
// user-info 에서 loc_code
callUserInfo().then((res) => {
if (isLogined()) {
console.log(res[0].loc_code)
const newCode = res[0].loc_code
const newdoe = String(newCode).substring(0, 2)
const newsgg = String(newCode).substring(0, 5)
const newemd = String(newCode).substring(0,)
async function CompareCode() {
await axios.get('/api/data/loccode').then((response) => {
console.log(response.data.contents.loc_code)
})
}
CompareCode()
}
else {
console.log(res)
}
})
}, []) }, [])
return ( return (
...@@ -81,7 +99,7 @@ function UserInfo() { ...@@ -81,7 +99,7 @@ function UserInfo() {
<Card style={cardstyled} id='localName'> <Card style={cardstyled} id='localName'>
<Card.Title> <Card.Title>
<strong> <strong>
{checkCookies() ? {isLogined() ?
<h3> <h3>
{`${userNick}`} {`${userNick}`}
</h3> </h3>
...@@ -98,14 +116,15 @@ function UserInfo() { ...@@ -98,14 +116,15 @@ function UserInfo() {
<hr /> <hr />
<Row style={{ alignItems: 'center', margin: 'auto', justifyContent: 'center' }}> <Row style={{ alignItems: 'center', margin: 'auto', justifyContent: 'center' }}>
<Card.Subtitle> <Card.Subtitle>
{localname_emd ? {isLogined() ?
<p className='mb-2'> <p className='mb-2'>
????????
{/*
{`${localname_doe}`} {`${localname_doe}`}
<br /> <br />
{`${localname_sgg}`} {`${localname_sgg}`}
<br /> <br />
{`${localname_emd}`} {`${localname_emd}`} */}
</p> </p>
: :
<p className='mb-2'> <p className='mb-2'>
...@@ -113,7 +132,7 @@ function UserInfo() { ...@@ -113,7 +132,7 @@ function UserInfo() {
</p> </p>
} }
</Card.Subtitle> </Card.Subtitle>
{checkCookies() && {isLogined() &&
<Button variant='light' className='m-auto d-flex' style={btnstyled2}> <Button variant='light' className='m-auto d-flex' style={btnstyled2}>
<Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}> <Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}>
변경 변경
...@@ -121,7 +140,7 @@ function UserInfo() { ...@@ -121,7 +140,7 @@ function UserInfo() {
</Button> </Button>
} }
</Row> </Row>
{checkCookies() && {isLogined() &&
<Card.Text> <Card.Text>
<hr /> <hr />
......
import axios from "axios";
import React, { useEffect, useState } from "react";
import { Form } from "react-bootstrap";
import { callUserInfo } from "../utils/CheckDB";
import { isLogined } from './../utils/Auth';
function UsingAircon() {
const [airUsing, setAirUsing] = useState(false)
useEffect(() => {
callUserInfo().then((res) => {
if (isLogined()) {
setAirUsing(res[0].using_aircon)
}
else {
console.log(res)
}
})
}, [])
async function airChange() {
setAirUsing(!airUsing)
await axios.post('/api/edit-profile', { using_aircon: !airUsing })
.then(
callUserInfo().then((res) => {
if (isLogined()) {
console.log('using_aircon :', res[0].using_aircon)
}
else {
console.log(res)
}
})
)
.catch(function (error) {
console.log('err', error);
});
}
return (
<Form
key='checkbox' className="d-flex justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}>
<Form.Check
type='switch'
id='airconditioner'
label='에어컨 사용중'
onChange={airChange}
checked={airUsing}
/>
</Form>
)
}
export default UsingAircon;
\ No newline at end of file
...@@ -8,8 +8,6 @@ import ChartLine from '../components/ChartLine'; ...@@ -8,8 +8,6 @@ import ChartLine from '../components/ChartLine';
import ChartDoughnut from '../components/ChartDoughnut'; import ChartDoughnut from '../components/ChartDoughnut';
import Donation from '../components/Donation'; import Donation from '../components/Donation';
function Home() { function Home() {
const constyled = { const constyled = {
display: 'flex', display: 'flex',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment