Commit 74ec15d7 authored by 이재연's avatar 이재연
Browse files

Merge remote-tracking branch 'origin/woojiweon' into jaeyeoniiiiii

parents 1393be96 122ea059
import { useEffect, useState } from "react";
import { Redirect, useParams } from "react-router-dom";
import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const id = localStorage.getItem('user');
const INIT_ROOM = {
name: '',
owner: id,
member: id,
profileimg: '',
}
......@@ -23,14 +21,26 @@ const CreateRoom = () => {
}, [room]);
function handleChange(event) {
const { name, value } = event.target
setRoom({ ...room, [name]: value })
const { name, value, files } = event.target;
if (files) {
setRoom({ ...room, [name]: files[0] })
} else {
setRoom({ ...room, [name]: value })
}
console.log(room)
}
async function handleSubmit(e) {
e.preventDefault()
let formData = new FormData();
console.log('profileimg:', room.profileimg)
console.log('name:', room.name)
formData.append("name", room.name);
formData.append("userId", id);
formData.append("profileimg", room.profileimg);
try {
const res = await roomApi.create(room)
const res = await roomApi.create(formData)
console.log(res)
const Id = res.id
console.log(Id)
alert(`방참여코드는 ${Id}입니다`)
......@@ -46,6 +56,7 @@ const CreateRoom = () => {
// console.log('success', success)
alert('룸생성이 완료되었습니다!')
window.location.href=`/user/${id}`
// return <Redirect to={`/user/${id}`} />
}
const { name, owner, member, profileimg } = room;
......@@ -54,7 +65,9 @@ const CreateRoom = () => {
<div className="modal-content" >
<form onSubmit={handleSubmit}>
<div className="modal-header">
<div className="modal-title" id="makeModal">방생성하기</div>
<div className="modal-title" id="makeModal">
방생성하기
</div>
<button
type="button"
className="btn-close"
......@@ -63,6 +76,7 @@ const CreateRoom = () => {
></button>
</div>
<div className="modal-body">
{error && <div className="alert alert-danger">{error}</div>}
<h6>방프로필사진</h6>
<div className="mb-4">
<input
......@@ -71,7 +85,7 @@ const CreateRoom = () => {
onChange={handleChange}
accept="image/*"
name="profileimg"
value={room.profileimg} />
/>
</div>
<h6>방이름</h6>
<div className="input-group">
......@@ -83,7 +97,6 @@ const CreateRoom = () => {
aria-describedby="basic-addon1"
onChange={handleChange}
name="name"
value={room.name}
/>
</div>
<div className="modal-footer">
......
......@@ -14,6 +14,7 @@ const RoomSingle = () => {
const [room, setRoom] = useState(INIT_ROOM)
const [error,setError]=useState('')
const channelId = 1
const roomId = "1234567abc"
async function getJoinRoom(Id) {
try {
......
import { useEffect, useState} from 'react'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import userApi from '../apis/user.api'
import catchErrors from '../context/catchError'
......@@ -31,6 +31,7 @@ const Login = () => {
try {
// setLoading(true);
// setError("");
console.log('user정보:', user)
const data = await userApi.login(user)
console.log(data)
setId(data.id)
......@@ -45,7 +46,7 @@ const Login = () => {
}
if (success) {
alert('로그인 되었습니다');
window.location.href=`/user/${id}`
window.location.href = `/user/${id}`
}
const { email, password } = user
......
......@@ -30,13 +30,12 @@ const Signup = () => {
e.preventDefault()
console.log('회원가입')
try {
if (!checkPassword()) {
return
if (checkPassword()) {
const data = await userApi.signup(user)
console.log(data)
setSuccess(true)
setError('')
}
const data = await userApi.signup(user)
console.log(data)
setSuccess(true)
setError('')
} catch (error) {
console.log('error')
catchErrors(error, setError)
......@@ -50,10 +49,11 @@ const Signup = () => {
if (p1 !== p2) {
// event.preventDefault()
alert('비밀번호가 일치하지 않습니다.')
window.location.href = '/login'
return false
} else {
alert('회원가입 되었습니다.')
window.location.href = '/'
// alert('회원가입 되었습니다.')
// window.location.href = '/'
return true
}
}
......
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