Skip to content

Commit 25cbf3b

Browse files
committed
added calendar event confirmation
1 parent 5e59260 commit 25cbf3b

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed

src/Mutations/event.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,28 @@ export const CANCEL_EVENT = gql`
117117
}
118118
}
119119
`
120+
121+
export const RESPOND_TO_EVENT_INVITATION = gql`
122+
mutation RespondToEventInvitation(
123+
$eventId: String!
124+
$inviteeResponse: String!
125+
$authToken: String!
126+
) {
127+
respondToEventInvitation(
128+
eventId: $eventId,
129+
inviteeResponse: $inviteeResponse,
130+
authToken: $authToken
131+
) {
132+
end
133+
hostName
134+
start
135+
timeToEnd
136+
title
137+
timeToStart
138+
invitees {
139+
email,
140+
status
141+
}
142+
}
143+
}
144+
`
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { useMutation } from "@apollo/client";
2+
import React, { useEffect, useState } from "react";
3+
import { useTranslation } from "react-i18next";
4+
import { toast } from "react-toastify"
5+
import moment from "moment";
6+
import { RESPOND_TO_EVENT_INVITATION } from "../Mutations/event";
7+
import { Link } from "react-router-dom";
8+
9+
const CalendarConfirmation = () => {
10+
const { t } = useTranslation()
11+
const [respondToEventInvitation] = useMutation(RESPOND_TO_EVENT_INVITATION)
12+
const params = new URLSearchParams(window.location.search)
13+
14+
if (!params.get('eventId') || !params.get('response')) toast.error("Missing URL Parameters")
15+
16+
const [event, setEvent] = useState({
17+
title: '',
18+
hostName: '',
19+
start: '',
20+
end: '',
21+
timeToStart: '',
22+
timeToEnd: '',
23+
invitees: []
24+
})
25+
const respond = async () => {
26+
try {
27+
const { data } = await respondToEventInvitation({
28+
variables: {
29+
eventId: params.get('eventId'),
30+
inviteeResponse: params.get('response'),
31+
authToken: localStorage.getItem('auth_token'),
32+
},
33+
})
34+
setEvent({
35+
title: data.respondToEventInvitation.title,
36+
hostName: data.respondToEventInvitation.hostName,
37+
start: data.respondToEventInvitation.start,
38+
end: data.respondToEventInvitation.end,
39+
timeToStart: data.respondToEventInvitation.timeToStart,
40+
timeToEnd: data.respondToEventInvitation.timeToEnd,
41+
invitees: data.respondToEventInvitation.invitees
42+
})
43+
toast.success("Successfully responded to invitation")
44+
} catch (err: any) {
45+
toast.error(err.message)
46+
}
47+
}
48+
useEffect(() => {
49+
respond()
50+
}, [])
51+
return (
52+
<div className="flex items-center justify-center">
53+
<div className="bg-indigo-100 dark:bg-dark-bg w-full sm:w-3/4 md:w-1/2 xl:w-4/12 rounded-lg p-4 pb-8 my-2">
54+
<div className="card-title w-full flex flex-wrap justify-center items-center ">
55+
<h3 className="font-bold text-sm dark:text-white text-center w-11/12">
56+
{t('Event Response')}
57+
</h3>
58+
<hr className=" bg-primary border-gray-300 my-3 w-full" />
59+
</div>
60+
<div className="my-6">
61+
<ul className="">
62+
<li className="text-sm dark:text-white w-11/12 mb-2">
63+
<span className="font-bold">Title:</span> {event.title}
64+
</li>
65+
<li className="text-sm dark:text-white w-11/12 mb-2">
66+
<span className="font-bold">Hostname:</span> {event.hostName}
67+
</li>
68+
<li className="text-sm dark:text-white w-11/12 mb-2">
69+
<span className="font-bold">When:</span> {moment(event.start).format("YYYY-MM-DD")} to {moment(event.end).format("YYYY-MM-DD")}
70+
</li>
71+
<li className="text-sm dark:text-white w-11/12 mb-2">
72+
<span className="font-bold">Time:</span> {event.timeToStart} to {event.timeToEnd}
73+
</li>
74+
<li className="text-sm dark:text-white flex gap-x-2 w-11/12 mb-2">
75+
<span className="font-bold">Guests:</span>
76+
<ul>
77+
{event.invitees?.map((invitee: any)=>(
78+
<li key={invitee.email}>{invitee.email} {invitee.status}</li>
79+
))}
80+
</ul>
81+
</li>
82+
</ul>
83+
</div>
84+
<Link to="/calendar" className="text-white py-2 px-4 w-1/2 md:w-1/3 bg-primary rounded">Go to calendar</Link>
85+
</div>
86+
</div>
87+
88+
)
89+
}
90+
91+
export default CalendarConfirmation

src/components/EventGuestList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const EventGuestList = ({ selectedGuests, handleAddGuest }: { selectedGuests: st
1414
return 'bg-green-500';
1515
case 'coordinator':
1616
return 'bg-blue-500';
17+
case 'manager':
18+
return 'bg-violet-500';
1719
default:
1820
return 'bg-gray-500';
1921
}
@@ -29,6 +31,8 @@ const EventGuestList = ({ selectedGuests, handleAddGuest }: { selectedGuests: st
2931
return 'Trainees';
3032
case 'coordinator':
3133
return 'Coordinators';
34+
case 'manager':
35+
return 'Managers';
3236
default:
3337
return 'Others';
3438
}
@@ -48,7 +52,7 @@ const EventGuestList = ({ selectedGuests, handleAddGuest }: { selectedGuests: st
4852
},
4953
);
5054

51-
const roles = ["admin", "trainee", "ttl", "coordinator"]
55+
const roles = ["admin", "trainee", "ttl", "coordinator","manager"]
5256
const authUser = JSON.parse(localStorage.getItem('auth')!)
5357

5458
return (

src/containers/Routes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Noredirect from '../pages/Noredirect';
3838
import ProtectedRoutes from '../ProtectedRoute';
3939
import RemoveTokenPage from '../utils/RemoveTokenPage';
4040
import DashRoutes from '../containers/DashRoutes';
41+
import CalendarConfirmation from '../components/CalendarConfirmation';
4142

4243
function MainRoutes() {
4344
return (
@@ -93,6 +94,7 @@ function MainRoutes() {
9394
<Route path="/docs/org-signin" element={<SigninOrgDocs />} />
9495
<Route path='/docs/getting-started' element={< UsersDocs />} />
9596
<Route path="/noredirect" element={<Noredirect />} />
97+
<Route path="/calendar/confirm" element={<CalendarConfirmation/>}></Route>
9698
</Route>
9799
<Route path="*" element={<Error />} />
98100
</Routes>

0 commit comments

Comments
 (0)