Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3395 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useEffect } from 'react';
2
import { useDispatch, useSelector } from 'react-redux';
3
import { useParams } from 'react-router-dom';
4
import { useFetch } from '@hooks';
5
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '@app/redux/feed/feed.actions';
6
import { feedTypes } from '@app/redux/feed/feed.types';
7
 
8
import GroupsWidget from '@app/components/dashboard/linkedin/Groups';
9
import UserProfileCard from '@app/components/dashboard/linkedin/user-profile-card';
10
import FeedShare from '@app/components/dashboard/linkedin/share/ShareComponent';
11
import DailyPulse from '@app/components/widgets/default/DailyPulse';
12
import HomeNews from '@app/components/widgets/default/HomeNews';
13
import PeopleYouMayKnow from '@app/components/widgets/default/PeopleYouMayKnow';
14
import AppsWidget from '@components/dashboard/widgets/AppsWidget';
15
import OnRoomWidget from '@components/dashboard/widgets/OnRoomWidget';
16
import MicrolearningWidget from '@components/dashboard/widgets/MicrolearningWidget';
17
import Pagination from '@components/common/Pagination';
18
import HabitsWidget from '@components/dashboard/widgets/HabitsWidget';
19
 
20
import LoadingWrapper from '@components/common/loading-wrapper';
21
import List from '@components/common/list';
22
import Feed from '@components/dashboard/feed/feed';
23
import { Box, Grid } from '@mui/material';
24
 
25
const DashboardPage = () => {
26
  const dispatch = useDispatch();
27
 
28
  const { id } = useParams();
29
  const { data } = useFetch(id ? `/dashboard/feed/${id}` : '/dashboard');
30
 
31
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
32
 
33
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
34
 
35
  const onChangePageHandler = (currentPage) => {
36
    dispatch(setCurrentPage(currentPage));
37
    window.scrollTo(0, 0);
38
  };
39
 
40
  useEffect(() => {
41
    if (!data || !data.routeTimeline) return;
42
    console.log(data.routeTimeline);
43
    dispatch(setTimelineUrl(data.routeTimeline));
44
  }, [data, id]);
45
 
46
  useEffect(() => {
47
    dispatch(fetchFeeds(timelineUrl, currentPage));
48
  }, [timelineUrl, currentPage]);
49
 
50
  return (
51
    <Grid container spacing={1}>
52
      <Grid
53
        size={{ xs: 12, md: 3 }}
54
        sx={{ display: { xs: 'none', md: 'flex' }, flexDirection: 'column', gap: 1 }}
55
      >
56
        <UserProfileCard user={data} />
57
        <OnRoomWidget
58
          moodle={{
59
            image: data?.moodle_image,
60
            name: data?.moodle_name
61
          }}
62
        />
63
        <HabitsWidget />
64
        <MicrolearningWidget />
65
        <AppsWidget
66
          microlearning={{
67
            playStore: data?.microlearning_playstore,
68
            appStore: data?.microlearning_appstore,
69
            name: data?.microlearning_name
70
          }}
71
        />
72
        <GroupsWidget />
73
      </Grid>
74
      <Grid size={{ xs: 12, md: 6 }} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
75
        <Box sx={{ display: { xs: 'flex', md: 'none' }, flexDirection: 'column', gap: 1 }}>
76
          {data?.routeDailyPulse && <DailyPulse dailyPulseUrl={data?.routeDailyPulse} />}
77
          <OnRoomWidget
78
            moodle={{
79
              image: data?.moodle_image,
80
              name: data?.moodle_name
81
            }}
82
          />
83
          <HabitsWidget />
84
          <MicrolearningWidget />
85
          <AppsWidget
86
            microlearning={{
87
              playStore: data?.microlearning_playstore,
88
              appStore: data?.microlearning_appstore,
89
              name: data?.microlearning_name
90
            }}
91
          />
92
        </Box>
93
        <FeedShare image={data?.image} feedType={feedTypes.DASHBOARD} postUrl='/feed/add' />
94
        <LoadingWrapper loading={loading}>
95
          <List
96
            items={allFeeds}
97
            elementsKey='feed_unique'
98
            emptyMessage='No hay publicaciones para mostrar'
99
            renderItem={(feed) => <Feed id={feed.feed_unique} />}
100
          />
101
 
102
          <Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
103
        </LoadingWrapper>
104
      </Grid>
105
 
106
      <Grid size={{ xs: 12, md: 3 }} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
107
        {data?.routeDailyPulse && <DailyPulse dailyPulseUrl={data?.routeDailyPulse} />}
108
        <PeopleYouMayKnow />
109
        <HomeNews />
110
      </Grid>
111
    </Grid>
112
  );
113
};
114
 
115
export default DashboardPage;