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