-
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.
Implement admin "select shift times" calendar (#150)
- Loading branch information
Showing
9 changed files
with
318 additions
and
5 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
frontend/src/components/admin/ShiftCalendar/ShiftCalendar.css
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,72 @@ | ||
a:hover { | ||
text-decoration: none; | ||
color: inherit; | ||
} | ||
|
||
.fc table { | ||
font-weight: 400; | ||
letter-spacing: 0.2px; | ||
line-height: 18px; | ||
font-size: 16px; | ||
} | ||
|
||
.fc .fc-col-header-cell-cushion { | ||
font-family: "Raleway", sans-serif; | ||
font-size: 18px; | ||
font-weight: 500; | ||
letter-spacing: 0.2px; | ||
line-height: 18px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.fc .fc-scrollgrid-sync-inner { | ||
align-items: center; | ||
display: flex; | ||
height: 75px; | ||
justify-content: center; | ||
} | ||
|
||
.fc-theme-standard .fc-scrollgrid { | ||
border: none; | ||
} | ||
|
||
.fc-v-event .fc-event-main-frame { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: row; | ||
} | ||
|
||
.fc-event-title-container { | ||
display: none; | ||
} | ||
|
||
.fc .fc-timegrid-axis-cushion, | ||
.fc .fc-timegrid-slot-label-cushion { | ||
font-size: 14px; | ||
padding-right: 0.5rem; | ||
padding-left: 0.5rem; | ||
} | ||
|
||
.fc-timegrid-event .fc-event-time { | ||
white-space: normal; | ||
text-align: center; | ||
flex-shrink: unset; | ||
padding-left: 0.3rem; | ||
padding-right: 0.3rem; | ||
} | ||
|
||
.fc-timegrid-event-harness > .fc-timegrid-event { | ||
display: block; | ||
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.25); | ||
border-radius: 4px; | ||
} | ||
|
||
.fc-theme-standard td, | ||
.fc-theme-standard th { | ||
border: 0.5px solid #ddd; | ||
} | ||
|
||
.fc .fc-timegrid-col.fc-day-today { | ||
background-color: inherit; | ||
} |
127 changes: 127 additions & 0 deletions
127
frontend/src/components/admin/ShiftCalendar/ShiftCalendar.tsx
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,127 @@ | ||
import FullCalendar, { | ||
DateSelectArg, | ||
EventChangeArg, | ||
EventClickArg, | ||
EventInput, | ||
} from "@fullcalendar/react"; | ||
import timeGridPlugin from "@fullcalendar/timegrid"; | ||
import interactionPlugin from "@fullcalendar/interaction"; | ||
import React, { useState } from "react"; | ||
import { | ||
Box, | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
} from "@chakra-ui/react"; | ||
import colors from "../../../theme/colors"; | ||
import "./ShiftCalendar.css"; | ||
import { getTime, getWeekday } from "../../../utils/DateTimeUtils"; | ||
|
||
export type Event = { | ||
id: string; | ||
start: Date; | ||
end: Date; | ||
}; | ||
|
||
type ShiftCalendarProps = { | ||
events: Event[]; | ||
selectedEvent: Event | null; | ||
setSelectedEvent: (event: Event | null) => void; | ||
addEvent: (newEvent: DateSelectArg) => void; | ||
changeEvent: (event: Event, oldEvent: Event, currEvents: Event[]) => void; | ||
deleteEvent: (currEvents: Event[]) => void; | ||
}; | ||
|
||
const ShiftCalendar = ({ | ||
events, | ||
selectedEvent, | ||
setSelectedEvent, | ||
addEvent, | ||
changeEvent, | ||
deleteEvent, | ||
}: ShiftCalendarProps): React.ReactElement => { | ||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); | ||
|
||
const openModal = (): void => { | ||
setIsModalOpen(true); | ||
}; | ||
|
||
const closeModal = (): void => { | ||
setIsModalOpen(false); | ||
}; | ||
|
||
const deleteDialog = (event: Event) => { | ||
openModal(); | ||
setSelectedEvent(event); | ||
}; | ||
|
||
const onDeleteEvent = (currEvents: Event[]) => { | ||
deleteEvent(currEvents); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<Modal onClose={closeModal} isOpen={isModalOpen} isCentered> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader mt={3}>Delete Shift?</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
{selectedEvent | ||
? `Are you sure you want to delete the event on ${getWeekday( | ||
selectedEvent.start, | ||
)} from ${getTime(selectedEvent.start)} to ${getTime( | ||
selectedEvent.end, | ||
)}?` | ||
: ""} | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button colorScheme="gray" mr={3} onClick={closeModal}> | ||
Cancel | ||
</Button> | ||
<Button | ||
colorScheme="red" | ||
onClick={() => onDeleteEvent(events.slice())} | ||
> | ||
Delete | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
<FullCalendar | ||
allDaySlot={false} | ||
dayHeaderFormat={{ weekday: "short" }} | ||
editable | ||
eventChange={(arg: EventChangeArg) => | ||
changeEvent(arg.event as Event, arg.oldEvent as Event, events.slice()) | ||
} | ||
eventClick={(arg: EventClickArg) => deleteDialog(arg.event as Event)} | ||
eventColor={colors.violet} | ||
eventTimeFormat={{ | ||
hour: "numeric", | ||
minute: "2-digit", | ||
meridiem: "short", | ||
}} | ||
events={events as EventInput[]} | ||
headerToolbar={false} | ||
initialView="timeGridWeek" | ||
plugins={[timeGridPlugin, interactionPlugin]} | ||
select={(selectInfo: DateSelectArg) => addEvent(selectInfo)} | ||
selectMirror | ||
selectable | ||
scrollTime="09:00:00" | ||
slotDuration="00:15:00" | ||
slotLabelInterval="01:00" | ||
timeZone="UTC" | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ShiftCalendar; |
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
60 changes: 58 additions & 2 deletions
60
frontend/src/components/pages/admin/posting/CreatePostingShiftsPage.tsx
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 |
---|---|---|
@@ -1,7 +1,63 @@ | ||
import React from "react"; | ||
import { DateSelectArg } from "@fullcalendar/react"; | ||
import React, { useState } from "react"; | ||
import { Container, Divider } from "@chakra-ui/react"; | ||
import ShiftCalendar, { | ||
Event, | ||
} from "../../../admin/ShiftCalendar/ShiftCalendar"; | ||
|
||
const CreatePostingShiftsPage = (): React.ReactElement => { | ||
return <div />; | ||
const [events, setEvents] = useState<Event[]>([]); | ||
const [eventCount, setEventCount] = useState<number>(0); | ||
const [selectedEvent, setSelectedEvent] = useState<Event | null>(null); | ||
|
||
const addEvent = (newEvent: DateSelectArg) => { | ||
setEvents([ | ||
...events, | ||
{ | ||
start: newEvent.start, | ||
end: newEvent.end, | ||
id: `event-${eventCount}`, | ||
}, | ||
]); | ||
setEventCount(eventCount + 1); | ||
}; | ||
|
||
const changeEvent = (event: Event, oldEvent: Event, currEvents: Event[]) => { | ||
const newEvent = currEvents.find( | ||
(currEvent) => currEvent.id === oldEvent.id, | ||
); | ||
if (newEvent) { | ||
newEvent.start = event.start; | ||
newEvent.end = event.end; | ||
setEvents([...currEvents]); | ||
} | ||
}; | ||
|
||
const deleteEvent = (currEvents: Event[]) => { | ||
if (selectedEvent) { | ||
for (let i = 0; i < currEvents.length; i += 1) { | ||
if (currEvents[i].id === selectedEvent.id) { | ||
currEvents.splice(i, 1); | ||
break; | ||
} | ||
} | ||
setEvents(currEvents); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container maxW="container.lg"> | ||
<ShiftCalendar | ||
events={events} | ||
selectedEvent={selectedEvent} | ||
setSelectedEvent={setSelectedEvent} | ||
addEvent={addEvent} | ||
changeEvent={changeEvent} | ||
deleteEvent={deleteEvent} | ||
/> | ||
<Divider my={4} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default CreatePostingShiftsPage; |
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
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