Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Catalog Page (Frontend) and Integrate w/ Backend #20

Merged
merged 9 commits into from
Jan 21, 2024
54 changes: 28 additions & 26 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './App.css';
import EmailSending from './components/EmailTemplates/EmailSending';
import { ChakraProvider, Text } from '@chakra-ui/react'
import { ChakraProvider } from '@chakra-ui/react';
import { Route, Routes, BrowserRouter as Router } from 'react-router-dom';
import { CookiesProvider } from 'react-cookie';
import Login from './components/Authentication/Login';
Expand All @@ -11,36 +11,38 @@ import ForgotPassword from './components/Authentication/ForgotPassword';
import EmailAction from './components/Authentication/EmailAction';
import AUTH_ROLES from './utils/auth_config';
import ProtectedRoute from './utils/ProtectedRoute';
import Catalog from './pages/Catalog/Catalog';

const { ADMIN_ROLE, USER_ROLE } = AUTH_ROLES.AUTH_ROLES;

const App = () => {
return (
<ChakraProvider>
<EmailSending />
<CookiesProvider>
<Router>
<Routes>
<Route exact path="/" element={<Login />} />
<Route exact path="/logout" element={<Logout />} />
<Route exact path="/forgotpassword" element={<ForgotPassword />} />
<Route exact path="/register" element={<Register />} />
<Route exact path="/emailAction" element={<EmailAction redirectPath="/" />} />
<Route
exact
path="/dashboard"
element={
<ProtectedRoute
Component={Dashboard}
redirectPath="/"
roles={[ADMIN_ROLE, USER_ROLE]}
/>
}
/>
</Routes>
</Router>
</CookiesProvider>
</ChakraProvider>
<ChakraProvider>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been a prettier change on my end to fix the formatting; should I revert this?

<EmailSending />
<CookiesProvider>
<Router>
<Routes>
<Route exact path="/" element={<Login />} />
<Route exact path="/logout" element={<Logout />} />
<Route exact path="/forgotpassword" element={<ForgotPassword />} />
<Route exact path="/register" element={<Register />} />
<Route exact path="/emailAction" element={<EmailAction redirectPath="/" />} />
<Route
exact
path="/dashboard"
element={
<ProtectedRoute
Component={Dashboard}
redirectPath="/"
roles={[ADMIN_ROLE, USER_ROLE]}
/>
}
/>
<Route exact path="/catalog" element={<Catalog />} />
</Routes>
</Router>
</CookiesProvider>
</ChakraProvider>
);
};

Expand Down
45 changes: 45 additions & 0 deletions src/pages/Catalog/Catalog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';
import { useState, useEffect } from 'react';
import { NPOBackend } from '../../utils/auth_utils';

export default function Catalog() {
const [tableData, setTableData] = useState([]);

useEffect(() => {
const fetchCatalogData = async () => {
const response = await NPOBackend.get('/catalog');
setTableData(response.data);
};

fetchCatalogData().catch(console.error);
}, []);

return (
<TableContainer>
<Table variant="simple">
<Thead>
<Tr>
<Th>Title</Th>
<Th>Host</Th>
<Th>Cohort Type</Th>
<Th>Event Type</Th>
<Th>Subject</Th>
<Th>Description</Th>
</Tr>
</Thead>
<Tbody>
{tableData.map(({ id, host, title, eventType, subject, description, year }) => (
<Tr key={id}>
<Td>{title}</Td>
<Td>{host}</Td>
<Td>{year}</Td>
<Td>{eventType}</Td>
<Td>{subject}</Td>
<Td>{description}</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
);
}
Loading