frontend/src/screens/Dashboard.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-09-04 16:30:36 +00:00
import React, { useEffect, useState } from 'react';
2020-09-04 16:50:50 +00:00
import { Panel, Placeholder, Loader } from 'rsuite';
2020-05-13 17:39:43 +00:00
2020-09-04 16:30:36 +00:00
import { NavBar, MeetingList } from '../components';
2020-05-13 17:39:43 +00:00
2020-09-04 16:30:36 +00:00
import './styles/layout.less';
import { backend } from '../helpers/http-common';
2020-09-04 16:50:50 +00:00
const { Paragraph } = Placeholder;
2020-09-04 16:30:36 +00:00
export default function Dashboard({ currentUser }) {
const [meetings, setMeetings] = useState([]);
const [confirmed, setConfirmed] = useState();
const [unconfirmed, setUnconfirmed] = useState();
2020-09-04 16:50:50 +00:00
const [loading, setLoading] = useState(true);
2020-09-04 16:30:36 +00:00
useEffect(() => {
backend
.get(`/accounts/${currentUser.id}/meetings`)
.then((response) => {
const allMeetings = response.data;
const confirmed = allMeetings.filter(
(meeting) => meeting.start_time,
);
const unconfirmed = allMeetings.filter(
(meeting) => !meeting.start_time,
);
setConfirmed(confirmed);
setUnconfirmed(unconfirmed);
setMeetings(allMeetings);
2020-09-04 16:50:50 +00:00
setLoading(false);
2020-09-04 16:30:36 +00:00
})
.catch((error) => console.log(error));
}, []);
2020-08-21 22:08:42 +00:00
2020-05-13 17:39:43 +00:00
return (
2020-08-21 22:08:42 +00:00
<>
2020-09-04 16:30:36 +00:00
<NavBar title='Dashboard' />
2020-09-04 16:50:50 +00:00
{loading ? (
2020-09-04 17:00:52 +00:00
<Panel className={'app-container-small'}>
2020-09-04 16:50:50 +00:00
<h2>Invitations</h2>
<h4>Confirmed</h4>
<Paragraph style={{ marginTop: 30 }} graph='square'>
<Loader backdrop content='loading...' vertical />
</Paragraph>
<h4>To confirm</h4>
<Paragraph style={{ marginTop: 30 }} graph='square'>
<Loader backdrop content='loading...' vertical />
</Paragraph>
</Panel>
) : (
2020-09-04 17:00:52 +00:00
<Panel className={'app-container-small'}>
2020-09-04 16:50:50 +00:00
<h2>Invitations</h2>
{confirmed && (
<MeetingList
meetings={confirmed}
status={'Confirmed'}
/>
)}
{unconfirmed && (
<MeetingList
meetings={unconfirmed}
status={'To confirm'}
/>
)}
{meetings.length === 0 && <p>You have no meetings.</p>}
</Panel>
)}
2020-08-21 22:08:42 +00:00
</>
2020-05-13 17:39:43 +00:00
);
}