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 { 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">
......
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
......
......@@ -31,13 +31,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)
......@@ -51,8 +50,11 @@ const Signup = () => {
if (p1 !== p2) {
// event.preventDefault()
alert('비밀번호가 일치하지 않습니다.')
window.location.href = '/login'
return false
} else {
// 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