Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5855 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

/* eslint-disable react/prop-types */
import React, { useState } from 'react'
import { addNotification } from '../../../redux/notification/notification.actions'
import Spinner from '../../../shared/loading-spinner/Spinner'
import { axios } from '../../../utils'
import { useSelector } from 'react-redux'

const SocialNetworks = ({ moodle, microlearning }) => {
  const [loading, setLoading] = useState(false)
  const labels = useSelector((state) => state.labels)

  const handleOnRoom = async () => {
    try {
      setLoading(true)
      const response = await axios.post('/moodle')
      if (response.data.success) {
        const form = document.createElement('form')
        form.setAttribute('method', 'post')
        form.setAttribute('action', response.data.data.url)
        form.setAttribute('target', '_blank')
        Object.keys(response.data.data).forEach((key) => {
          if (key !== 'url') {
            const value = response.data.data[key]
            const hiddenField = document.createElement('input')
            hiddenField.setAttribute('type', 'hidden')
            hiddenField.setAttribute('name', key)
            hiddenField.setAttribute('value', value)
            form.appendChild(hiddenField)
          }
        })
        document.body.appendChild(form)
        form.submit()
      }
    } catch (error) {
      console.log('>>: error > ', error)
      addNotification({
        style: 'danger',
        msg: 'Ha ocurrido un error en la comunicacion con ON ROOM',
      })
    } finally {
      setLoading(false)
    }
  }

  return (
    <div className="app-widget">
      {loading && <Spinner />}
      <span
        className="d-flex flex-column align-items-center gap-2 cursor-pointer"
        onClick={() => handleOnRoom()}
      >
        <img src={moodle.image} alt="" />
        {moodle.name}
      </span>
      <div className="d-flex align-items-center justify-content-center gap-2">
        <a href={microlearning.playStore} target="_blank" rel="noreferrer">
          <img src="/images/logo-2getskillsa-apple.jpeg" alt="" />
        </a>
        <a href={microlearning.appStore} target="_blank" rel="noreferrer">
          <img src="/images/logo-2getskills-android.jpeg" alt="" />
        </a>
      </div>
      <span>{labels.MICRO_LEARNING}</span>
    </div>
  )
}

export default SocialNetworks