Completed JoinedOrgs route
This commit is contained in:
parent
1d72e09969
commit
cd5be03cdf
2 changed files with 62 additions and 2 deletions
|
|
@ -1,10 +1,40 @@
|
|||
import React, { useEffect } from 'react';
|
||||
import { Paper, Typography } from '@mui/material';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import Cookies from 'js-cookie';
|
||||
import { Paper, Typography, Box } from '@mui/material';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
|
||||
import OrgUnit from './OrgUnit';
|
||||
|
||||
function JoinedOrgs() {
|
||||
const [orgs, setOrgs] = useState([]);
|
||||
const theme = useTheme();
|
||||
|
||||
useEffect(() => {
|
||||
async function getOrgs() {
|
||||
axios
|
||||
.get(
|
||||
`${process.env.DOMAIN_ROOT}/auth/orgs?token=${Cookies.get(
|
||||
'token'
|
||||
)}`
|
||||
)
|
||||
.then((response) => {
|
||||
setOrgs(() =>
|
||||
response.data.map((org) => {
|
||||
return {
|
||||
orgID: org.orgID,
|
||||
orgName: org.orgName,
|
||||
memberCount: org.memberCount,
|
||||
orgCreatedAt: org.createdAt,
|
||||
};
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
getOrgs();
|
||||
});
|
||||
|
||||
return (
|
||||
<Paper
|
||||
sx={{
|
||||
|
|
@ -17,6 +47,11 @@ function JoinedOrgs() {
|
|||
}}
|
||||
>
|
||||
<Typography variant='h6'>Organizations</Typography>
|
||||
<Box sx={{ overflowY: 'auto' }}>
|
||||
{orgs.map((org) => (
|
||||
<OrgUnit org={org} />
|
||||
))}
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
25
client/src/components/OrgUnit.jsx
Normal file
25
client/src/components/OrgUnit.jsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Box, Stack, Typography } from '@mui/material';
|
||||
|
||||
function OrgUnit({ org }) {
|
||||
const { orgID, orgName, memberCount, orgCreatedAt } = org;
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Link to={orgID}>Name: {orgName}</Link>
|
||||
<Box>
|
||||
<Stack spacing={2} direction={{ xs: 'column', md: 'row' }}>
|
||||
<Typography variant='body1'>
|
||||
Members: {memberCount}
|
||||
</Typography>
|
||||
<Typography variant='body1'>
|
||||
Created On: {orgCreatedAt}
|
||||
</Typography>
|
||||
</Stack>
|
||||
</Box>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default OrgUnit;
|
||||
Reference in a new issue