Skip to content

Commit 2a16cd6

Browse files
author
Harshil Patel
committed
Calendar view added
1 parent 6ed7421 commit 2a16cd6

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

client/components/pages/Settings/MyTicketsPage/MyTicketsPage.js

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ScaleLoader from 'react-spinners/ScaleLoader';
88
import EmptyContainer from '../../../sections/EmptyContainer';
99
import MovieTicketCard from '../../../elements/Card/MovieTicketCard';
1010
import { useGetAllTicketsQuery } from '../../../../store/services/allTickets';
11+
import Schedule from './Schedule';
1112

1213
const getSegment = (totalEvents, curIndex, eventPerPage) => {
1314
const end = curIndex * eventPerPage;
@@ -338,6 +339,8 @@ export default function MyTicketsPage() {
338339
/>
339340
</div>
340341
</div>
342+
<hr className="mt-6 mb-6 border-b-1 border-gray-400" />
343+
341344
{isLoading ? (
342345
<div
343346
className="flex justify-center items-center"
@@ -369,6 +372,17 @@ export default function MyTicketsPage() {
369372
</div>
370373
</div>
371374
)}
375+
376+
{upcomingMovies.length > 0 && (
377+
<div className="bg-white rounded-lg shadow-lg p-4 text-center">
378+
<span className="text-4xl font-semibold m-2 mb-10">
379+
Upcoming Events{' '}
380+
</span>
381+
<div className="mt-4">
382+
<Schedule data={upcomingMovies} />
383+
</div>
384+
</div>
385+
)}
372386
</React.Fragment>
373387
);
374388
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import React from 'react';
2+
import FullCalendar from '@fullcalendar/react';
3+
import dayGridPlugin from '@fullcalendar/daygrid';
4+
import timeGridPlugin from '@fullcalendar/timegrid';
5+
import moment from 'moment';
6+
import interactionPlugin from '@fullcalendar/interaction'; // needed for dayClick
7+
import { motion } from 'framer-motion';
8+
import PropTypes from 'prop-types';
9+
// import '@fullcalendar/common/main.css';
10+
// import '@fullcalendar/daygrid/main.css';
11+
// import '@fullcalendar/timegrid/main.css';
12+
13+
// this is used to make custom view in calendar for event
14+
15+
export default class Schedule extends React.Component {
16+
constructor(props) {
17+
super(props);
18+
this.calendarRef = React.createRef();
19+
this.state = {
20+
events: [],
21+
};
22+
}
23+
24+
componentDidMount() {
25+
const cleanedEvents = this.props?.data.map(
26+
({ movieName, startTime, endTime, showId }) => {
27+
const startDateTime = moment(startTime).format('YYYY-MM-DD HH:mm:ss');
28+
const endDateTime = moment(endTime).format('YYYY-MM-DD HH:mm:ss');
29+
return {
30+
title: movieName,
31+
start: startDateTime,
32+
end: endDateTime,
33+
id: `/show/${showId}`,
34+
};
35+
},
36+
);
37+
this.setState({ events: cleanedEvents });
38+
}
39+
40+
redirectToEventPage = (selectionInfo) => {
41+
window.open(selectionInfo.event._def.publicId, '_blank').focus();
42+
};
43+
44+
setDate = (e) => {
45+
const calendarApi = this.calendarRef.current.getApi();
46+
calendarApi.gotoDate(e.target.value);
47+
};
48+
49+
changeView = () => {
50+
const calendarApi = this.calendarRef.current.getApi();
51+
const currentOption = calendarApi.getOption('eventDisplay');
52+
const circleOfLife = [
53+
'auto',
54+
'block',
55+
'list-item',
56+
'background',
57+
'inverse-background',
58+
'none',
59+
];
60+
const i = circleOfLife.indexOf(currentOption);
61+
const newI = (i + 1) % (circleOfLife.length - 1);
62+
calendarApi.setOption('eventDisplay', circleOfLife[newI]);
63+
};
64+
65+
render() {
66+
return (
67+
<div>
68+
<FullCalendar
69+
ref={this.calendarRef}
70+
height="800px"
71+
stickyHeaderDates={true}
72+
stickyFooterScrollbar={true}
73+
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
74+
headerToolbar={{
75+
center: 'dayGridMonth,timeGridWeek,timeGridDay',
76+
}}
77+
eventColor="#B388DD"
78+
// eventBorderColor=""
79+
// dateClick={this.handleDateClick}
80+
// eventContent={renderEventContent}
81+
defaultView="timeGridWeek"
82+
events={this.state.events}
83+
eventDisplay="auto"
84+
eventTimeFormat={{
85+
// like '14:30:00'
86+
hour: '2-digit',
87+
minute: '2-digit',
88+
meridiem: false,
89+
}}
90+
eventClick={this.redirectToEventPage}
91+
eventMouseEnter={this.popOver}
92+
dayMaxEventRows={true}
93+
dayMaxEvents={true}
94+
/>
95+
{this.state.alert}
96+
<div className="flex w-full mt-4">
97+
<div className="font-semibold text-lg">
98+
Jump to :
99+
<input type="date" className="ml-2 " onChange={this.setDate} />
100+
</div>
101+
<div className="ml-auto">
102+
<motion.button
103+
type="button"
104+
className="rounded-lg font-semibold p-2 px-4 text-base text-white hover:lightalpha active:lightalpha "
105+
onClick={this.changeView}
106+
style={{ backgroundColor: '#b388dd' }}
107+
whileHover={{ scale: 1.05 }}
108+
whileTap={{ scale: 0.9 }}
109+
>
110+
{' '}
111+
<i className="fas fa-wrench text-sm" /> Toggle View
112+
</motion.button>
113+
</div>
114+
</div>
115+
</div>
116+
);
117+
}
118+
}
119+
120+
Schedule.propTypes = {
121+
data: PropTypes.arrayOf(
122+
PropTypes.shape({
123+
movieName: PropTypes.string.isRequired,
124+
startTime: PropTypes.string.isRequired,
125+
endTime: PropTypes.string.isRequired,
126+
showId: PropTypes.string.isRequired,
127+
}),
128+
).isRequired,
129+
};

package-lock.json

+59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"@fortawesome/free-regular-svg-icons": "^6.4.2",
6363
"@fortawesome/free-solid-svg-icons": "^6.4.2",
6464
"@fortawesome/react-fontawesome": "^0.1.0",
65+
"@fullcalendar/core": "^6.1.10",
66+
"@fullcalendar/daygrid": "^6.1.10",
67+
"@fullcalendar/interaction": "^6.1.10",
68+
"@fullcalendar/react": "^6.1.10",
69+
"@fullcalendar/timegrid": "^6.1.10",
6570
"@mui/material": "^5.14.13",
6671
"@reduxjs/toolkit": "^1.9.7",
6772
"@typegoose/auto-increment": "^3.6.0",

0 commit comments

Comments
 (0)