improve timezone discovery
This commit is contained in:
@@ -7,7 +7,8 @@ import {
|
||||
} from '@/components/ui/popover';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Check, X, Loader2 } from 'lucide-react';
|
||||
import { TimezoneSelector } from '@/components/TimezoneSelector';
|
||||
|
||||
const TIMEZONE = 'America/Toronto';
|
||||
|
||||
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
|
||||
const hours = [9, 10, 11, 12, 13, 14, 15, 16, 17];
|
||||
@@ -78,8 +79,6 @@ interface AvailabilityHeatmapProps {
|
||||
onSlotSelect: (slot: TimeSlot) => void;
|
||||
showPartialAvailability?: boolean;
|
||||
isLoading?: boolean;
|
||||
displayTimezone: string;
|
||||
onTimezoneChange: (timezone: string) => void;
|
||||
}
|
||||
|
||||
export const AvailabilityHeatmap = ({
|
||||
@@ -88,15 +87,13 @@ export const AvailabilityHeatmap = ({
|
||||
onSlotSelect,
|
||||
showPartialAvailability = false,
|
||||
isLoading = false,
|
||||
displayTimezone,
|
||||
onTimezoneChange,
|
||||
}: AvailabilityHeatmapProps) => {
|
||||
const weekDates = getWeekDates(displayTimezone);
|
||||
const weekDates = getWeekDates(TIMEZONE);
|
||||
|
||||
// Find a slot that matches the given display timezone date/hour
|
||||
const getSlot = (dateStr: string, hour: number): TimeSlot | undefined => {
|
||||
// Convert display timezone date/hour to UTC
|
||||
const targetUTC = toUTCDate(dateStr, hour, displayTimezone);
|
||||
const targetUTC = toUTCDate(dateStr, hour, TIMEZONE);
|
||||
|
||||
return slots.find((s) => {
|
||||
const slotDate = new Date(s.start_time);
|
||||
@@ -118,7 +115,7 @@ export const AvailabilityHeatmap = ({
|
||||
|
||||
const isSlotTooSoon = (dateStr: string, hour: number) => {
|
||||
// Convert to UTC and compare with current time
|
||||
const slotTimeUTC = toUTCDate(dateStr, hour, displayTimezone);
|
||||
const slotTimeUTC = toUTCDate(dateStr, hour, TIMEZONE);
|
||||
const now = new Date();
|
||||
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
|
||||
return slotTimeUTC < twoHoursFromNow;
|
||||
@@ -177,10 +174,6 @@ export const AvailabilityHeatmap = ({
|
||||
{selectedParticipants.length} participant{selectedParticipants.length > 1 ? 's' : ''}: {selectedParticipants.map(p => p.name.split(' ')[0]).join(', ')}
|
||||
</p>
|
||||
</div>
|
||||
<TimezoneSelector
|
||||
value={displayTimezone}
|
||||
onChange={onTimezoneChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
@@ -242,19 +235,6 @@ export const AvailabilityHeatmap = ({
|
||||
{selectedParticipants.map((participant) => {
|
||||
const isAvailable = slot.availableParticipants.includes(participant.name);
|
||||
|
||||
// Calculate participant's local time for this slot
|
||||
let participantTime = '';
|
||||
try {
|
||||
const slotDate = new Date(slot.start_time);
|
||||
participantTime = new Intl.DateTimeFormat('en-US', {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
timeZone: participant.timezone,
|
||||
}).format(slotDate);
|
||||
} catch (e) {
|
||||
// Fallback if timezone is invalid
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={participant.id}
|
||||
@@ -269,9 +249,6 @@ export const AvailabilityHeatmap = ({
|
||||
isAvailable ? "text-foreground" : "text-muted-foreground"
|
||||
)}>
|
||||
{participant.name.split(' ')[0]}
|
||||
<span className="opacity-70 ml-1">
|
||||
({participantTime || '?'})
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user