WelcomeModal.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from "react";
  2. import { useTranslation } from "react-i18next";
  3. import styled from "styled-components";
  4. import { toast } from "react-toastify";
  5. import Modal from "../../ui/Modal";
  6. import GameInformation from "./GameInformation";
  7. const StyledUrl = styled.div`
  8. background-color: var(--color-midGrey);
  9. padding: 0.5em;
  10. border-radius: 2px;
  11. display: flex;
  12. align-items: center;
  13. justify-content: space-between;
  14. margin-bottom: 2em;
  15. & span {
  16. overflow: hidden;
  17. white-space: nowrap;
  18. text-overflow: ellipsis;
  19. }
  20. & img {
  21. margin-left: 1em;
  22. cursor: pointer;
  23. }
  24. `;
  25. const WelcomeModal = ({ show, setShow, welcome = true }) => {
  26. const { t } = useTranslation();
  27. const currentUrl = window.location.href;
  28. const handleCopy = async () => {
  29. await navigator.clipboard.writeText(window.location.href);
  30. toast.info(t("Url copied to clipboard!"), { autoClose: 1000 });
  31. };
  32. return (
  33. <Modal
  34. title={welcome ? t("Ready to play ?") : t("Invite more player")}
  35. setShow={setShow}
  36. show={show}
  37. >
  38. <header>
  39. <h3>{t("Share this link with your friends")}</h3>
  40. </header>
  41. <section>
  42. <StyledUrl>
  43. <span>{currentUrl}</span>
  44. <img
  45. className="copy"
  46. src="https://icongr.am/entypo/copy.svg?size=22&color=888886"
  47. alt={t("Copy")}
  48. onClick={handleCopy}
  49. />
  50. </StyledUrl>
  51. <p>
  52. {t(
  53. "Share this link with your friends and start playing immediately."
  54. )}
  55. </p>
  56. {welcome && (
  57. <button
  58. onClick={() => {
  59. setShow(false);
  60. }}
  61. className="button success"
  62. style={{ margin: "1em auto" }}
  63. >
  64. {t("I want to play...")}
  65. </button>
  66. )}
  67. </section>
  68. {welcome && <GameInformation />}
  69. </Modal>
  70. );
  71. };
  72. export default WelcomeModal;