Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5852 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4438 stevensc 1
/* eslint-disable react/prop-types */
5104 stevensc 2
import React, { useState } from 'react'
3
import { addNotification } from '../../../redux/notification/notification.actions'
4
import Spinner from '../../../shared/loading-spinner/Spinner'
5
import { axios } from '../../../utils'
5399 stevensc 6
import { useSelector } from 'react-redux'
1386 steven 7
 
5851 stevensc 8
const SocialNetworks = ({ moodle, microlearning }) => {
5282 stevensc 9
  const [loading, setLoading] = useState(false)
5851 stevensc 10
  const labels = useSelector((state) => state.labels)
2097 steven 11
 
5104 stevensc 12
  const handleOnRoom = async () => {
13
    try {
14
      setLoading(true)
15
      const response = await axios.post('/moodle')
16
      if (response.data.success) {
17
        const form = document.createElement('form')
18
        form.setAttribute('method', 'post')
19
        form.setAttribute('action', response.data.data.url)
20
        form.setAttribute('target', '_blank')
5851 stevensc 21
        Object.keys(response.data.data).forEach((key) => {
5104 stevensc 22
          if (key !== 'url') {
23
            const value = response.data.data[key]
24
            const hiddenField = document.createElement('input')
25
            hiddenField.setAttribute('type', 'hidden')
26
            hiddenField.setAttribute('name', key)
27
            hiddenField.setAttribute('value', value)
28
            form.appendChild(hiddenField)
29
          }
30
        })
31
        document.body.appendChild(form)
32
        form.submit()
33
      }
34
    } catch (error) {
35
      console.log('>>: error > ', error)
36
      addNotification({
37
        style: 'danger',
5851 stevensc 38
        msg: 'Ha ocurrido un error en la comunicacion con ON ROOM',
5104 stevensc 39
      })
40
    } finally {
41
      setLoading(false)
2084 steven 42
    }
5104 stevensc 43
  }
5282 stevensc 44
 
5104 stevensc 45
  return (
5851 stevensc 46
    <div className="app-widget">
5282 stevensc 47
      {loading && <Spinner />}
5851 stevensc 48
      <span
49
        className="d-flex flex-column align-items-center gap-2 cursor-pointer"
50
        onClick={() => handleOnRoom()}
51
      >
52
        <img src={moodle.image} alt="" />
53
        {moodle.name}
5441 stevensc 54
      </span>
5851 stevensc 55
      <div className="d-flex align-items-center justify-content-center gap-2">
5852 stevensc 56
        <a href={microlearning.playStore} target="_blank" rel="noreferrer">
5855 stevensc 57
          <img src="/images/play-store.png" alt="" />
5282 stevensc 58
        </a>
5852 stevensc 59
        <a href={microlearning.appStore} target="_blank" rel="noreferrer">
5855 stevensc 60
          <img src="/images/app-store.png" alt="" />
5282 stevensc 61
        </a>
62
      </div>
5441 stevensc 63
      <span>{labels.MICRO_LEARNING}</span>
5282 stevensc 64
    </div>
5104 stevensc 65
  )
1386 steven 66
}
5282 stevensc 67
 
68
export default SocialNetworks