-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for participant attributes (#262)
- Loading branch information
1 parent
84d4bfd
commit fa5861a
Showing
12 changed files
with
844 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
import prisma from '../utils/database'; | ||
|
||
export const getAllAttributes = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
|
||
const attributes = await prisma.attributes.findMany({ | ||
where: { | ||
organizationId: orgId, | ||
eventId: eventId, | ||
}, | ||
}); | ||
|
||
if (!attributes) { | ||
return res.status(404).json({ error: 'No attributes found' }); | ||
} | ||
|
||
return res.status(200).json({ attributes }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const getAttributeById = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId, attributeId } = req?.params; | ||
|
||
const attribute = await prisma.attributes.findMany({ | ||
where: { | ||
organizationId: orgId, | ||
eventId, | ||
id: attributeId, | ||
}, | ||
include: { | ||
participantAttributes: { | ||
include: { | ||
participant: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!attribute) { | ||
return res.status(404).json({ error: 'No attributes found' }); | ||
} | ||
|
||
return res.status(200).json({ attribute }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; | ||
|
||
export const addNewAttribute = async (req: Request, res: Response) => { | ||
try { | ||
const { orgId, eventId } = req?.params; | ||
const { name } = req?.body; | ||
|
||
const newAttribute = await prisma.attributes.create({ | ||
data: { | ||
name, | ||
organizationId: orgId, | ||
eventId: eventId, | ||
}, | ||
}); | ||
|
||
return res.status(200).json({ newAttribute }); | ||
} catch (err: any) { | ||
console.error(err); | ||
return res.status(500).json({ error: 'Something went wrong' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...admin/src/pages/organizations/[orgId]/events/[eventId]/attributes/[attributeId]/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useRouter } from 'next/router'; | ||
|
||
import { | ||
Box, | ||
Flex, | ||
Table, | ||
TableCaption, | ||
Tbody, | ||
Td, | ||
Tfoot, | ||
Th, | ||
Thead, | ||
Tr, | ||
TableContainer, | ||
Text, | ||
} from '@chakra-ui/react'; | ||
|
||
import { useFetch } from '@/hooks/useFetch'; | ||
|
||
import DashboardLayout from '@/layouts/DashboardLayout'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default function Events() { | ||
const router = useRouter(); | ||
|
||
const { orgId, eventId, attributeId } = router.query; | ||
|
||
const { loading, get } = useFetch(); | ||
|
||
const [attribute, setAttribute] = useState({}); | ||
|
||
useEffect(() => { | ||
const fetchAttribute = async () => { | ||
const { data, status } = await get( | ||
`/core/organizations/${orgId}/events/${eventId}/attributes/${attributeId}`, | ||
); | ||
setAttribute(data.attribute || []); | ||
console.log(data); | ||
}; | ||
fetchAttribute(); | ||
}, [orgId, eventId, attributeId]); | ||
|
||
return ( | ||
<DashboardLayout> | ||
<Flex | ||
direction="column" | ||
height="100%" | ||
width="100%" | ||
alignItems="center" | ||
justifyContent="center" | ||
gap={8} | ||
> | ||
<Box width="100%" p={8}> | ||
<Text fontSize="4xl" fontWeight="bold"> | ||
Attribute Details | ||
</Text> | ||
</Box> | ||
<Box width="100%" height="100%"> | ||
{JSON.stringify(attribute)} | ||
</Box> | ||
</Flex> | ||
</DashboardLayout> | ||
); | ||
} |
109 changes: 109 additions & 0 deletions
109
apps/web-admin/src/pages/organizations/[orgId]/events/[eventId]/attributes/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { useRouter } from 'next/router'; | ||
|
||
import { | ||
Box, | ||
Flex, | ||
Table, | ||
TableCaption, | ||
Tbody, | ||
Td, | ||
Tfoot, | ||
Th, | ||
Thead, | ||
Tr, | ||
TableContainer, | ||
Text, | ||
Button, | ||
} from '@chakra-ui/react'; | ||
|
||
import { useFetch } from '@/hooks/useFetch'; | ||
|
||
import DashboardLayout from '@/layouts/DashboardLayout'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default function Events() { | ||
const router = useRouter(); | ||
|
||
const { orgId, eventId } = router.query; | ||
|
||
const { loading, get } = useFetch(); | ||
|
||
const [attributes, setAttributes] = useState([]); | ||
const handleClick = () => { | ||
router.push(`/organizations/${orgId}/events/${eventId}/attributes/new`); | ||
}; | ||
|
||
useEffect(() => { | ||
const fetchAttributes = async () => { | ||
const { data, status } = await get( | ||
`/core/organizations/${orgId}/events/${eventId}/attributes`, | ||
); | ||
setAttributes(data.attributes || []); | ||
console.log(data); | ||
}; | ||
fetchAttributes(); | ||
}, [orgId, eventId]); | ||
|
||
return ( | ||
<DashboardLayout> | ||
<Flex | ||
direction="column" | ||
height="100%" | ||
width="100%" | ||
alignItems="center" | ||
justifyContent="center" | ||
gap={8} | ||
> | ||
<Box width="100%" p={8} display="flex" justifyContent="space-between"> | ||
<Text fontSize="4xl" fontWeight="bold"> | ||
Attributes | ||
</Text> | ||
<Button | ||
padding="4" | ||
minWidth="-moz-initial" | ||
bgColor="rgb(128, 90, 213)" | ||
color="white" | ||
_hover={{ bgColor: 'rgb(100, 70, 183)' }} | ||
onClick={handleClick} | ||
> | ||
Add Attribute | ||
</Button> | ||
</Box> | ||
<Box width="100%" height="100%"> | ||
<TableContainer width="100%" height="100%"> | ||
<Table variant="simple"> | ||
<TableCaption>Attributes</TableCaption> | ||
<Thead> | ||
<Tr> | ||
<Th>ID</Th> | ||
<Th>Name</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{attributes.map((attribute) => ( | ||
<Tr | ||
key={attribute?.id} | ||
onClick={() => { | ||
router.push( | ||
`/organizations/${orgId}/events/${eventId}/attributes/${attribute?.id}`, | ||
); | ||
}} | ||
cursor="pointer" | ||
> | ||
<Td>{attribute?.id}</Td> | ||
<Td>{attribute?.name}</Td> | ||
</Tr> | ||
))} | ||
</Tbody> | ||
<Tfoot> | ||
<Tr> | ||
<Th>{attributes.length} attributes</Th> | ||
</Tr> | ||
</Tfoot> | ||
</Table> | ||
</TableContainer> | ||
</Box> | ||
</Flex> | ||
</DashboardLayout> | ||
); | ||
} |
Oops, something went wrong.