Commit 945e73ff authored by seoyeon's avatar seoyeon
Browse files

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

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