Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule Page 'Missed Shift' Status #43

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions frontend/src/components/ShiftCard/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dayjs from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween';
import CheckInIcon from '../../assets/check-in-icon.png'
import Plus from '../../assets/plus.png'
import RequestCoverageIcon from '../../assets/request-coverage.png'
Expand All @@ -8,7 +9,13 @@ import { SHIFT_TYPES, COVERAGE_STATUSES } from '../../data/constants';

function ShiftCard({ shift, shiftType, onUpdate, onShiftSelect }) {
const currentDate = dayjs();
const pastShift = dayjs(shift.shift_date).format('YYYY-MM-DD') <= currentDate.format('YYYY-MM-DD');
const shiftDay = dayjs(shift.shift_date).format('YYYY-MM-DD');
const shiftStart = dayjs(`${shiftDay} ${shift.start_time}`);
const shiftEnd = dayjs(`${shiftDay} ${shift.end_time}`);

const pastShift = currentDate.isAfter(shiftEnd);
const currentShift = currentDate.isBetween(shiftStart, shiftEnd, 'minute', '[]');

const volunteerID = localStorage.getItem('volunteerID');

const handleCoverShiftClick = async () => {
Expand All @@ -27,7 +34,7 @@ function ShiftCard({ shift, shiftType, onUpdate, onShiftSelect }) {

// TODO Check-in handler for 'my-shifts'
const handleCheckInClick = async () => {
if (!shift.checked_in && pastShift) {
if (!shift.checked_in && currentShift) {
// Perform check-in logic here
console.log(`Checking in for shift ${shift.shift_id}`);
// Set the state or make API call here to mark the shift as checked in
Expand All @@ -43,9 +50,15 @@ function ShiftCard({ shift, shiftType, onUpdate, onShiftSelect }) {
const buttonConfig = {
[SHIFT_TYPES.MY_SHIFTS]: {
lineColor: 'var(--green)',
label: shift.checked_in ? 'Checked In' : pastShift ? 'Check In' : 'Upcoming',
icon: shift.checked_in ? null : pastShift ? CheckInIcon : null,
disabled: shift.checked_in || !pastShift,
label: shift.checked_in
? 'Checked In'
: currentShift
? 'Check In'
: pastShift
? 'Missed Shift'
: 'Upcoming',
icon: shift.checked_in ? null : currentShift ? CheckInIcon : null,
disabled: shift.checked_in || !currentShift,
buttonClass: shift.checked_in ? 'checked-in' : '',
onClick: handleCheckInClick,
},
Expand Down Expand Up @@ -87,7 +100,7 @@ function ShiftCard({ shift, shiftType, onUpdate, onShiftSelect }) {
const primaryButton = buttonConfig[shiftType] || buttonConfig[SHIFT_TYPES.DEFAULT];

buttons.push(primaryButton);
if (shiftType === SHIFT_TYPES.MY_SHIFTS) {
if (shiftType === SHIFT_TYPES.MY_SHIFTS && !shift.checked_in && !pastShift) {
buttons.push(buttonConfig.REQUEST_COVERAGE);
}
return buttons;
Expand Down