mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
b657f79a2a
Add a dashboard for managing Google Calendar events and tasks, including create, edit, delete, status updates, search, and integration error notices.
238 lines
9.9 KiB
TypeScript
238 lines
9.9 KiB
TypeScript
'use client';
|
|
|
|
import React, { useState } from 'react';
|
|
import { CalendarTaskItem, TaskStatus } from '@/lib/google-calendar/types';
|
|
import { ListTodo, CheckCircle2, Clock, Edit2, Trash2, Search, ExternalLink } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
import dayjs from 'dayjs';
|
|
|
|
interface TaskListProps {
|
|
tasks: CalendarTaskItem[];
|
|
onToggleStatus: (task: CalendarTaskItem, newStatus: TaskStatus) => void;
|
|
onEdit: (task: CalendarTaskItem) => void;
|
|
onDelete: (task: CalendarTaskItem) => void;
|
|
onAddTask: () => void;
|
|
isTogglingId?: string | null;
|
|
}
|
|
|
|
export default function TaskList({
|
|
tasks,
|
|
onToggleStatus,
|
|
onEdit,
|
|
onDelete,
|
|
onAddTask,
|
|
isTogglingId,
|
|
}: TaskListProps) {
|
|
const [search, setSearch] = useState('');
|
|
const [statusFilter, setStatusFilter] = useState<'all' | 'needsAction' | 'completed'>('all');
|
|
|
|
const filtered = tasks.filter((t) => {
|
|
const q = search.toLowerCase();
|
|
const matchSearch =
|
|
t.title.toLowerCase().includes(q) ||
|
|
(t.description && t.description.toLowerCase().includes(q));
|
|
|
|
if (!matchSearch) return false;
|
|
|
|
if (statusFilter === 'all') return true;
|
|
return t.status === statusFilter;
|
|
});
|
|
|
|
const formatDue = (dueStr: string) => {
|
|
if (!dueStr) return '-';
|
|
if (!dueStr.includes('T')) {
|
|
return dayjs(dueStr).format('DD MMM YYYY');
|
|
}
|
|
return dayjs(dueStr).format('DD MMM YYYY, HH:mm') + ' WIB';
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
{/* Controls: Search & Filter Tabs */}
|
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
|
|
<div className="relative flex-1 max-w-sm">
|
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 size-4 text-zinc-400 pointer-events-none" />
|
|
<Input
|
|
placeholder="Cari task..."
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
className="pl-9 h-9 text-xs sm:text-sm bg-white dark:bg-zinc-900 border-zinc-200 dark:border-zinc-800"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1.5 bg-zinc-100 dark:bg-zinc-800/80 p-1 rounded-lg self-start sm:self-auto">
|
|
<button
|
|
type="button"
|
|
onClick={() => setStatusFilter('all')}
|
|
className={`px-2.5 py-1 text-xs rounded-md font-medium transition-colors ${
|
|
statusFilter === 'all'
|
|
? 'bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 shadow-xs'
|
|
: 'text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200'
|
|
}`}
|
|
>
|
|
Semua ({tasks.length})
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setStatusFilter('needsAction')}
|
|
className={`px-2.5 py-1 text-xs rounded-md font-medium transition-colors ${
|
|
statusFilter === 'needsAction'
|
|
? 'bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 shadow-xs'
|
|
: 'text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200'
|
|
}`}
|
|
>
|
|
Menunggu ({tasks.filter((t) => t.status === 'needsAction').length})
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setStatusFilter('completed')}
|
|
className={`px-2.5 py-1 text-xs rounded-md font-medium transition-colors ${
|
|
statusFilter === 'completed'
|
|
? 'bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 shadow-xs'
|
|
: 'text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200'
|
|
}`}
|
|
>
|
|
Selesai ({tasks.filter((t) => t.status === 'completed').length})
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* List Container */}
|
|
{filtered.length === 0 ? (
|
|
<div className="rounded-xl border border-dashed border-zinc-300 dark:border-zinc-800 p-8 text-center bg-zinc-50/50 dark:bg-zinc-900/30">
|
|
<ListTodo className="size-10 text-zinc-400 mx-auto mb-3 stroke-[1.5]" />
|
|
<h3 className="text-sm font-semibold text-zinc-800 dark:text-zinc-200">
|
|
{tasks.length === 0 ? 'Belum Ada Task Kalender' : 'Tidak Ada Task yang Sesuai Filter'}
|
|
</h3>
|
|
<p className="text-xs text-zinc-500 max-w-sm mx-auto mt-1 mb-4">
|
|
{tasks.length === 0
|
|
? 'Tambahkan task pertama Anda. Task akan diberi penanda khusus [TASK] pada Google Calendar resmi.'
|
|
: 'Silakan reset pencarian atau filter status untuk melihat data lain.'}
|
|
</p>
|
|
{tasks.length === 0 && (
|
|
<Button size="sm" onClick={onAddTask} className="h-9">
|
|
Tambah Task Pertama
|
|
</Button>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div className="space-y-2.5">
|
|
{filtered.map((item) => {
|
|
const isCompleted = item.status === 'completed';
|
|
const isProcessing = isTogglingId === item.id;
|
|
|
|
return (
|
|
<div
|
|
key={item.id}
|
|
className={`group flex flex-col md:flex-row md:items-center justify-between p-4 rounded-xl border transition-colors shadow-xs gap-3 ${
|
|
isCompleted
|
|
? 'border-zinc-200/60 dark:border-zinc-800/50 bg-zinc-50/60 dark:bg-zinc-900/40 opacity-85'
|
|
: 'border-zinc-200 dark:border-zinc-800/80 bg-white dark:bg-zinc-900 hover:border-zinc-300 dark:hover:border-zinc-700'
|
|
}`}
|
|
>
|
|
{/* Checkbox & Task Details */}
|
|
<div className="flex items-start gap-3 flex-1 min-w-0">
|
|
<div className="pt-0.5">
|
|
<Checkbox
|
|
checked={isCompleted}
|
|
disabled={isProcessing}
|
|
onCheckedChange={(checked) => {
|
|
onToggleStatus(item, checked ? 'completed' : 'needsAction');
|
|
}}
|
|
className="size-5 rounded-md border-zinc-300 dark:border-zinc-700 data-[state=checked]:bg-emerald-600 data-[state=checked]:border-emerald-600"
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-1 flex-1 min-w-0">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<h4
|
|
className={`font-semibold text-sm sm:text-base truncate ${
|
|
isCompleted
|
|
? 'line-through text-zinc-500 dark:text-zinc-400'
|
|
: 'text-zinc-900 dark:text-zinc-100'
|
|
}`}
|
|
>
|
|
{item.title}
|
|
</h4>
|
|
|
|
{isCompleted ? (
|
|
<Badge variant="statusSuccess" className="text-[10px] py-0 px-2 gap-1">
|
|
<CheckCircle2 className="size-3" />
|
|
<span>Selesai</span>
|
|
</Badge>
|
|
) : (
|
|
<Badge variant="statusWarning" className="text-[10px] py-0 px-2 gap-1">
|
|
<Clock className="size-3" />
|
|
<span>Menunggu</span>
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-zinc-500 dark:text-zinc-400">
|
|
<div className="flex items-center gap-1.5">
|
|
<Clock className="size-3.5 text-zinc-400" />
|
|
<span>Tenggat: {formatDue(item.due)}</span>
|
|
</div>
|
|
{item.completedAt && (
|
|
<span className="text-[11px] text-zinc-400">
|
|
(Diselesaikan {dayjs(item.completedAt).format('DD MMM YYYY, HH:mm')})
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
{item.description && (
|
|
<p className="text-xs text-zinc-600 dark:text-zinc-300 line-clamp-2 pt-0.5">
|
|
{item.description}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Actions */}
|
|
<div className="flex items-center gap-1.5 self-end md:self-center shrink-0 pt-2 md:pt-0 border-t md:border-t-0 border-zinc-100 dark:border-zinc-800/60 w-full md:w-auto justify-end">
|
|
{item.htmlLink && (
|
|
<Button
|
|
asChild
|
|
variant="ghost"
|
|
size="sm"
|
|
className="h-8 w-8 p-0 text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200"
|
|
title="Lihat di Google Calendar"
|
|
>
|
|
<a href={item.htmlLink} target="_blank" rel="noopener noreferrer">
|
|
<ExternalLink className="size-3.5" />
|
|
</a>
|
|
</Button>
|
|
)}
|
|
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onEdit(item)}
|
|
className="h-8 px-2.5 text-xs text-zinc-700 dark:text-zinc-300 hover:bg-zinc-100 dark:hover:bg-zinc-800"
|
|
>
|
|
<Edit2 className="size-3 mr-1" />
|
|
<span>Edit</span>
|
|
</Button>
|
|
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onDelete(item)}
|
|
className="h-8 px-2.5 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 mr-1" />
|
|
<span>Hapus</span>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|