Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 364 | Rev 1442 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 364 Rev 1437
Línea 1... Línea 1...
1
import React, { useEffect, useState } from "react";
1
import React, { useEffect, useState } from 'react'
2
import { axios } from "../../../../utils";
2
import { axios } from '../../../../utils'
3
import { Modal } from "react-bootstrap";
3
import { Modal } from 'react-bootstrap'
4
import { useDispatch } from "react-redux";
4
import { useDispatch } from 'react-redux'
5
import { addNotification } from "../../../../redux/notification/notification.actions";
5
import { addNotification } from '../../../../redux/notification/notification.actions'
Línea 6... Línea 6...
6
 
6
 
Línea 7... Línea 7...
7
import FormErrorFeedback from "../../../UI/FormErrorFeedback";
7
import FormErrorFeedback from '../../../UI/form/FormErrorFeedback'
8
 
8
 
9
const SharePopup = ({ shareData, onClose, onError, show }) => {
9
const SharePopup = ({ shareData, onClose, onError, show }) => {
10
  const [shareUrl, setShareUrl] = useState("");
10
  const [shareUrl, setShareUrl] = useState('')
Línea 11... Línea 11...
11
  const [state, setState] = useState("pending");
11
  const [state, setState] = useState('pending')
12
  const dispatch = useDispatch();
12
  const dispatch = useDispatch()
13
 
13
 
14
  const getShareUrl = (url = "") => {
14
  const getShareUrl = (url = '') => {
15
    axios
15
    axios
16
      .get(url)
16
      .get(url)
17
      .then(({ data }) => {
17
      .then(({ data }) => {
18
        if (!data.success) {
18
        if (!data.success) {
Línea 19... Línea 19...
19
          dispatch(addNotification({ style: "danger", msg: data.data }));
19
          dispatch(addNotification({ style: 'danger', msg: data.data }))
20
          return;
20
          return
21
        }
21
        }
22
 
22
 
23
        setShareUrl(data.data);
23
        setShareUrl(data.data)
24
      })
24
      })
25
      .catch((err) => {
25
      .catch((err) => {
Línea 26... Línea 26...
26
        onError(err);
26
        onError(err)
27
        throw new Error(err);
27
        throw new Error(err)
28
      });
28
      })
29
  };
29
  }
30
 
30
 
31
  const copyClicked = async () => {
31
  const copyClicked = async () => {
32
    try {
32
    try {
33
      await navigator.clipboard.writeText(shareUrl || "");
33
      await navigator.clipboard.writeText(shareUrl || '')
34
      setState("success");
34
      setState('success')
Línea 35... Línea 35...
35
    } catch (err) {
35
    } catch (err) {
36
      onError && onError(err);
36
      onError && onError(err)
37
      setState("error");
37
      setState('error')
38
    }
38
    }
39
  };
39
  }
40
 
40
 
41
  const getButtonText = (state) => {
41
  const getButtonText = (state) => {
42
    switch (state) {
42
    switch (state) {
43
      case "success":
43
      case 'success':
Línea 44... Línea 44...
44
        return "URL Copiada al portapapeles";
44
        return 'URL Copiada al portapapeles'
45
      case "pending":
45
      case 'pending':
46
      default:
46
      default:
47
        return "Copiar URL";
47
        return 'Copiar URL'
48
    }
48
    }
Línea 49... Línea 49...
49
  };
49
  }
50
 
50
 
51
  useEffect(() => {
51
  useEffect(() => {
52
    if (show) {
52
    if (show) {
53
      getShareUrl(shareData?.url);
53
      getShareUrl(shareData?.url)
54
    }
54
    }
55
  }, [shareData, show]);
55
  }, [shareData, show])
56
 
56
 
57
  return (
57
  return (
58
    <Modal show={show} onHide={onClose} centered>
58
    <Modal show={show} onHide={onClose} centered>
59
      <Modal.Header closeButton />
59
      <Modal.Header closeButton />
60
      <Modal.Body>
60
      <Modal.Body>
61
        {state === "error" ? (
61
        {state === 'error' ? (
62
          <FormErrorFeedback>
62
          <FormErrorFeedback>
63
            No se pudo copiar al portapapeles, por favor copia la url
63
            No se pudo copiar al portapapeles, por favor copia la url
64
            manualmente para compartir.
64
            manualmente para compartir.
65
          </FormErrorFeedback>
65
          </FormErrorFeedback>
66
        ) : null}
66
        ) : null}
Línea 67... Línea 67...
67
        <input className="form-control" type="text" value={shareUrl} readOnly />
67
        <input className='form-control' type='text' value={shareUrl} readOnly />