InviteModal.jsx 1.8 KB

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