Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 349 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
348 stevensc 1
import React, { useState } from "react";
2
 
3
const SharePopup = ({ shareData, onClose, onError }) => {
4
  const [state, setState] = useState("pending");
5
 
6
  const copyClicked = async () => {
7
    try {
8
      await navigator.clipboard.writeText(shareData?.url || "");
9
      setState("success");
10
    } catch (err) {
11
      onError && onError(err);
12
      setState("error");
13
    }
14
  };
15
 
16
  const getButtonText = (state) => {
17
    switch (state) {
18
      case "success":
19
        return "Link copied";
20
      case "pending":
21
      default:
22
        return "Copy link";
23
    }
24
  };
25
 
26
  return (
27
    <div>
28
      <div>
29
        <div>
30
          <div>
31
            <div>
32
              <div>
33
                <h3>{shareData.title}</h3>
34
                <button onClick={onClose}>
35
                  <span>Close Share</span>
36
                  <div aria-hidden="true">
37
                    <svg
38
                      xmlns="http://www.w3.org/2000/svg"
39
                      width="24"
40
                      height="24"
41
                      viewBox="0 0 24 24"
42
                    >
43
                      <g id="close">
44
                        <path
45
                          id="x"
46
                          d="M18.717 6.697l-1.414-1.414-5.303 5.303-5.303-5.303-1.414 1.414 5.303 5.303-5.303 5.303 1.414 1.414 5.303-5.303 5.303 5.303 1.414-1.414-5.303-5.303z"
47
                        />
48
                      </g>
49
                    </svg>
50
                  </div>
51
                </button>
52
              </div>
53
              <div>
54
                {state === "error" ? (
55
                  <div>
56
                    <p>
57
                      Unable to copy to clipboard, please manually copy the url
58
                      to share.
59
                    </p>
60
                  </div>
61
                ) : null}
62
                <input value={shareData.url} readOnly />
63
                <button onClick={copyClicked}>{getButtonText(state)}</button>
64
              </div>
65
            </div>
66
          </div>
67
        </div>
68
      </div>
69
    </div>
70
  );
71
};
72
 
73
export default SharePopup;