feat(time-blocks): Add comprehensive time blocking system with contracts

- Add TimeBlock and Holiday models with recurrence support (one-time, weekly, monthly, yearly, holiday)
- Implement business-level and resource-level blocking with hard/soft block types
- Add multi-select holiday picker for bulk holiday blocking
- Add calendar overlay visualization with distinct colors:
  - Business blocks: Red (hard) / Yellow (soft)
  - Resource blocks: Purple (hard) / Cyan (soft)
- Add month view resource indicators showing 1/n width per resource
- Add yearly calendar view for block overview
- Add My Availability page for staff self-service
- Add contracts module with templates, signing flow, and PDF generation
- Update scheduler with click-to-day navigation in week view

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
poduck
2025-12-04 17:19:12 -05:00
parent cf91bae24f
commit 8d0cc1e90a
63 changed files with 11863 additions and 61 deletions

View File

@@ -0,0 +1,247 @@
/**
* TimeBlockCalendarOverlay - Renders time block overlays on the scheduler calendar
*
* Shows blocked time periods with visual styling:
* - Hard blocks: Red with diagonal stripes, 50% opacity
* - Soft blocks: Yellow with dotted border, 30% opacity
* - Business blocks: Full-width across the lane
* - Resource blocks: Only on matching resource lane
*/
import React, { useMemo, useState } from 'react';
import { BlockedDate, BlockType } from '../../types';
interface TimeBlockCalendarOverlayProps {
blockedDates: BlockedDate[];
resourceId: string;
viewDate: Date;
zoomLevel: number;
pixelsPerMinute: number;
startHour: number;
dayWidth: number;
laneHeight: number;
days: Date[];
onDayClick?: (day: Date) => void;
}
interface TimeBlockTooltipProps {
block: BlockedDate;
position: { x: number; y: number };
}
const TimeBlockTooltip: React.FC<TimeBlockTooltipProps> = ({ block, position }) => {
return (
<div
className="fixed z-[100] px-3 py-2 bg-gray-900 text-white text-sm rounded-lg shadow-lg max-w-xs pointer-events-none"
style={{
left: position.x + 10,
top: position.y - 40,
}}
>
<div className="font-semibold">{block.title}</div>
<div className="text-xs text-gray-300 mt-1">
{block.block_type === 'HARD' ? 'Hard Block' : 'Soft Block'}
{block.all_day ? ' (All Day)' : ` (${block.start_time} - ${block.end_time})`}
</div>
</div>
);
};
const TimeBlockCalendarOverlay: React.FC<TimeBlockCalendarOverlayProps> = ({
blockedDates,
resourceId,
viewDate,
zoomLevel,
pixelsPerMinute,
startHour,
dayWidth,
laneHeight,
days,
onDayClick,
}) => {
const [hoveredBlock, setHoveredBlock] = useState<{ block: BlockedDate; position: { x: number; y: number } } | null>(null);
// Filter blocks for this resource (includes business-level blocks where resource_id is null)
const relevantBlocks = useMemo(() => {
return blockedDates.filter(
(block) => block.resource_id === null || block.resource_id === resourceId
);
}, [blockedDates, resourceId]);
// Calculate block positions for each day
const blockOverlays = useMemo(() => {
const overlays: Array<{
block: BlockedDate;
left: number;
width: number;
dayIndex: number;
}> = [];
relevantBlocks.forEach((block) => {
// Parse date string as local date, not UTC
// "2025-12-06" should be Dec 6 in local timezone, not UTC
const [year, month, dayNum] = block.date.split('-').map(Number);
const blockDate = new Date(year, month - 1, dayNum);
blockDate.setHours(0, 0, 0, 0);
// Find which day this block falls on
days.forEach((day, dayIndex) => {
const dayStart = new Date(day);
dayStart.setHours(0, 0, 0, 0);
if (blockDate.getTime() === dayStart.getTime()) {
let left: number;
let width: number;
if (block.all_day) {
// Full day block
left = dayIndex * dayWidth;
width = dayWidth;
} else if (block.start_time && block.end_time) {
// Partial day block
const [startHours, startMins] = block.start_time.split(':').map(Number);
const [endHours, endMins] = block.end_time.split(':').map(Number);
const startMinutes = (startHours - startHour) * 60 + startMins;
const endMinutes = (endHours - startHour) * 60 + endMins;
left = dayIndex * dayWidth + startMinutes * pixelsPerMinute * zoomLevel;
width = (endMinutes - startMinutes) * pixelsPerMinute * zoomLevel;
} else {
// Default to full day if no times specified
left = dayIndex * dayWidth;
width = dayWidth;
}
overlays.push({
block,
left,
width,
dayIndex,
});
}
});
});
return overlays;
}, [relevantBlocks, days, dayWidth, pixelsPerMinute, zoomLevel, startHour]);
const getBlockStyle = (blockType: BlockType, isBusinessLevel: boolean): React.CSSProperties => {
const baseStyle: React.CSSProperties = {
position: 'absolute',
top: 0,
height: '100%',
pointerEvents: 'auto',
cursor: 'default',
};
if (isBusinessLevel) {
// Business blocks: Red (hard) / Amber (soft)
if (blockType === 'HARD') {
return {
...baseStyle,
background: `repeating-linear-gradient(
-45deg,
rgba(239, 68, 68, 0.3),
rgba(239, 68, 68, 0.3) 5px,
rgba(239, 68, 68, 0.5) 5px,
rgba(239, 68, 68, 0.5) 10px
)`,
borderTop: '2px solid rgba(239, 68, 68, 0.7)',
borderBottom: '2px solid rgba(239, 68, 68, 0.7)',
};
} else {
return {
...baseStyle,
background: 'rgba(251, 191, 36, 0.2)',
borderTop: '2px dashed rgba(251, 191, 36, 0.8)',
borderBottom: '2px dashed rgba(251, 191, 36, 0.8)',
};
}
} else {
// Resource blocks: Purple (hard) / Cyan (soft)
if (blockType === 'HARD') {
return {
...baseStyle,
background: `repeating-linear-gradient(
-45deg,
rgba(147, 51, 234, 0.25),
rgba(147, 51, 234, 0.25) 5px,
rgba(147, 51, 234, 0.4) 5px,
rgba(147, 51, 234, 0.4) 10px
)`,
borderTop: '2px solid rgba(147, 51, 234, 0.7)',
borderBottom: '2px solid rgba(147, 51, 234, 0.7)',
};
} else {
return {
...baseStyle,
background: 'rgba(6, 182, 212, 0.15)',
borderTop: '2px dashed rgba(6, 182, 212, 0.7)',
borderBottom: '2px dashed rgba(6, 182, 212, 0.7)',
};
}
}
};
const handleMouseEnter = (e: React.MouseEvent, block: BlockedDate) => {
setHoveredBlock({
block,
position: { x: e.clientX, y: e.clientY },
});
};
const handleMouseMove = (e: React.MouseEvent) => {
if (hoveredBlock) {
setHoveredBlock({
...hoveredBlock,
position: { x: e.clientX, y: e.clientY },
});
}
};
const handleMouseLeave = () => {
setHoveredBlock(null);
};
return (
<>
{blockOverlays.map((overlay, index) => {
const isBusinessLevel = overlay.block.resource_id === null;
const style = getBlockStyle(overlay.block.block_type, isBusinessLevel);
return (
<div
key={`${overlay.block.time_block_id}-${overlay.dayIndex}-${index}`}
style={{
...style,
left: overlay.left,
width: overlay.width,
cursor: onDayClick ? 'pointer' : 'default',
}}
onMouseEnter={(e) => handleMouseEnter(e, overlay.block)}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
onClick={() => onDayClick?.(days[overlay.dayIndex])}
>
{/* Block level indicator */}
<div className={`absolute top-1 left-1 px-1.5 py-0.5 text-white text-[10px] font-bold rounded shadow-sm uppercase tracking-wide ${
isBusinessLevel
? 'bg-red-600'
: 'bg-purple-600'
}`}>
{isBusinessLevel ? 'B' : 'R'}
</div>
</div>
);
})}
{/* Tooltip */}
{hoveredBlock && (
<TimeBlockTooltip block={hoveredBlock.block} position={hoveredBlock.position} />
)}
</>
);
};
export default TimeBlockCalendarOverlay;