Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3577 stevensc 1
import React, { useState } from 'react';
2
import { useParams } from 'react-router-dom';
3
import { Backdrop, Box, styled, Typography } from '@mui/material';
4
 
5
import { parse } from '@utils';
6
import { useFetch, useInmail } from '@hooks';
7
 
8
import Widget from '@components/UI/Widget';
9
import Input from '@components/UI/inputs/Input';
10
import Ckeditor from '@components/common/ckeditor/Ckeditor';
11
import Spinner from '@components/UI/Spinner';
12
 
13
const Row = styled(Box)(({ theme }) => ({
14
  display: 'flex',
15
  gap: theme.spacing(1),
16
  marginBottom: theme.spacing(0.5)
17
}));
18
 
19
function InmailAttachment({ filename, contentType, attachmentLink }) {
20
  const [show, setShow] = useState(false);
21
 
22
  const getAttachmentType = (type = '') => {
23
    const attachmentTypes = ['image', 'video', 'audio'];
24
    return (
25
      attachmentTypes.find((attachmentType) => type.includes(attachmentType)) ?? attachmentTypes[0]
26
    );
27
  };
28
 
29
  const attachmentTypeTags = {
30
    image: <img src={attachmentLink} alt={filename} />,
31
    video: <video src={attachmentLink} />,
32
    audio: <audio src={attachmentLink} />
33
  };
34
 
35
  const toggleShow = () => setShow(!show);
36
 
37
  return (
38
    <>
39
      <img
40
        src={`/images/${getAttachmentType(contentType)}.png`}
41
        alt={filename}
42
        onClick={toggleShow}
43
        width={60}
44
        height={60}
45
      />
46
      <Backdrop
47
        sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}
48
        open={show}
49
        onClick={toggleShow}
50
      >
51
        <Widget styles={{ maxWidth: '500px' }}>
52
          <Widget.Header title={filename} />
53
          <Widget.Body>
54
            {attachmentTypeTags[getAttachmentType(contentType)] ?? attachmentTypeTags.image}
55
          </Widget.Body>
56
        </Widget>
57
      </Backdrop>
58
    </>
59
  );
60
}
61
 
62
export function MessageViewPage() {
63
  const { messages, loading } = useInmail();
64
  const { uuid } = useParams();
65
  const currentMessage = messages.find((message) => message.email_id === uuid);
66
 
67
  const { data: message, isLoading } = useFetch(currentMessage?.get_link, null);
68
 
69
  if (isLoading || loading) {
70
    return <Spinner />;
71
  }
72
 
73
  return (
74
    <Widget>
75
      <Widget.Body>
76
        <Row>
77
          <Typography variant='overline'>De: </Typography>
78
          <Input value={message?.name} disabled fullWidth />
79
        </Row>
80
        <Row>
81
          <Typography variant='overline'>Asunto: </Typography>
82
          <Input value={message?.subject} disabled fullWidth />
83
        </Row>
84
        <Typography variant='overline' sx={{ marginBottom: 0.5 }}>
85
          Fecha: {message?.date}
86
        </Typography>
87
        <Ckeditor defaultValue={parse(message?.body)} disabled />
88
        <Typography variant='h3' sx={{ my: 0.5 }}>
89
          Archivos adjuntos:
90
        </Typography>
91
        {message?.attachments.map((attachment, index) => (
92
          <InmailAttachment
93
            key={index}
94
            filename={attachment.filename}
95
            attachmentLink={attachment.attachment_link}
96
            contentType={attachment['content-type']}
97
          />
98
        ))}
99
      </Widget.Body>
100
    </Widget>
101
  );
102
}