mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
93a9b489d0
This commit updates the task dashboard and assignment views for smaller screens by tightening spacing, improving text wrapping, and making filter/search controls responsive. It also refreshes the assignment detail layout with clearer date spans, team summaries, and switchable grid/list member views, while polishing client and assignment cards for better readability on mobile.
291 lines
19 KiB
TypeScript
291 lines
19 KiB
TypeScript
"use client";
|
|
|
|
import { IProjectAssignment } from '../../type.assignment';
|
|
import { motion } from 'motion/react';
|
|
import { Card900 } from '@/components/ui/card';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu';
|
|
import {
|
|
Tooltip, TooltipContent, TooltipTrigger,
|
|
} from '@/components/ui/tooltip';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import { Briefcase, Calendar, ExternalLink, MoreVertical, Building, FolderGit2, FileText, BuildingComplex } from 'lucide-react';
|
|
import Link from 'next/link';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { formatAssignmentDate } from './AssignmentList';
|
|
|
|
interface AssignmentGridProps {
|
|
assignments: IProjectAssignment[];
|
|
clientId?: string;
|
|
onManageTeam?: (assignment: IProjectAssignment) => void;
|
|
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
|
onDelete?: (assignment: IProjectAssignment) => void;
|
|
}
|
|
|
|
export default function AssignmentGrid({
|
|
assignments,
|
|
clientId,
|
|
onManageTeam,
|
|
onUpdateStatus,
|
|
onDelete,
|
|
}: AssignmentGridProps) {
|
|
return (
|
|
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6 auto-rows-fr">
|
|
{assignments.map((assignment, index) => {
|
|
const isProject = !!assignment.wo_name;
|
|
const assignmentType = isProject ? 'Work Order' : 'Internal Memo';
|
|
const assignmentName = assignment.wo_name || assignment.im_name || assignment.project?.name || 'Untitled Assignment';
|
|
const assignmentCode = assignment.wo_code || assignment.im_code || assignment.project?.code;
|
|
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
|
|
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
|
|
const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description;
|
|
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name;
|
|
|
|
const illustrationSrc = isProject
|
|
? '/assets/illustrations/work_order.jpg'
|
|
: '/assets/illustrations/internal_memo.jpg';
|
|
|
|
const effectiveClientId = clientId || assignment.client?.id;
|
|
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
|
|
const projectDetailUrl = effectiveClientId && assignment.project?.id
|
|
? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}`
|
|
: null;
|
|
const editAssignmentUrl = effectiveClientId
|
|
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
|
|
: null;
|
|
|
|
return (
|
|
<motion.div
|
|
initial={{ opacity: 0, y: 8 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ duration: 0.25, delay: index * 0.04 }}
|
|
className="h-full"
|
|
key={index}
|
|
>
|
|
<Card900 className="h-full group hover:border-his/50 transition-all duration-300 hover:shadow-xl hover:-translate-y-1 flex flex-col justify-between p-4 sm:p-5 border-border/80 rounded-2xl bg-card gap-4 min-w-0">
|
|
{/* Top Section: 3D Emblem, Badges, and Action Menu */}
|
|
<div className="flex items-start justify-between gap-2.5 min-w-0">
|
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
|
{/* 3D App Icon / Emblem */}
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="relative w-12 h-12 sm:w-16 sm:h-16 shrink-0 rounded-2xl overflow-hidden bg-muted/20 dark:bg-zinc-800/40 border border-border/60 flex items-center justify-center p-1 shadow-2xs group-hover:scale-105 group-hover:border-his/40 transition-all duration-300"
|
|
>
|
|
<LazyImage
|
|
src={illustrationSrc}
|
|
alt={assignmentType}
|
|
className="w-full h-full bg-transparent"
|
|
imgClassName="object-contain rounded-lg"
|
|
/>
|
|
</Link>
|
|
|
|
{/* Identity & Badges */}
|
|
<div className="min-w-0 space-y-1.5 flex-1">
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
|
<Badge
|
|
variant="outline"
|
|
className={`text-[10px] font-semibold tracking-wide px-2 py-0.5 gap-1 shrink-0 ${isProject
|
|
? 'bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/30'
|
|
: 'bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/30'
|
|
}`}
|
|
>
|
|
{isProject ? <Briefcase className="w-3 h-3" /> : <FileText className="w-3 h-3" />}
|
|
<span>{assignmentType}</span>
|
|
</Badge>
|
|
|
|
{assignmentStatus && <BadgeStatus status={assignmentStatus} />}
|
|
</div>
|
|
|
|
{assignmentCode && (
|
|
<span className="inline-block text-[11px] font-mono font-semibold px-2 py-0.5 rounded-md bg-muted/80 dark:bg-zinc-800 text-muted-foreground border border-border/60 shrink-0 truncate max-w-full">
|
|
# {assignmentCode}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Actions Menu */}
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 text-muted-foreground hover:text-foreground shrink-0 rounded-full hover:bg-muted"
|
|
aria-label="Assignment actions"
|
|
>
|
|
<MoreVertical className="w-4 h-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-48">
|
|
<DropdownMenuItem asChild>
|
|
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
|
</DropdownMenuItem>
|
|
{projectDetailUrl && (
|
|
<DropdownMenuItem asChild>
|
|
<Link href={projectDetailUrl}>View Project Details</Link>
|
|
</DropdownMenuItem>
|
|
)}
|
|
{!clientId && assignment.client?.id && (
|
|
<DropdownMenuItem asChild>
|
|
<Link href={`/task/client-detail/${assignment.client.id}`}>View Client</Link>
|
|
</DropdownMenuItem>
|
|
)}
|
|
{editAssignmentUrl && (
|
|
<DropdownMenuItem asChild>
|
|
<Link href={editAssignmentUrl}>Edit Assignment</Link>
|
|
</DropdownMenuItem>
|
|
)}
|
|
{onManageTeam && (
|
|
<DropdownMenuItem onSelect={() => onManageTeam(assignment)}>
|
|
Manage Team
|
|
</DropdownMenuItem>
|
|
)}
|
|
{onUpdateStatus && (
|
|
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
|
Update Status
|
|
</DropdownMenuItem>
|
|
)}
|
|
{onDelete && (
|
|
<DropdownMenuItem
|
|
onSelect={() => onDelete(assignment)}
|
|
className="text-destructive focus:text-destructive"
|
|
>
|
|
Delete
|
|
</DropdownMenuItem>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
|
|
{/* Center: Title, Project, Description, Tags */}
|
|
<div className="space-y-2.5 flex-1 min-w-0">
|
|
{/* Title */}
|
|
<div>
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="font-bold text-base sm:text-lg leading-snug text-foreground hover:text-his transition-colors block line-clamp-2 tracking-tight wrap-break-word"
|
|
>
|
|
{assignmentName}
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Project Reference */}
|
|
{assignment.project?.name && (
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-0.5 min-w-0">
|
|
<FolderGit2 className="w-3.5 h-3.5 text-his shrink-0" />
|
|
<span className="text-[11px] text-muted-foreground shrink-0">Project:</span>
|
|
{projectDetailUrl ? (
|
|
<Link
|
|
href={projectDetailUrl}
|
|
className="font-medium text-foreground hover:text-his truncate hover:underline flex items-center gap-1 min-w-0"
|
|
>
|
|
<span className="truncate">{assignment.project.name}</span>
|
|
<ExternalLink className="w-3 h-3 shrink-0 opacity-60" />
|
|
</Link>
|
|
) : (
|
|
<span className="font-medium text-foreground truncate min-w-0">{assignment.project.name}</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Description */}
|
|
{assignmentDesc && (
|
|
<p className="text-xs text-muted-foreground line-clamp-2 leading-relaxed pt-0.5 wrap-break-word">
|
|
{assignmentDesc}
|
|
</p>
|
|
)}
|
|
|
|
{/* Client & End User Badges */}
|
|
<div className="flex flex-wrap items-center gap-1.5 pt-1 text-xs">
|
|
{assignment.client?.name && !clientId && (
|
|
<Link
|
|
href={`/task/client-detail/${assignment.client.id}`}
|
|
className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/60 hover:bg-muted border border-border/50 text-foreground transition-colors text-[11px] max-w-full min-w-0"
|
|
>
|
|
{assignment.client.photo ?
|
|
<LazyImage
|
|
src={assignment.client.photo}
|
|
alt={assignment.client.name}
|
|
className="w-3 h-3 rounded-xs bg-transparent shrink-0"
|
|
imgClassName="object-cover"
|
|
/>
|
|
:
|
|
<BuildingComplex className="w-3 h-3 text-muted-foreground shrink-0" />
|
|
}
|
|
<span className="text-muted-foreground shrink-0">Client:</span>
|
|
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.client.name}</span>
|
|
</Link>
|
|
)}
|
|
|
|
{assignment.end_user?.name && (
|
|
<div className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/40 border border-border/40 text-foreground text-[11px] max-w-full min-w-0">
|
|
<div className="w-3.5 h-3.5 rounded-xs overflow-hidden shrink-0 bg-secondary">
|
|
{assignment.end_user?.photo ? (
|
|
<LazyImage
|
|
src={assignment.end_user.photo ? assignment.end_user.photo : '/assets/ilustration.png'}
|
|
alt={assignment.end_user.name}
|
|
className="w-full h-full bg-transparent"
|
|
imgClassName="object-contain"
|
|
/>
|
|
) : (
|
|
<Building className="w-3 h-3 text-muted-foreground" />
|
|
)}
|
|
</div>
|
|
<span className="text-muted-foreground shrink-0">End User:</span>
|
|
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.end_user.name}</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Footer: Timeline & Team Members */}
|
|
<div className="pt-3.5 border-t border-border/60 flex flex-wrap sm:flex-nowrap items-center justify-between gap-2.5 text-xs">
|
|
<div className="flex items-center gap-1.5 text-muted-foreground min-w-0 flex-1">
|
|
<Calendar className="w-3.5 h-3.5 shrink-0 text-muted-foreground/80" />
|
|
<span className="font-medium text-[11px] truncate">
|
|
{formatAssignmentDate(assignmentStartDate)} - {formatAssignmentDate(assignmentEndDate)}
|
|
</span>
|
|
</div>
|
|
|
|
{/* Assigned Team */}
|
|
<div className="flex -space-x-2 overflow-hidden items-center shrink-0">
|
|
{assignment.project_assignment_work_order_detail?.slice(0, 4).map((item, key) => (
|
|
<div key={key}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="inline-block relative">
|
|
<LazyImage
|
|
src={item?.user?.avatar ? `${process.env.BASE_URL_IMG}/${item.user.avatar}` : '/assets/no-avatar.jpg'}
|
|
alt={item?.user?.fullname || item?.user?.name || 'Member'}
|
|
className="w-7 h-7 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p className="text-xs font-bold">{item?.user?.fullname || item?.user?.name}</p>
|
|
<p className="text-[10px] opacity-80">{item?.user?.position?.name || 'Team Member'}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
))}
|
|
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length > 4 && (
|
|
<div className="w-7 h-7 rounded-full bg-accent ring-2 ring-background flex items-center justify-center text-[10px] font-bold">
|
|
+{assignment.project_assignment_work_order_detail.length - 4}
|
|
</div>
|
|
)}
|
|
{(!assignment.project_assignment_work_order_detail || assignment.project_assignment_work_order_detail.length === 0) && (
|
|
<span className="text-[11px] text-muted-foreground italic mr-1">No team</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|