Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2875 stevensc 1
import React, { useState } from 'react'
2
import { Avatar, Box, Typography } from '@mui/material'
3
 
4
import { getOnRoom } from '@services/onRoom'
5
import { addNotification } from '@store/notification/notification.actions'
6
 
7
import Widget from '@components/UI/Widget'
8
import Spinner from '@components/UI/Spinner'
9
 
10
export default function OnRoomWidget({ moodle }) {
11
  const [loading, setLoading] = useState(false)
12
 
13
  const handleOnRoom = async () => {
14
    try {
15
      setLoading(true)
16
      const response = await getOnRoom()
17
      const onRoomUrl = new URL(response.url)
18
      Object.keys(response).forEach((key) => {
19
        if (key === 'url') return
20
        onRoomUrl.searchParams.set(key, response[key])
21
      })
22
 
23
      setTimeout(() => {
24
        window.open(onRoomUrl.toString(), '_blank')
25
      }, 0)
26
    } catch (error) {
27
      addNotification({ style: 'danger', msg: error.message })
28
    } finally {
29
      setLoading(false)
30
    }
31
  }
32
 
33
  return (
34
    <Widget>
2884 stevensc 35
      <Widget.Body styles={{ display: 'grid', placeItems: 'center' }}>
2875 stevensc 36
        {loading && (
37
          <Box
38
            sx={{
39
              position: 'absolute',
40
              width: '100%',
41
              height: '100%',
42
              display: 'grid',
43
              placeItems: 'center',
44
              zIndex: 50
45
            }}
46
          >
47
            <Spinner />
48
          </Box>
49
        )}
50
 
51
        <Avatar
52
          sx={{ cursor: 'pointer' }}
53
          src={moodle.image}
54
          alt={moodle.name}
55
          onClick={() => handleOnRoom()}
56
        />
57
        <Typography variant='body2'>{moodle.name}</Typography>
58
      </Widget.Body>
59
    </Widget>
60
  )
61
}