mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:56:27 +00:00
5a3629badf
Added the ability to view and re-download leave application forms in the Employee History page (Leave, Permit, and Sick tabs) Added employee alpha stats and employee alpha detail in Employee Performance Page Added total WFO, WFH and WFS in Admin Summary Report Added batch import from Excel files in Admin Manual Attendance
138 lines
7.4 KiB
TypeScript
138 lines
7.4 KiB
TypeScript
"use client"
|
|
|
|
import { useState, type FC } from 'react';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogDescription,
|
|
} from '@/components/ui/dialog';
|
|
import { CalendarX2, AlertTriangle, Calendar, ChevronRight, X, UserX, Eye } from 'lucide-react';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { format, getMonth, getYear, parseISO } from 'date-fns';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
type Props = {
|
|
alphaData: any[]
|
|
};
|
|
|
|
const monthColors: Record<number, { bg: string; text: string; border: string; dot: string }> = {
|
|
0: { bg: 'bg-primary/10', text: 'text-primary', border: 'border-primary/20', dot: 'bg-primary' },
|
|
1: { bg: 'bg-destructive/10', text: 'text-destructive', border: 'border-destructive/20', dot: 'bg-destructive' },
|
|
};
|
|
|
|
const EmployeeAlpha: FC<Props> = ({ alphaData }) => {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
// Group by month
|
|
const grouped = alphaData.reduce<Record<string, typeof alphaData>>((acc, item) => {
|
|
const d = parseISO(item.date);
|
|
const key = `${getYear(d)}-${String(getMonth(d)).padStart(2, '0')}`;
|
|
if (!acc[key]) acc[key] = [];
|
|
acc[key].push(item);
|
|
return acc;
|
|
}, {});
|
|
|
|
const sortedMonths = Object.keys(grouped).sort();
|
|
|
|
return (
|
|
<>
|
|
<Eye size={20} onClick={() => setOpen(true)} className='text-emerald-600 hover:text-his duration-200 cursor-pointer' />
|
|
|
|
{/* Modal */}
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogContent className="sm:max-w-lg p-0 gap-0 overflow-hidden border-border/50 bg-card">
|
|
{/* Modal Header */}
|
|
<div className="relative bg-destructive/5 border-b border-destructive/10 px-6 pt-6 pb-5">
|
|
<div className="absolute -top-8 -right-8 w-24 h-24 rounded-full bg-destructive/10 blur-xl" />
|
|
<DialogHeader className="relative">
|
|
<div className="flex items-center gap-3 mb-2">
|
|
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-destructive/10 border border-destructive/20">
|
|
<CalendarX2 className="h-5 w-5 text-destructive" />
|
|
</div>
|
|
<div>
|
|
<DialogTitle className="text-lg font-semibold text-foreground">
|
|
Absence Records
|
|
</DialogTitle>
|
|
<DialogDescription className="text-sm text-muted-foreground mt-0.5">
|
|
{alphaData.length} days without check-in
|
|
</DialogDescription>
|
|
</div>
|
|
</div>
|
|
</DialogHeader>
|
|
</div>
|
|
|
|
{/* Modal Body */}
|
|
<div className="px-6 py-5 max-h-[60vh] overflow-y-auto space-y-5">
|
|
{sortedMonths.map((monthKey, mIdx) => {
|
|
const dates = grouped[monthKey];
|
|
const sampleDate = parseISO(dates[0].date);
|
|
const monthLabel = format(sampleDate, 'MMMM yyyy');
|
|
const colorIdx = mIdx % 2;
|
|
const colors = monthColors[colorIdx];
|
|
|
|
return (
|
|
<div key={monthKey} className="animate-fade-in" style={{ animationDelay: `${mIdx * 80}ms` }}>
|
|
{/* Month Header */}
|
|
<div className="flex items-center justify-between mb-3">
|
|
<div className="flex items-center gap-2">
|
|
<div className={`h-2 w-2 rounded-full ${colors.dot}`} />
|
|
<span className="text-sm font-semibold text-foreground">{monthLabel}</span>
|
|
</div>
|
|
<Badge variant="secondary" className="text-xs font-mono">
|
|
{dates.length} day{dates.length > 1 ? 's' : ''}
|
|
</Badge>
|
|
</div>
|
|
|
|
{/* Date Items */}
|
|
<div className="space-y-2">
|
|
{dates.map((item, idx) => {
|
|
const d = parseISO(item.date);
|
|
return (
|
|
<div
|
|
key={item.date}
|
|
className={`flex items-center gap-3 rounded-xl border ${colors.border} ${colors.bg} px-4 py-3 transition-all duration-200 hover:scale-[1.01]`}
|
|
style={{ animationDelay: `${(mIdx * 4 + idx) * 50}ms` }}
|
|
>
|
|
<div className={`flex h-9 w-9 items-center justify-center rounded-lg bg-card border ${colors.border}`}>
|
|
<Calendar className={`h-4 w-4 ${colors.text}`} />
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<p className="text-sm font-medium text-foreground">
|
|
{format(d, 'EEEE')}
|
|
</p>
|
|
<p className="text-xs text-muted-foreground font-mono">
|
|
{format(d, 'dd MMMM yyyy')}
|
|
</p>
|
|
</div>
|
|
<Badge variant="outline" className={`${colors.text} ${colors.border} ${colors.bg} text-xs`}>
|
|
Alpha
|
|
</Badge>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
|
|
{/* Modal Footer */}
|
|
<div className="border-t border-border px-6 py-4 bg-muted/30">
|
|
<div className="flex items-center justify-between">
|
|
<p className="text-xs text-muted-foreground">
|
|
Total: <span className="font-semibold font-mono text-foreground">{alphaData.length}</span> absence records
|
|
</p>
|
|
<Button variant="outline" size="sm" onClick={() => setOpen(false)}>
|
|
Close
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default EmployeeAlpha; |