Skip to content

Commit

Permalink
added some frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaRaimec22 committed Mar 26, 2024
1 parent b9df0aa commit 0fd8403
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 37 deletions.
4 changes: 0 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ type AuthData {

type CheckIn {
_id: ID!
allotedRoom: String
allotedSeat: String
event: Event!
feedbackSubmitted: Boolean!
time: DateTime!
user: User!
}

input CheckInInput {
allotedRoom: String
allotedSeat: String
eventId: ID!
userId: ID!
}
Expand Down
34 changes: 18 additions & 16 deletions src/GraphQl/Mutations/EventAttendeeMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ export const ADD_EVENT_ATTENDEE = gql`
}
`;

/**
* GraphQL mutation to invite an user for an event
*
* @param userId - The ID of the user being invited.
* @param eventId - The ID of the event to which the user is being invited.
* @return The updated event object with the added invited user.
*/

export const INVITE_USER = gql`
mutation InviteUser($userId: ID!, $eventId: ID!) {
addEventAttendee(data: { userId: $userId, eventId: $eventId }) {
_id
}
}
`;

/**
* GraphQL mutation to remove an attendee from an event.
*
Expand All @@ -37,26 +53,12 @@ export const REMOVE_EVENT_ATTENDEE = gql`
*
* @param userId - The ID of the user checking in.
* @param eventId - The ID of the event at which the user is checking in.
* @param allotedRoom - The room assigned to the user during check-in (optional).
* @param allotedSeat - The seat assigned to the user during check-in (optional).
* @returns The updated event object with the user's check-in information.
*/

export const MARK_CHECKIN = gql`
mutation checkIn(
$userId: ID!
$eventId: ID!
$allotedRoom: String
$allotedSeat: String
) {
checkIn(
data: {
userId: $userId
eventId: $eventId
allotedRoom: $allotedRoom
allotedSeat: $allotedSeat
}
) {
mutation checkIn($userId: ID! $eventId: ID!) {
checkIn(data: {userId: $userId eventId: $eventId}) {
_id
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/GraphQl/Queries/Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ export const EVENT_ATTENDEES = gql`
}
`;

export const GET_EVENT_ATTENDEE = gql`
query getEventAttendee($userId: ID!, $eventId: ID!) {
getEventAttendee(userId: $userId, eventId: $eventId) {
_id
}
}
`

export const EVENT_CHECKINS = gql`
query eventCheckIns($id: ID!) {
event(id: $id) {
Expand All @@ -252,8 +260,6 @@ export const EVENT_CHECKINS = gql`
checkIn {
_id
time
allotedRoom
allotedSeat
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/CheckIn/TableRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ describe('Testing Table Row for CheckIn Table', () => {
checkIn: {
_id: '123',
time: '12:00:00',
allotedRoom: '',
allotedSeat: '',
},
eventId: `event123`,
},
Expand Down
3 changes: 0 additions & 3 deletions src/components/CheckIn/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ export const TableRow = ({
const [checkInMutation] = useMutation(MARK_CHECKIN);

const markCheckIn = (): void => {
// Since the backend supports the storage of the alloted seat and the alloted room to the user, we pass the same as blank
// as we do not want to clutter the UI currently with the same (only provide the most basic of operations)
checkInMutation({
variables: {
userId: data.userId,
eventId: data.eventId,
allotedSeat: '',
allotedRoom: '',
},
})
.then(() => {
Expand Down
6 changes: 0 additions & 6 deletions src/components/CheckIn/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const checkInQueryData: InterfaceAttendeeQueryResponse = {
checkIn: {
_id: 'checkin1',
time: '08:00:00',
allotedRoom: 'Room 1',
allotedSeat: 'Seat 1',
},
},
],
Expand All @@ -52,8 +50,6 @@ export const checkInMutationSuccess = [
variables: {
userId: 'user123',
eventId: 'event123',
allotedSeat: '',
allotedRoom: '',
},
},
result: {
Expand All @@ -73,8 +69,6 @@ export const checkInMutationUnsuccess = [
variables: {
userId: 'user123',
eventId: 'event123',
allotedSeat: '',
allotedRoom: '',
},
},
error: new Error('Oops'),
Expand Down
4 changes: 0 additions & 4 deletions src/components/CheckIn/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export interface InterfaceAttendeeCheckIn {
checkIn: null | {
_id: string;
time: string;
allotedRoom: string;
allotedSeat: string;
};
}

Expand All @@ -35,8 +33,6 @@ export interface InterfaceTableCheckIn {
checkIn: null | {
_id: string;
time: string;
allotedRoom: string;
allotedSeat: string;
};
eventId: string;
}
Expand Down
43 changes: 43 additions & 0 deletions src/components/InviteUsers/InviteUserModal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.loader,
.loader:after {
border-radius: 50%;
width: 10em;
height: 10em;
}
.loader {
margin: 60px auto;
margin-top: 35vh !important;
font-size: 10px;
position: relative;
text-indent: -9999em;
border-top: 1.1em solid rgba(255, 255, 255, 0.2);
border-right: 1.1em solid rgba(255, 255, 255, 0.2);
border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);
border-left: 1.1em solid #febc59;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation: load8 1.1s infinite linear;
animation: load8 1.1s infinite linear;
}

@-webkit-keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
131 changes: 131 additions & 0 deletions src/components/InviteUsers/InviteUsersModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React, {useState} from "react";
import { Modal, Button } from "react-bootstrap";
import { toast } from "react-toastify";
import { useMutation, useQuery } from "@apollo/client";
import { INVITE_USER } from "GraphQl/Mutations/EventAttendeeMutations";
import styles from './InviteUserModal.module.css'
import Avatar from '@mui/material/Avatar';
import Chip from '@mui/material/Chip';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import { GET_EVENT_ATTENDEE, MEMBERS_LIST } from "GraphQl/Queries/Queries";

type ModalPropType = {
show: boolean;
eventId: string;
orgId: string;
handleClose: () => void;
};

interface InterfaceUser {
_id: string;
firstName: string;
lastName: string;
}

export const InviteUserModal = (props: ModalPropType): JSX.Element => {
const [member, setMember] = useState<InterfaceUser | null>(null);

const [inviteUsersMutation] = useMutation(INVITE_USER);

const {
data: invitedUserData,
loading: invitedUserLoading,
refetch: invitedUsersRefectch,
} = useQuery(GET_EVENT_ATTENDEE, {
variables: { id: props.eventId },
});

const { data: memberData, loading: memberLoading } = useQuery(MEMBERS_LIST, {
variables: { id: props.orgId },
});

const InviteEventAttendee = (): void => {
if(member === null) {
toast.warning(`Please choose an user to Invite first!`);
return;
}
toast.warn(`Inviting the attendee...`);
inviteUsersMutation({
variables: {
userId: member._id,
eventId: props.eventId,
},
})
.then(() => {
toast.success(`Invited the Attendee successfully!`);
invitedUsersRefectch();
})
.catch((err) => {
toast.error('There was an error in adding the attendee!');
toast.error(err.message);
});
};

// Render the loading screen
if (invitedUserLoading || memberLoading) {
return (
<>
<div className={styles.loader}></div>
</>
);
}

return (
<>
<Modal
show={props.show}
onHide={props.handleClose}
backdrop="static"
centered
>
<Modal.Header closeButton className="bg-primary">
<Modal.Title className="text-white">Invite Event Attendee</Modal.Title>
</Modal.Header>
<Modal.Body>
<h5 className="mb-2">Registered Registrants</h5>
{invitedUserData.event.attendee.length == 0
? `There are no registered attendee for this event.`
: null}
<Stack direction="row" className="flex-wrap gap-2">
{invitedUserData.event.attendee.map((invitedAttendee: InterfaceUser) => {
<Chip
avatar={
<Avatar>{`${invitedAttendee.firstName[0]} ${invitedAttendee.lastName[0]}`}</Avatar>
}
label={`${invitedAttendee.firstName} ${invitedAttendee.lastName}`}
variant="outlined"
key={invitedAttendee._id}
/>
})}
</Stack>
<br/>
<Autocomplete
id="inviteAttendee"
onChange={(_, member): void => {
setMember(member);
}}
options={memberData.organizations[0].members}
getOptionLabel={(member: InterfaceUser): string =>
`${member.firstName} ${member.lastName}`
}
renderInput={(params): React.ReactNode => (
<TextField
{...params}
label="Add an Registrant"
placeholder="Choose the user that you want to add"
/>
)}
/>
<br/>
</Modal.Body>
<Modal.Footer>
<Button variant="success" onClick={InviteEventAttendee}>
Invite Attendee
</Button>
</Modal.Footer>
</Modal>
</>
)
}
14 changes: 14 additions & 0 deletions src/components/InviteUsers/InviteUsersWrapper.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
button .iconWrapper {
width: 32px;
padding-right: 4px;
margin-right: 4px;
transform: translateY(4px);
}

button .iconWrapperSm {
width: 32px;
display: flex;
justify-content: center;
align-items: center;
}

Loading

0 comments on commit 0fd8403

Please sign in to comment.