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