Skip to content

Commit

Permalink
feat: IEDCMEC#603 seperated registrations for events with and without…
Browse files Browse the repository at this point in the history
… shortlisting, restricted access to registration page when registration is currently unavailable and added page to viewe registrant for admin
  • Loading branch information
Aaron-53 committed Dec 30, 2024
1 parent 38e37b4 commit 16ea704
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 50 deletions.
102 changes: 86 additions & 16 deletions apps/core-admin/src/controllers/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ export const orgAndEventVerification = async (req: Request, res: Response) => {
where: {
id: eventId,
},
select: {
organizationId: true,
isRegistrationClosed: true,
},
});
if (!event) {
return res.status(404).json({ error: 'Event not found' });
}
if (event.organizationId != orgId) {
} else if (event.organizationId != orgId) {
return res.status(404).json({ error: "Organisation and event don't match" });
} else if (event.isRegistrationClosed) {
return res.status(403).json({ error: 'Registration currently unavailable' });
}
return res.status(200).json({ msg: 'Event corresponds to the given org and both exists' });
} catch (err: any) {
Expand All @@ -29,6 +34,19 @@ export const addFormResponse = async (req: Request, res: Response) => {
const { orgId, eventId } = req?.params;
const data = req?.body;

const event = await prisma.event.findFirst({
where: {
id: eventId,
},
select: {
isShortlisting: true,
},
});

if (!event) {
return res.status(404).json({ error: 'Event not found' });
}

const defaultKeys = ['firstName', 'lastName', 'email', 'phone'];
const defaultData: { [key: string]: string } = {};
const attrData: { attributeId: string; value: string }[] = [];
Expand All @@ -44,21 +62,35 @@ export const addFormResponse = async (req: Request, res: Response) => {
}
}

const newRegistrant = await prisma.registrant.create({
data: {
firstName: defaultData['firstName'],
lastName: defaultData['lastName'] || null,
email: defaultData['email'],
phone: defaultData['phone'] || null,
eventId: eventId,
organizationId: orgId,
registrantAttributes: {
create: attrData,
},
},
});
const newAttendee = event.isShortlisting
? await prisma.registrant.create({
data: {
firstName: defaultData['firstName'],
lastName: defaultData['lastName'] || null,
email: defaultData['email'],
phone: defaultData['phone'] || null,
eventId: eventId,
organizationId: orgId,
registrantAttributes: {
create: attrData,
},
},
})
: await prisma.participant.create({
data: {
firstName: defaultData['firstName'],
lastName: defaultData['lastName'] || null,
email: defaultData['email'],
phone: defaultData['phone'] || null,
eventId: eventId,
organizationId: orgId,
participantAttributes: {
create: attrData,
},
},
});

return res.status(200).json({ newRegistrant });
return res.status(200).json({ newAttendee });
} catch (err: any) {
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
Expand Down Expand Up @@ -105,3 +137,41 @@ export const getFormAttributes = async (req: Request, res: Response) => {
return res.status(500).json({ error: 'Something went wrong' });
}
};

export const getAllRegistrations = async (req: Request, res: Response) => {
try {
const { orgId, eventId } = req?.params;
let registrants = await prisma.registrant.findMany({
where: {
organizationId: orgId,
eventId,
},
include: {
registrantAttributes: true,
registrantExtras: true,
},
});

if (!registrants) {
return res.status(500).json({ error: 'Something went wrong' });
}

registrants = registrants.map((registrant: any) => {
return {
id: registrant.id,
addedAt: registrant.createdAt,
firstName: registrant.firstName,
lastName: registrant.lastName,
phone: registrant.phone,
email: registrant.email,
numberOfAttributesAssigned: registrant.registrantAttributes.length,
numnerOfExtrasAssigned: registrant.registrantExtras.length,
};
});

return res.status(200).json({ registrants });
} catch (err: any) {
console.error(err);
return res.status(500).json({ error: 'Something went wrong' });
}
};
2 changes: 2 additions & 0 deletions apps/core-admin/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
updateParticipantAttribute,
getParticipantBycheckInKey,
} from './controllers/participants';
import { getAllRegistrations } from './controllers/registration';
import {
addNewAttribute,
editAttribute,
Expand Down Expand Up @@ -79,6 +80,7 @@ router.get('/organizations/:orgId/events/:eventId', getEventStats); //midhun //m
router.post('/organizations/:orgId/events', createNewEvent); //midhun

router.get('/organizations/:orgId/events/:eventId/participants', getAllParticipants); //midhun //midhun - done
router.get('/organizations/:orgId/events/:eventId/registrations', getAllRegistrations);
router.post('/organizations/:orgId/events/:eventId/participants', addNewParticipant);
router.put('/organizations/:orgId/events/:eventId/participants/:participantId', editParticipant);

Expand Down
2 changes: 2 additions & 0 deletions apps/registration-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChakraProvider } from '@chakra-ui/react';
import Form from './pages/Form';
import NotFound from './pages/NotFound';
import Registered from './pages/Registered';
import RegistrationClosed from './pages/RegistrationClosed';

