using cp for plans

This commit is contained in:
2025-10-18 23:35:46 +02:00
parent 07c495a6dc
commit 372b9b2f20
13 changed files with 485 additions and 9 deletions

View File

@@ -0,0 +1,43 @@
// src/components/Scheduler.tsx
import React from 'react';
import { useScheduling } from '../hooks/useScheduling';
interface Props {
scheduleRequest: ScheduleRequest;
}
export const Scheduler: React.FC<Props> = ({ scheduleRequest }) => {
const { generateSchedule, loading, error, result } = useScheduling();
const handleGenerateSchedule = async () => {
try {
await generateSchedule(scheduleRequest);
} catch (err) {
// Error handling
}
};
return (
<div>
<button
onClick={handleGenerateSchedule}
disabled={loading}
>
{loading ? 'Generating Schedule...' : 'Generate Optimal Schedule'}
</button>
{loading && (
<div>
<progress max="100" value="70" />
<p>Optimizing schedule... (max 2 minutes)</p>
</div>
)}
{error && <div className="error">{error}</div>}
{result && (
<ScheduleResultView result={result} />
)}
</div>
);
};

View File

@@ -0,0 +1,37 @@
// frontend/src/services/scheduling/scheduling.ts
import { useState, useCallback } from 'react';
import { ScheduleRequest, ScheduleResult } from '../types/scheduling';
export const useScheduling = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<ScheduleResult | null>(null);
const generateSchedule = useCallback(async (request: ScheduleRequest) => {
setLoading(true);
setError(null);
try {
const response = await fetch('/api/scheduling/generate-schedule', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(request)
});
if (!response.ok) throw new Error('Scheduling request failed');
const data: ScheduleResult = await response.json();
setResult(data);
return data;
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
setError(errorMessage);
throw err;
} finally {
setLoading(false);
}
}, []);
return { generateSchedule, loading, error, result };
};

View File

@@ -5,7 +5,7 @@ import { useAuth } from '../../contexts/AuthContext';
import { shiftPlanService } from '../../services/shiftPlanService';
import { employeeService } from '../../services/employeeService';
import { shiftAssignmentService, ShiftAssignmentService } from '../../services/shiftAssignmentService';
import { IntelligentShiftScheduler, SchedulingResult, AssignmentResult } from '../../services/scheduling';
import { IntelligentShiftScheduler, SchedulingResult, AssignmentResult } from '../../hooks/useScheduling';
import { ShiftPlan, TimeSlot, ScheduledShift } from '../../models/ShiftPlan';
import { Employee, EmployeeAvailability } from '../../models/Employee';
import { useNotification } from '../../contexts/NotificationContext';

View File

@@ -1,5 +0,0 @@
// frontend/src/services/scheduling.ts/scheduling.ts
import { Employee, EmployeeAvailability } from '../models/Employee';
import { ScheduledShift, ShiftPlan } from '../models/ShiftPlan';
import { shiftAssignmentService } from './shiftAssignmentService';

View File

@@ -2,7 +2,7 @@
import { ShiftPlan, ScheduledShift } from '../models/ShiftPlan';
import { Employee, EmployeeAvailability } from '../models/Employee';
import { authService } from './authService';
import { IntelligentShiftScheduler, AssignmentResult, WeeklyPattern } from './scheduling';
import { IntelligentShiftScheduler, AssignmentResult, WeeklyPattern } from '../hooks/useScheduling';
import { isScheduledShift } from '../models/helpers';
const API_BASE_URL = 'http://localhost:3002/api/scheduled-shifts';