Skip to content

Commit

Permalink
fix: A lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alllenshibu committed Feb 22, 2024
1 parent 62be976 commit baba4b5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 84 deletions.
23 changes: 14 additions & 9 deletions apps/core-admin/src/controllers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@ export const getOrganizationMembers = async (req: Request, res: Response) => {
try {
const organizationId = req.params.orgId;

const organizationUsers = await prisma.organizationUser.findMany({
let organizationUsers = await prisma.organizationUser.findMany({
where: {
organizationId,
},
include: {
user: true,
},
});
const users = await prisma.user.findMany({
where: {
id: {
in: organizationUsers.map((ou: { userId: any }) => ou.userId),
},
},
});

return res.status(200).json({ organizationUsers, users });
organizationUsers = organizationUsers.map((organizationUser: any) => ({
id: organizationUser.id,
role: organizationUser.role,
createdAt: organizationUser.createdAt,
updatedAt: organizationUser.updatedAt,
organizationId: organizationUser.organizationId,
userId: organizationUser.userId,
firstName: organizationUser.user.firstName,
lastName: organizationUser.user.lastName,
email: organizationUser.user.email,
}));

return res.status(200).json({ organizationUsers });
} catch (err: any) {
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
Expand Down
76 changes: 31 additions & 45 deletions apps/web-admin/src/pages/organizations/[orgId]/members/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import { useFetch } from '@/hooks/useFetch';

import DashboardLayout from '@/layouts/DashboardLayout';
import { useEffect, useState } from 'react';
import { DataGrid, GridToolbar } from '@mui/x-data-grid';
import { ThemeProvider, createTheme } from '@mui/material';
const MuiTheme = createTheme({});

export default function Members() {
const router = useRouter();
Expand All @@ -33,31 +30,6 @@ export default function Members() {

const [members, setMembers] = useState([]);

const columns = [
{
field: 'email',
headerName: 'Email',
width: 250,
valueGetter: (params) => params.row.user.email,
},
{
field: 'firstName',
headerName: 'First Name',
width: 150,
valueGetter: (params) => params.row.user.firstName || 'null',
},
{
field: 'lastName',
headerName: 'Last Name',
width: 150,
valueGetter: (params) => params.row.user.lastName || 'null',
},
{
field: 'role',
headerName: 'Role',
},
];

useEffect(() => {
const fetchmembers = async () => {
const { data, status } = await get(`/core/organizations/${orgId}/members`);
Expand All @@ -78,7 +50,7 @@ export default function Members() {
>
<Box width="100%" p={8} display="flex" justifyContent="space-between">
<Text fontSize="4xl" fontWeight="bold">
members
Members
</Text>
<Button
padding="4"
Expand All @@ -94,22 +66,36 @@ export default function Members() {
</Button>
</Box>
<Box width="100%" height="100%">
<ThemeProvider theme={MuiTheme}>
<DataGrid
rows={members}
columns={columns}
slotProps={{
toolbar: {
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
},
}}
slots={{
toolbar: GridToolbar,
}}
autoHeight
/>
</ThemeProvider>
<TableContainer width="100%" height="100%">
<Table variant="simple">
<TableCaption>Members</TableCaption>
<Thead>
<Tr>
<Th>ID</Th>
<Th>Email</Th>
<Th>Role</Th>
<Th>First Name</Th>
<Th>Last Name</Th>
</Tr>
</Thead>
<Tbody>
{members.map((member) => (
<Tr key={member?.id}>
<Td>{member?.id}</Td>
<Td>{member?.email}</Td>
<Td>{member?.role}</Td>
<Td>{member?.firstName}</Td>
<Td>{member?.lastName}</Td>
</Tr>
))}
</Tbody>
<Tfoot>
<Tr>
<Th>{members.length} members</Th>
</Tr>
</Tfoot>
</Table>
</TableContainer>
</Box>
</Flex>
</DashboardLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function NewOrganization() {
},
);
if (status === 200) {
router.push(`/organizations/${orgId}/users`);
router.push(`/organizations/${orgId}/members`);
} else {
alert(data.error);
}
Expand Down
62 changes: 33 additions & 29 deletions apps/web-admin/src/pages/organizations/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useRouter } from 'next/router';
import Link from 'next/link';
import {
Box,
Flex,
Table,
TableCaption,
Card,
CardBody,
Tbody,
Td,
Tfoot,
Expand All @@ -23,6 +26,7 @@ const MuiTheme = createTheme({});

import DashboardLayout from '@/layouts/DashboardLayout';
import { useEffect, useState } from 'react';
import { purple } from '@mui/material/colors';

export default function Organizations() {
const router = useRouter();
Expand Down Expand Up @@ -88,35 +92,35 @@ export default function Organizations() {
</Button>
</Box>
<Box width="100%" height="100%">
<ThemeProvider theme={MuiTheme}>
<DataGrid
rows={organizations}
columns={columns}
slotProps={{
toolbar: {
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
},
}}
slots={{
toolbar: GridToolbar,
}}
autoHeight
sx={{
// disable cell selection style
'.MuiDataGrid-cell:focus': {
outline: 'none',
},
// pointer cursor on ALL rows
'& .MuiDataGrid-row:hover': {
cursor: 'pointer',
},
}}
onRowClick={(row) => {
router.push(`/organizations/${row.id}/events`);
}}
/>
</ThemeProvider>
{organizations.length === 0 && (
<Flex height="100%" width="100%" justifyContent="center" alignItems="center">
<Text fontSize="2xl" fontWeight="semibold">
You do not have any organizations yet. Please{' '}
<Link href="/organizations/new">
<Text as="span" color="purple" textDecoration="underline">
create one
</Text>
</Link>{' '}
to start managing events.
</Text>
</Flex>
)}
<Flex gap={4}>
{organizations.map((organization) => (
<Card
key={organization.id}
cursor="pointer"
onClick={() => {
router.push(`/organizations/${organization.id}`);
}}
>
<CardBody>
<Text>{organization?.id}</Text>
<Text>{organization?.name}</Text>
</CardBody>
</Card>
))}
</Flex>
</Box>
</Flex>
</DashboardLayout>
Expand Down

0 comments on commit baba4b5

Please sign in to comment.