const App = () => {
return (
Expand All @@ -11,6 +12,7 @@ const App = () => {
<Routes>
<Route path="/event/:eventID/:orgID" element={<Form />} />
<Route path="/already-registered" element={<Registered />} />
<Route path="/registrationclosed" element={<RegistrationClosed />} />
<Route path="*" element={<NotFound />} />
</Routes>
</ChakraProvider>
Expand Down
8 changes: 7 additions & 1 deletion apps/registration-admin/src/hooks/useFetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export const useFetch = () => {
} catch (err) {
console.error(err);
setLoading(false);
return null;
if (axios.isAxiosError(err) && err.response) {
console.error(`Error: ${err.response.status} - ${err.response.statusText}`);
return { data: err.response.data, status: err.response.status };
} else {
console.error('Error: Unable to process the request.');
return null;
}
}
};

Expand Down
4 changes: 3 additions & 1 deletion apps/registration-admin/src/pages/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const Form = () => {
status: 'error',
});
}
} else if (checkResponse?.status === 403) {
navigate('/registrationclosed');
} else {
navigate('/');
}
Expand Down Expand Up @@ -58,7 +60,7 @@ const Form = () => {
description: 'Form submitted successfully!',
status: 'success',
});
navigate('/');
navigate('/already-registered');
} else {
showAlert({
title: 'Error',
Expand Down
4 changes: 2 additions & 2 deletions apps/registration-admin/src/pages/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import { Box, Heading, Text, Center } from '@chakra-ui/react';

const NotFound: React.FC = () => {
const NotFound: React.FC<{ msg?: String }> = ({ msg }) => {
return (
<Center height="100vh" flexDirection="column" bg="gray.100">
<Box textAlign="center" p={6} borderRadius="md" boxShadow="lg" bg="white">
<Heading as="h1" size="2xl" mb={4} color="red.500">
404
</Heading>
<Text fontSize="lg" mb={4}>
Sorry, the page you are looking for does not exist.
{msg || 'Sorry, the page you are looking for does not exist.'}
</Text>
</Box>
</Center>
Expand Down
19 changes: 19 additions & 0 deletions apps/registration-admin/src/pages/RegistrationClosed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { Box, Heading, Text, Center } from '@chakra-ui/react';

const RegistrationClosed: React.FC = () => {
return (
<Center height="100vh" flexDirection="column" bg="gray.100">
<Box textAlign="center" p={6} borderRadius="md" boxShadow="lg" bg="white">
<Heading as="h1" size="2xl" mb={4} color="red.500">
Registration Closed
</Heading>
<Text fontSize="lg" mb={4}>
The registrations for this event is not currently active
</Text>
</Box>
</Center>
);
};

export default RegistrationClosed;
2 changes: 1 addition & 1 deletion apps/registration-admin/tsconfig.app.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/hooks/usealert.tsx","./src/hooks/usefetch.tsx","./src/pages/form.tsx","./src/pages/notfound.tsx","./src/pages/registered.tsx"],"version":"5.7.2"}
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/hooks/usealert.tsx","./src/hooks/usefetch.tsx","./src/pages/form.tsx","./src/pages/notfound.tsx","./src/pages/registered.tsx","./src/pages/registrationclosed.tsx"],"version":"5.7.2"}
3 changes: 3 additions & 0 deletions apps/web-admin/src/contexts/MyContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const MyContext = ({ children }) => {
const { user, isAuthenticated, isLoading, loginWithRedirect } = useAuth0();
const [participants, setParticipants] = useState([]);
const [userDetails, setUserDetails] = useState([]);
const [eventDetails, setEventDetails] = useState({});

const { loading, get, put } = useFetch();
const showAlert = useAlert();
Expand Down Expand Up @@ -76,6 +77,8 @@ const MyContext = ({ children }) => {
updateAccountDetails,
participants,
setParticipants,
eventDetails,
setEventDetails,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ const NavigationMenu = ({ orgId, eventId }) => {
width: { base: '100%', md: 'auto' },
});
const router = useRouter();
const navItems = [
{ link: 'participants', name: 'Participants' },
{ link: 'check-in', name: 'Participants Check In' },
{ link: 'attributes', name: 'Attributes' },
{ link: 'extras', name: 'Extras' },
];
const { activeTab, setActiveTab } = useContext(account);
const { activeTab, setActiveTab, eventDetails } = useContext(account);
console.log('trial', eventDetails.isShortlisting);
const navItems =
eventDetails.isShortlisting && router.asPath.endsWith('/participants')
? [
{ link: 'registrants', name: 'Registrants' },
{ link: 'check-in', name: 'Participants Check In' },
{ link: 'attributes', name: 'Attributes' },
{ link: 'extras', name: 'Extras' },
]
: [
{ link: 'participants', name: 'Participants' },
{ link: 'check-in', name: 'Participants Check In' },
{ link: 'attributes', name: 'Attributes' },
{ link: 'extras', name: 'Extras' },
];
useEffect(() => {
//console.log(activeTab);
}, [activeTab]);
Expand Down Expand Up @@ -94,24 +103,27 @@ const NavigationMenu = ({ orgId, eventId }) => {
width="100%"
display={{ base: 'none', md: 'flex' }} // Horizontal layout on desktop
>
{['participants', 'check-in', 'attributes', 'extras'].map((tab) => (
<Button
key={tab}
style={tabStyle(activeTab === tab)}
onClick={() => {
setActiveTab(tab);
const element = tab === 'check-in' ? 'participants/check-in' : tab;
router.push(
`/${orgId}/events/${eventId}/${element}
{navItems.map((content) => {
const tab = content.link;
return (
<Button
key={tab}
style={tabStyle(activeTab === tab)}
onClick={() => {
setActiveTab(tab);
const element = tab === 'check-in' ? 'participants/check-in' : tab;
router.push(
`/${orgId}/events/${eventId}/${element}
`,
);
}}
>
{tab === 'check-in'
? 'Participant Check In'
: tab.replace(/(^\w|\s\w)/g, (m) => m.toUpperCase())}
</Button>
))}
);
}}
>
{tab === 'check-in'
? 'Participant Check In'
: tab.replace(/(^\w|\s\w)/g, (m) => m.toUpperCase())}
</Button>
);
})}
</Flex>
</Box>
);
Expand Down
Loading

0 comments on commit 16ea704

Please sign in to comment.