import { useEffect, useState, useMemo, useCallback, useRef } from 'react'
// @ts-ignore - react-big-calendar types not available
import { Calendar, momentLocalizer, Views } from 'react-big-calendar'
// @ts-ignore - react-big-calendar dragAndDrop types not available
import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop'
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'
import moment from 'moment'
import type { User, ExperimentPhase, Experiment, ExperimentRepetition, Soaking, Airdrying } from '../services/supabase'
import { availabilityManagement, userManagement, experimentPhaseManagement, experimentManagement, repetitionManagement, phaseManagement, supabase } from '../services/supabase'
import 'react-big-calendar/lib/css/react-big-calendar.css'
import './CalendarStyles.css'
// Type definitions for calendar events
interface CalendarEvent {
id: number | string
title: string
start: Date
end: Date
resource?: string
}
interface SchedulingProps {
user: User
currentRoute: string
}
type SchedulingView = 'main' | 'view-schedule' | 'indicate-availability' | 'schedule-experiment'
export function Scheduling({ user, currentRoute }: SchedulingProps) {
// Extract current view from route
const getCurrentView = (): SchedulingView => {
if (currentRoute === '/scheduling') {
return 'main'
}
const match = currentRoute.match(/^\/scheduling\/(.+)$/)
if (match) {
const subRoute = match[1]
switch (subRoute) {
case 'view-schedule':
return 'view-schedule'
case 'indicate-availability':
return 'indicate-availability'
case 'schedule-experiment':
return 'schedule-experiment'
default:
return 'main'
}
}
return 'main'
}
const currentView = getCurrentView()
const handleCardClick = (view: SchedulingView) => {
const newPath = view === 'main' ? '/scheduling' : `/scheduling/${view}`
window.history.pushState({}, '', newPath)
// Trigger a popstate event to update the route
window.dispatchEvent(new PopStateEvent('popstate'))
}
const handleBackToMain = () => {
window.history.pushState({}, '', '/scheduling')
// Trigger a popstate event to update the route
window.dispatchEvent(new PopStateEvent('popstate'))
}
// Render different views based on currentView
if (currentView === 'view-schedule') {
return
This is the scheduling module of the dashboard. Here you can indicate your availability for upcoming experiment runs.
View the complete schedule of all upcoming experiment runs and their current status.
Set your availability preferences and time slots for upcoming experiment runs.
Schedule specific experiment runs and assign team members to upcoming sessions.
View all scheduled experiment runs and their current status.
This view will show a comprehensive calendar and list of all scheduled experiment runs, including dates, times, assigned team members, and current status.
Set your availability preferences and time slots for upcoming experiment runs.
Schedule specific experiment runs and assign team members to upcoming sessions.
Fetching conductors, phases, and experiments.
Click and drag to add availability slots, or click on existing events to remove them. You can add multiple time slots per day.