import React, { useState, useEffect, useContext } from "react"; import Paper from '@mui/material/Paper'; import Moment from 'react-moment'; import { useParams, useNavigate } from "react-router-dom"; import './Dashboard.css'; import { GlobalContext } from "./GlobalContext.js"; import { base } from "./Common.js"; function Dashboard() { const { csrfToken, user, setUser } = useContext(GlobalContext); const [ groups, setGroups ] = useState([]); const [ error, setError ] = useState(null); useEffect(() => { if (!user || !csrfToken) { return; } const effect = async () => { const res = await window.fetch( `${base}/api/v1/groups`, { method: 'POST', cache: 'no-cache', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'CSRF-Token': csrfToken } }); const data = await res.json(); if (res.status >= 400) { setError(data.message ? data.message : res.statusText); return; } if (!data) { return; } setGroups(data); } effect(); }, [user, setGroups, csrfToken ]); return ( { groups.map((group) => { return
{group.name}
{ group.nextEvent &&
Next event on .
}
; }) }
); } export default Dashboard;