Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3578 | Rev 3581 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3578 Rev 3580
Línea 1... Línea 1...
1
import React from 'react';
1
import React, { useEffect, useState } from 'react';
2
import { Grid, Typography } from '@mui/material';
2
import { Grid, Typography } from '@mui/material';
3
import { useFetch } from '@shared/hooks';
-
 
Línea -... Línea 3...
-
 
3
 
-
 
4
import { useApi, useFetch } from '@shared/hooks';
-
 
5
import { getMessages } from '@inmail/services';
4
 
6
 
-
 
7
import { Spinner } from '@shared/components';
Línea 5... Línea 8...
5
import { Card, CardHeader, List, Spinner } from '@shared/components';
8
import { ConversationsList } from '@inmail/components/conversations';
-
 
9
 
-
 
10
export function InmailPage() {
6
 
11
  const [selectedConversation, setSelectedConversation] = useState(null);
-
 
12
 
-
 
13
  const { data: conversations, loading } = useFetch('/inmail');
-
 
14
  const { data: messages, loading: loadingMessages, execute: fetchMessages } = useApi(getMessages);
-
 
15
 
-
 
16
  useEffect(() => {
-
 
17
    if (selectedConversation) {
-
 
18
      fetchMessages(selectedConversation.messages_link);
Línea 7... Línea 19...
7
export function InmailPage() {
19
    }
8
  const { data: conversations, loading } = useFetch('/inmail');
20
  }, [selectedConversation]);
9
 
21
 
Línea 10... Línea 22...
10
  if (loading || !conversations) {
22
  if (loading || !conversations) {
11
    return <Spinner />;
23
    return <Spinner />;
12
  }
24
  }
13
 
-
 
14
  return (
-
 
15
    <Grid container spacing={2}>
25
 
16
      <Grid item xs={12} md={3}>
-
 
17
        <Typography variant='h3'>Conversaciones</Typography>
-
 
18
        <List
-
 
19
          items={conversations}
-
 
20
          keyExtractor={(item) => item.uuid}
-
 
21
          emptyMessage='No hay conversaciones'
-
 
22
          renderItem={(conversation) => (
26
  return (
23
            <Card>
27
    <Grid container spacing={2}>
24
              <CardHeader
-
 
25
                avatar={conversation.image}
-
 
26
                title={conversation.name}
-
 
27
                subheader={conversation.last_message}
28
      <Grid item xs={12} md={3}>
28
              />
29
        <ConversationsList
29
            </Card>
30
          conversations={conversations}
-
 
31
          onSelectConversation={setSelectedConversation}
-
 
32
        />
-
 
33
      </Grid>
-
 
34
      <Grid item xs={12} md={9}>
-
 
35
        {loadingMessages ? (
30
          )}
36
          <Spinner />
-
 
37
        ) : (
-
 
38
          <>
-
 
39
            {messages.map((message) => (
31
        />
40
              <Typography key={message.uuid}>{JSON.stringify(message)}</Typography>
32
      </Grid>
41
            ))}
33
      <Grid item xs={12} md={9}>
42
          </>
34
        <Typography variant='h3'>Mensajes</Typography>
43
        )}