-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc2c60d
commit 6c6adbb
Showing
4 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { useState } from "react"; | ||
import FullCalendar, { formatDate } from "@fullcalendar/react"; | ||
import dayGridPlugin from "@fullcalendar/daygrid"; | ||
import timeGridPlugin from "@fullcalendar/timegrid"; | ||
import interactionPlugin from "@fullcalendar/interaction"; | ||
import listPlugin from "@fullcalendar/list"; | ||
import { | ||
Box, | ||
List, | ||
ListItem, | ||
ListItemText, | ||
Typography, | ||
useTheme, | ||
} from "@mui/material"; | ||
import Header from "../../components/Header"; | ||
import { tokens } from "../../theme"; | ||
|
||
export default function Calendar() { | ||
const theme = useTheme(); | ||
const colors = tokens(theme.palette.mode); | ||
const [currentEvents, setCurrentEvents] = useState([]); | ||
|
||
const handleDateClick = (selected) => { | ||
console.log(selected); | ||
const title = prompt("Please enter a new title for your event"); | ||
const calendarApi = selected.view.calendar; | ||
calendarApi.unselect(); | ||
|
||
if (title) { | ||
calendarApi.addEvent({ | ||
id: `${selected.startStr}-${title}`, | ||
title, | ||
start: selected.startStr, | ||
end: selected.endStr, | ||
allDay: selected.allDay, | ||
}); | ||
} | ||
}; | ||
|
||
const handleEventClick = (selected) => { | ||
if ( | ||
window.confirm( | ||
`Are you sure you want to delete the event '${selected.event.title}'` | ||
) | ||
) { | ||
selected.event.remove(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box m="20px"> | ||
<Header title="Calendar" subtitle="Full Calendar Interactive Page" /> | ||
|
||
<Box display="flex" justifyContent="space-between"> | ||
{/* CALENDAR SIDEBAR */} | ||
<Box | ||
flex="1 1 20%" | ||
backgroundColor={colors.primary[400]} | ||
p="15px" | ||
borderRadius="4px" | ||
> | ||
<Typography variant="h5">Events</Typography> | ||
<List> | ||
{currentEvents.map((event) => ( | ||
<ListItem | ||
key={event.id} | ||
sx={{ | ||
backgroundColor: colors.greenAccent[500], | ||
margin: "10px 0", | ||
borderRadius: "2px", | ||
}} | ||
> | ||
<ListItemText | ||
primary={event.title} | ||
secondary={ | ||
<Typography> | ||
{formatDate(event.start, { | ||
year: "numeric", | ||
month: "short", | ||
day: "numeric", | ||
})} | ||
</Typography> | ||
} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Box> | ||
|
||
{/* CALENDAR */} | ||
<Box flex="1 1 100%" ml="15px"> | ||
<FullCalendar | ||
height="75vh" | ||
plugins={[ | ||
dayGridPlugin, | ||
timeGridPlugin, | ||
interactionPlugin, | ||
listPlugin, | ||
]} | ||
headerToolbar={{ | ||
left: "prev,next today", | ||
center: "title", | ||
right: "dayGridMonth,timeGridWeek,timeGridDay,listMonth", | ||
}} | ||
initialView="dayGridMonth" | ||
editable={true} | ||
selectable={true} | ||
selectMirror={true} | ||
dayMaxEvents={true} | ||
select={handleDateClick} | ||
eventClick={handleEventClick} | ||
eventsSet={(events) => setCurrentEvents(events)} | ||
initialEvents={[ | ||
{ | ||
id: "12315", | ||
title: "All-day event", | ||
date: "2022-09-14", | ||
}, | ||
{ | ||
id: "5123", | ||
title: "Timed event", | ||
date: "2022-09-28", | ||
}, | ||
]} | ||
/> | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
} |