Commit cb69af51 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

방 생성 & 참여시에도 출입시간 기록

parent f7b7d734
......@@ -7,15 +7,29 @@ import catchErrors from '../utils/catchErrors'
function EnterRoom(props) {
const [enterCode, setEnterCode] = useState('');
const [error, setError] = useState('');
const realTime = new Date().toISOString()
const userId = sessionStorage.getItem('userId');
async function recordEntryLog() {
const leaveInfo = { userId: userId, roomCode: enterCode, leaveTime: realTime }
try {
const check = await axios.get('/room/entrylog', { params: leaveInfo })
if (check.data) { //있으면 put으로
await axios.put('/room/entrylog', leaveInfo)
} else { //없으면 post
await axios.post('/room/entrylog', leaveInfo)
}
} catch (error) {
catchErrors(error, setError)
}
}
function handleChange(event) {
const { name, value } = event.target
setEnterCode(value)
console.log(enterCode)
}
async function handleSubmit(event) {
event.preventDefault()
try {
......@@ -31,6 +45,7 @@ function EnterRoom(props) {
props.handleCloseEnter()
props.handleChato()
setEnterCode('')
recordEntryLog()
} catch (error) {
catchErrors(error, setError)
}
......
......@@ -12,8 +12,25 @@ const INIT_ROOM = {
function RoomMake(props) {
const [room, setRoom] = useState(INIT_ROOM);
const [error, setError] = useState('');
const [roomCode, setRoomCode] = useState('')
const member = sessionStorage.getItem('userId');
const realTime = new Date().toISOString()
async function recordEntryLog(Id) {
const leaveInfo = { userId: member, roomCode: Id, leaveTime: realTime }
try {
const check = await axios.get('/room/entrylog', { params: leaveInfo })
if (check.data) { //있으면 put으로
await axios.put('/room/entrylog', leaveInfo)
} else { //없으면 post
await axios.post('/room/entrylog', leaveInfo)
}
} catch (error) {
catchErrors(error, setError)
}
}
function handleChange(event) {
const { name, value } = event.target
setRoom({ ...room, [name]: value, member })
......@@ -29,6 +46,8 @@ function RoomMake(props) {
alert(`방암호는 ${Id}입니다`)
props.handleCloseModal()
setRoom(INIT_ROOM)
// setRoomCode(Id)
recordEntryLog(Id)
} catch (error) {
catchErrors(error, setError)
}
......@@ -80,7 +99,7 @@ function RoomMake(props) {
}
<Form.Group as={Row}>
<Col sm={{ span: 5, offset: 4 }}>
<Button type="submit" style={{backgroundColor:"#9174ad", borderColor:"#9174ad"}} > 생성</Button>
<Button type="submit" style={{ backgroundColor: "#9174ad", borderColor: "#9174ad" }} > 생성</Button>
</Col>
</Form.Group>
</Form>
......
......@@ -10,6 +10,7 @@ import RoomMake from "../Components/RoomMake"
import EnterRoom from "../Components/EnterRoom"
import axios from 'axios';
import "./Home.css"
import catchErrors from '../utils/catchErrors';
const socket = io();
......@@ -34,6 +35,9 @@ const INIT_UNREAD = {
function Home() {
const userName = sessionStorage.getItem('name')
const userId = sessionStorage.getItem('userId')
const realTime = new Date().toISOString()
const [error, setError] = useState('')
const [checknew, setChecknew] = useState('')
const [unreadnumber, setUnreadnumber] = useState(INIT_UNREAD)
......@@ -128,11 +132,27 @@ function Home() {
alert('참가되었습니다.')
setSysmsg(`${userNick}님이 들어왔습니다.`)
getClosedList()
recordEntryLog()
} else {
alert('이미 참가된 방입니다.')
}
}
async function recordEntryLog() {
const leaveInfo = { userId: userId, roomCode: roomCode, leaveTime: realTime }
try {
const check = await axios.get('/room/entrylog', { params: leaveInfo })
if (check.data) { //있으면 put으로
await axios.put('/room/entrylog', leaveInfo)
} else { //없으면 post
await axios.post('/room/entrylog', leaveInfo)
}
} catch (error) {
catchErrors(error, setError)
}
}
function enterButton() {
setOpen(false)
}
......
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