Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3505 | Rev 3528 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react';
import { useParams } from 'react-router-dom';
import { Doughnut } from 'react-chartjs-2';
import { Box, Grid, styled, Typography } from '@mui/material';

import { useFetch } from '@shared/hooks';
import { Spinner } from '@shared/components';

const Tag = styled('span')`
  display: flex;
  flex-direction: column;
  align-items: center;
  small {
    color: ${(props) => props.theme.font.color.primary};
  }
`;

export function ProgressPage() {
  const { uuid } = useParams();
  const { data, loading } = useFetch(`/microlearning/progress/${uuid}`);

  const chartOptions = {
    maintainAspectRatio: true,
    responsive: true,
    plugins: {
      legend: {
        display: false
      }
    }
  };

  if (loading || !data) {
    return <Spinner />;
  }

  return (
    <Grid container spacing={1}>
      <Grid item xs={12} md={6}>
        <Typography variant='h1'>Cápsulas</Typography>

        <Box mx='auto' mt={2} maxWidth={400}>
          <Doughnut
            data={{
              labels: ['Completado', 'Por completar'],
              datasets: [
                {
                  data: [data?.percentCompleted, data?.percentIncompleted],
                  backgroundColor: ['#16283c99', '#36a2eb99']
                }
              ]
            }}
            options={chartOptions}
          />
        </Box>

        <Box display='flex' gap={2} justifyContent='center' alignItems='baseline' mt={1}>
          <Tag>
            <small>{data?.capsuleTotal}</small> Total
          </Tag>
          <Tag>
            <small>{data?.capsuleStarted}</small> Iniciadas
          </Tag>
          <Tag>
            <small>{data?.capsuleToStart}</small> Por realizar
          </Tag>
          <Tag>
            <small>{data?.capsuleCompleted}</small> Completadas
          </Tag>
        </Box>
      </Grid>

      <Grid item xs={12} md={6}>
        <Typography variant='h1'>Retorno</Typography>

        <Box mx='auto' mt={2} maxWidth={400}>
          <Doughnut
            data={{
              labels: ['Con retorno', 'Sin retorno'],
              datasets: [
                {
                  data: [data?.capsuleWithReturning, data?.capsuleWithoutReturning],
                  backgroundColor: ['#16283c99', '#36a2eb99']
                }
              ]
            }}
            options={chartOptions}
          />
        </Box>
      </Grid>
    </Grid>
  );
}