Created
June 26, 2021 03:25
-
-
Save MoranggNormal/f4786ac0a07973e290ee04a185a688a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormEvent, useState } from 'react' | |
import { Link } from 'react-router-dom' | |
import illustrationImg from '../assets/images/illustration.svg' | |
import logoImg from '../assets/images/logo.svg' | |
import { Button } from '../components/Button' | |
import { database } from '../services/firebase' | |
import { useAuth } from '../hooks/useAuth'; | |
import '../styles/auth.scss'; | |
export function NewRoom() { | |
const { user } = useAuth(); // <-- Erro acontece aqui | |
const [newRoom, setNewRoom] = useState('') | |
async function handleCreateRoom(event: FormEvent) { | |
event.preventDefault() | |
if (newRoom.trim() === '') { | |
return | |
} | |
const roomRef = database.ref('rooms') | |
const firebaseRoom = await roomRef.push({ | |
tittle: newRoom, | |
autherId: user?.id | |
}) | |
} | |
return ( | |
<div id="page-auth"> | |
<aside> | |
<img src={illustrationImg} alt="Ilustração simbolizando perguntas e respostas" /> | |
<strong>Crie salas de Q&A ao-vivo</strong> | |
<p>Tire as duvidas da sua audiência em tempo-real</p> | |
</aside> | |
<main> | |
<div className="main-content"> | |
<img src={logoImg} alt="Letmeask" /> | |
<h2>Criar uma nova sala</h2> | |
<form onSubmit={handleCreateRoom}> | |
<input | |
type="text" | |
placeholder="Nome da sala" | |
onChange={event => setNewRoom(event.target.value)} | |
value={newRoom} | |
/> | |
<Button type="submit"> | |
Criar sala | |
</Button> | |
</form> | |
<p> | |
Quer entrar em uma sala existente? <Link to="/">Clique aqui</Link> | |
</p> | |
</div> | |
</main> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment