Skip to content
Snippets Groups Projects
Commit ad7ac9b5 authored by Veda Hegde's avatar Veda Hegde
Browse files

List All Organizations working

parent 357b6bb9
No related branches found
No related tags found
No related merge requests found
import * as React from 'react'; import React, { useState, useEffect} from 'react';
import Table from '@mui/material/Table'; import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody'; import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell'; import TableCell from '@mui/material/TableCell';
...@@ -10,77 +10,53 @@ import Paper from '@mui/material/Paper'; ...@@ -10,77 +10,53 @@ import Paper from '@mui/material/Paper';
import Axios from "axios"; import Axios from "axios";
import { Button } from '@mui/material'; import { Button } from '@mui/material';
// function createData(name, calories, fat, carbs, protein) { export const ListAllOrganizations = (props) => {
// return { name, calories, fat, carbs, protein }; const [rows, setRows] = useState([]); // State to store the rows
// }
// const rows = [ useEffect(() => {
// createData('Frozen yoghurt', 159, 6.0, 24, 4.0), const fetchOrganizations = async () => {
// createData('Ice cream sandwich', 237, 9.0, 37, 4.3), try {
// createData('Eclair', 262, 16.0, 24, 6.0), const response = await Axios.get("http://localhost:8080/organization/all");
// createData('Cupcake', 305, 3.7, 67, 4.3), setRows(response.data); // Update state with fetched data
// createData('Gingerbread', 356, 16.0, 49, 3.9), } catch (error) {
// ]; console.error('Error fetching data: ', error);
}
};
function createData() { fetchOrganizations();
}, []); // The empty array ensures this effect runs once on mount
}
const rows = [];
const handleSubmit = (e) => {
e.preventDefault();
Axios.get("http://localhost:8080/organization/all")
.then((response) => {
const posts = response.data; // json array
console.log("hello");
console.log(posts);
//rows.append(posts);
});
};
export const ListAllOrganizations = (props) =>{
// {(e) => handleSubmit(e.target.value)};
// handleSubmit(e);
return ( return (
<div> <div>
<button onClick={handleSubmit}>hi</button> <TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableContainer component={Paper}> <TableHead>
<Table sx={{ minWidth: 650 }} aria-label="simple table"> <TableRow>
<TableHead> <TableCell>Name</TableCell>
<TableRow> <TableCell align="right">Category</TableCell>
<TableCell>Dessert (100g serving)</TableCell> <TableCell align="right">Description</TableCell>
<TableCell align="right">Calories</TableCell> <TableCell align="right">Owner Email</TableCell>
<TableCell align="right">Fat&nbsp;(g)</TableCell> <TableCell align="right">Member Count</TableCell>
<TableCell align="right">Carbs&nbsp;(g)</TableCell>
<TableCell align="right">Protein&nbsp;(g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow
key={row.name}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow> </TableRow>
))} </TableHead>
</TableBody> <TableBody>
</Table> {rows.map((row) => (
</TableContainer> <TableRow
key={row.name}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.name}
</TableCell>
<TableCell align="right">{row.category}</TableCell>
<TableCell align="right">{row.description}</TableCell>
<TableCell align="right">{row.owner}</TableCell>
<TableCell align="right">{row.membercount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div> </div>
); );
} }
\ No newline at end of file
// export default ListAllOrganizations;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment