Skip to content

Commit

Permalink
new commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaRaimec22 committed Apr 6, 2024
1 parent 2579838 commit 84e0256
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 217 deletions.
6 changes: 4 additions & 2 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"location": "Location",
"about": "About",
"deleteThisOrganization": "Delete This Organization",
"eventInvites": "Event Invites",
"statistics": "Statistics",
"members": "Members",
"admins": "Admins",
Expand All @@ -197,8 +198,9 @@
"noUpcomingEvents": "No Upcoming Events",
"latestPosts": "Latest Posts",
"noPostsPresent": "No Posts Present",
"membershipRequests": "Membership requests",
"noMembershipRequests": "No Membership requests present",
"noEventInvites": "No Event Invites Found.",
"membershipRequests": "Membership requests",
"talawaApiUnavailable": "Talawa-API service is unavailable. Is it running? Check your network connectivity too."
},
"organizationPeople": {
Expand Down Expand Up @@ -661,7 +663,7 @@
"addedAsAdmin": "User is added as admin.",
"talawaApiUnavailable": "Talawa-API service is unavailable. Kindly check your network connection and wait for a while.",
"noEventInvites": "No Event Invites Found.",
"viewAll":"View All"
"viewAll": "View All"
},
"userLogin": {
"login": "Login",
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQl/Mutations/EventAttendeeMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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.
Expand Down Expand Up @@ -57,8 +57,8 @@ export const REMOVE_EVENT_ATTENDEE = gql`
*/

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

export const GET_EVENT_ATTENDEE = gql`
query getEventAttendee($userId: ID!, $eventId: ID!) {
getEventAttendee(userId: $userId, eventId: $eventId) {
_id
query GetEventAttendeesByEventId($eventId: ID!) {
getEventAttendeesByEventId(eventId: $eventId) {
userId
isInvited
}
}
`;
Expand Down Expand Up @@ -337,9 +338,10 @@ export const ORGANIZATIONS_LIST = gql`

//Query to get all the event invites for an user.
export const GET_EVENT_INVITES = gql`
query ExampleQuery($eventId: ID!) {
getEventAttendeesByEventId(eventId: $eventId) {
userId
query GetEventInvitesByUserId($userId: ID!) {
getEventInvitesByUserId(userId: $userId) {
eventId
isRegistered
}
}
`;
Expand Down
243 changes: 132 additions & 111 deletions src/components/InviteUsers/InviteUsersModal.tsx
Original file line number Diff line number Diff line change
@@ -1,131 +1,152 @@
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 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";
import { GET_EVENT_ATTENDEE, MEMBERS_LIST } from 'GraphQl/Queries/Queries';

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

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

interface InterfaceUser2 {
userId: string;
isInvited: boolean;
}

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

const [inviteUsersMutation] = useMutation(INVITE_USER);
const [inviteUsersMutation] = useMutation(INVITE_USER);

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

const { data: memberData, loading: memberLoading } = useQuery(MEMBERS_LIST, {
variables: { id: props.orgId },
});
console.log(JSON.stringify(invitedUserData, null, 2));
// console.log(`ye hai na: ${invitedUserData.getEventAttendeesByEventId}`);

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);
});
};
const { data: memberData, loading: memberLoading } = useQuery(MEMBERS_LIST, {
variables: { id: props.orgId },
});

// Render the loading screen
if (invitedUserLoading || memberLoading) {
return (
<>
<div className={styles.loader}></div>
</>
);
console.log(`organization data is: ${memberData}`);

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 (
<>
<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>
</>
)
}
<>
<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.getEventAttendeesByEventId.length === 0
? `There are no registered attendee for this event.`
: null}
<Stack direction="row" className="flex-wrap gap-2">
{invitedUserData.getEventAttendeesByEventId.map(
(invitedAttendee: InterfaceUser2) => {
console.log(JSON.stringify(invitedAttendee, null, 2));
console.log(`mera answer hai: ${invitedAttendee.userId}`);
return (
<React.Fragment key={invitedAttendee.userId}>
<Chip
avatar={
<Avatar>{`${invitedAttendee.userId} ${invitedAttendee.userId}`}</Avatar>
}
label={`${invitedAttendee.userId} ${invitedAttendee.userId}`}
variant="outlined"
key={invitedAttendee.userId}
/>
</React.Fragment>
);
},
)}
</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>
</>
);
};
25 changes: 12 additions & 13 deletions src/components/InviteUsers/InviteUsersWrapper.module.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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;
}

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 84e0256

Please sign in to comment.