Files
grungnet/src/modals/JoinModal.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-13 18:29:46 +10:00
import React, { useState, useRef } from "react";
import { Box, Label, Input, Button, Flex } from "theme-ui";
import { useHistory } from "react-router-dom";
2020-04-13 18:29:46 +10:00
import Modal from "../components/Modal";
2020-04-13 18:29:46 +10:00
function JoinModal({ isOpen, onRequestClose }) {
let history = useHistory();
2020-04-05 22:20:34 +10:00
const [gameId, setGameId] = useState("");
function handleChange(event) {
setGameId(event.target.value);
}
function handleSubmit(event) {
event.preventDefault();
history.push(`/game/${gameId}`);
}
2020-04-13 18:29:46 +10:00
const inputRef = useRef();
function focusInput() {
inputRef.current && inputRef.current.focus();
}
return (
2020-04-13 18:29:46 +10:00
<Modal
isOpen={isOpen}
onRequestClose={onRequestClose}
onAfterOpen={focusInput}
>
<Flex
sx={{
flexDirection: "column",
2020-04-05 22:20:34 +10:00
justifyContent: "center",
maxWidth: "300px",
flexGrow: 1,
}}
2020-04-13 18:29:46 +10:00
m={2}
>
<Box as="form" onSubmit={handleSubmit}>
<Label htmlFor="id">Let me see your identification</Label>
<Input
2020-03-26 12:24:52 +11:00
mt={1}
mb={3}
id="id"
name="id"
value={gameId || ""}
onChange={handleChange}
2020-04-13 18:29:46 +10:00
ref={inputRef}
/>
2020-04-14 16:05:44 +10:00
<Flex>
<Button sx={{ flexGrow: 1 }} disabled={!gameId}>
Join
2020-04-14 16:05:44 +10:00
</Button>
</Flex>
</Box>
</Flex>
2020-04-13 18:29:46 +10:00
</Modal>
);
}
2020-04-13 18:29:46 +10:00
export default JoinModal;