Files
hats-app/app/(dashboard)/integrated-calendar/components/EventDetailModal.tsx
T
Ichsan Kurniawan c9dc6a5e51 Add multi-calendar monthly grid view
Replace the event and task lists with a monthly calendar grid, calendar filters, and event detail view. Add multi-calendar event fetching and route create, edit, and delete actions to the selected calendar.
2026-11-18 18:17:26 +07:00

299 lines
9.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
import React from 'react';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { CalendarEventItem } from '@/lib/google-calendar/types';
import { getEventColorInfo } from '@/lib/google-calendar/constants';
import {
Calendar,
Clock,
MapPin,
Users,
Video,
Edit2,
Trash2,
ExternalLink,
AlignLeft,
Lock,
} from 'lucide-react';
import dayjs from 'dayjs';
interface EventDetailModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
event: CalendarEventItem | null;
onEdit: (event: CalendarEventItem) => void;
onDelete: (event: CalendarEventItem) => void;
}
export default function EventDetailModal({
open,
onOpenChange,
event,
onEdit,
onDelete,
}: EventDetailModalProps) {
if (!event) return null;
const colorInfo = getEventColorInfo(event.colorId);
const displayHex = colorInfo?.hex || event.calendarColor || '#039be5';
const guestList = event.attendees || [];
const formatDateRange = (startStr: string, endStr: string, isAllDay: boolean) => {
if (!startStr) return '-';
if (isAllDay) {
const s = dayjs(startStr).format('dddd, DD MMMM YYYY');
const e =
endStr && endStr !== startStr
? ` – ${dayjs(endStr).format('dddd, DD MMMM YYYY')}`
: '';
return `${s}${e}`;
}
const s = dayjs(startStr).format('dddd, DD MMMM YYYY • HH:mm');
const sameDay = dayjs(startStr).isSame(dayjs(endStr), 'day');
const e = endStr
? sameDay
? dayjs(endStr).format('HH:mm')
: dayjs(endStr).format('dddd, DD MMMM YYYY • HH:mm')
: '';
return `${s} – ${e} WIB`;
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="p-0 overflow-hidden bg-white dark:bg-zinc-950 border-zinc-200 dark:border-zinc-800">
{/* Top Colored Strip */}
<div className="h-2 w-full" style={{ backgroundColor: displayHex }} />
<DialogHeader className="p-6 pb-4 border-b border-zinc-100 dark:border-zinc-800">
<div className="flex items-start gap-3 pr-6">
<span
className="size-4 rounded-md shrink-0 mt-1 shadow-xs"
style={{ backgroundColor: displayHex }}
/>
<div className="space-y-1.5 min-w-0 flex-1">
<DialogTitle className="text-lg font-semibold text-zinc-900 dark:text-zinc-100 leading-snug break-words">
{event.summary}
</DialogTitle>
<DialogDescription className="text-xs text-zinc-600 dark:text-zinc-400 flex items-center gap-1.5">
<Clock className="size-3.5 text-zinc-400 shrink-0" />
<span>{formatDateRange(event.start, event.end, event.isAllDay)}</span>
</DialogDescription>
<div className="flex flex-wrap items-center gap-1.5 pt-1">
{event.isAllDay && (
<Badge variant="outline" className="text-[10px] py-0 px-2">
Sepanjang Hari (All-Day)
</Badge>
)}
{colorInfo && (
<Badge variant="outline" className="text-[10px] py-0 px-2 gap-1 font-normal relative text-white">
<div
className="size-1.5 rounded-full w-full h-full absolute inset-0"
style={{ backgroundColor: displayHex }}
/>
<span className='relative'>{colorInfo.name}</span>
</Badge>
)}
{event.isReadOnly && (
<Badge variant="secondary" className="text-[10px] py-0 px-2 gap-1 font-normal">
<Lock className="size-2.5" />
Read-only
</Badge>
)}
</div>
</div>
</div>
</DialogHeader>
{/* Event Details Body */}
<div className="p-6 pt-3 space-y-4 max-h-[65vh] overflow-y-auto text-xs sm:text-sm">
{/* Google Meet Button */}
{event.hangoutLink && (
<div className="flex items-center justify-between p-3 rounded-xl border border-sky-200 dark:border-sky-900/60 bg-sky-50/60 dark:bg-sky-950/30">
<div className="flex items-center gap-2.5 min-w-0">
<div className="p-2 rounded-lg text-primary shrink-0">
<Video className="size-4" />
</div>
<div className="min-w-0">
<p className="text-xs font-semibold text-zinc-900 dark:text-zinc-100">
Rapat Video Google Meet
</p>
<p className="text-[11px] text-zinc-500 dark:text-zinc-400 truncate">
{event.hangoutLink}
</p>
</div>
</div>
<Button
asChild
size="sm"
className="h-8 px-3 text-xs bg-sky-600 hover:bg-sky-700 text-white shrink-0 ml-2"
>
<a href={event.hangoutLink} target="_blank" rel="noopener noreferrer">
Gabung Meet
</a>
</Button>
</div>
)}
{/* Source Calendar */}
{event.calendarSummary && (
<div className="flex items-start gap-3">
<Calendar className="size-4 text-zinc-400 shrink-0 mt-0.5" />
<div className="space-y-0.5">
<p className="text-[11px] font-medium text-zinc-400 dark:text-zinc-500">
Kalender
</p>
<div className="flex items-center gap-2">
<span
className="size-2.5 rounded-full shrink-0"
style={{ backgroundColor: event.calendarColor || '#039be5' }}
/>
<span className="text-xs sm:text-sm font-medium text-zinc-800 dark:text-zinc-200">
{event.calendarSummary}
</span>
</div>
</div>
</div>
)}
{/* Location */}
{event.location && (
<div className="flex items-start gap-3">
<MapPin className="size-4 text-zinc-400 shrink-0 mt-0.5" />
<div className="space-y-0.5 min-w-0">
<p className="text-[11px] font-medium text-zinc-400 dark:text-zinc-500">
Lokasi
</p>
<p className="text-xs sm:text-sm text-zinc-800 dark:text-zinc-200 break-words">
{event.location}
</p>
</div>
</div>
)}
{/* Guests / Attendees */}
{guestList.length > 0 && (
<div className="flex items-start gap-3">
<Users className="size-4 text-zinc-400 shrink-0 mt-0.5" />
<div className="space-y-1.5 min-w-0 flex-1">
<p className="text-[11px] font-medium text-zinc-400 dark:text-zinc-500">
{guestList.length} Tamu (Guests)
</p>
<div className="flex flex-wrap gap-1.5">
{guestList.map((email) => (
<Badge
key={email}
variant="secondary"
className="text-[11px] font-normal bg-zinc-100 dark:bg-zinc-800 text-zinc-800 dark:text-zinc-200"
>
{email}
</Badge>
))}
</div>
</div>
</div>
)}
{/* Rich HTML Description */}
{event.description && (
<div className="flex items-start gap-3 pt-1">
<AlignLeft className="size-4 text-zinc-400 shrink-0 mt-0.5" />
<div className="space-y-1 min-w-0 flex-1">
<p className="text-[11px] font-medium text-zinc-400 dark:text-zinc-500">
Deskripsi
</p>
<div
className="prose prose-sm dark:prose-invert max-w-none
prose-headings:text-foreground prose-headings:font-bold
prose-h1:text-xl prose-h1:mb-3 prose-h1:mt-0
prose-h2:text-lg prose-h2:mb-2 prose-h2:mt-5
prose-p:text-muted-foreground prose-p:leading-relaxed
prose-li:text-muted-foreground prose-li:marker:text-primary
prose-a:text-primary prose-a:no-underline hover:prose-a:underline
prose-strong:text-foreground
prose-ul:my-2 prose-li:my-0.5"
dangerouslySetInnerHTML={{ __html: event.description, }}
/>
</div>
</div>
)}
</div>
{/* Footer Actions */}
<DialogFooter className="p-4 bg-zinc-50 dark:bg-zinc-900/50 border-t border-zinc-100 dark:border-zinc-800 flex flex-row items-center justify-between sm:justify-between gap-2">
<div>
{event.htmlLink && (
<Button
asChild
variant="ghost"
size="sm"
className="h-8 px-2.5 text-xs text-zinc-600 dark:text-zinc-400 hover:text-zinc-900 dark:hover:text-zinc-100"
>
<a href={event.htmlLink} target="_blank" rel="noopener noreferrer">
<span>Buka di Google Calendar</span>
<ExternalLink className="size-3.5 ml-1.5" />
</a>
</Button>
)}
</div>
<div className="flex items-center gap-2">
{!event.isReadOnly && (
<>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => {
onOpenChange(false);
onDelete(event);
}}
className="h-8 px-3 text-xs border-rose-200 text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/40"
>
<Trash2 className="size-3.5 mr-1.5" />
<span>Hapus</span>
</Button>
<Button
type="button"
size="sm"
onClick={() => {
onOpenChange(false);
onEdit(event);
}}
className="h-8 px-3 text-xs"
>
<Edit2 className="size-3.5" />
<span>Edit Event</span>
</Button>
</>
)}
{event.isReadOnly && (
<Button
type="button"
variant="outline"
size="sm"
onClick={() => onOpenChange(false)}
className="h-8 px-3 text-xs"
>
Tutup
</Button>
)}
</div>
</DialogFooter>
</DialogContent>
</Dialog>
);
}