mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
c6aa1c912a
Introduce ConvertedAssignmentBadge component to surface conversions between Internal Memos (IM) and Projects with hovercard details for both directions. Integrate the badge into AssignmentGrid and AssignmentList, add origin IM link when a project assignment lacks a project, and reuse formatAssignmentDate. Extend IProjectAssignment type to include im and list_wo fields to support the new UI data paths.
327 lines
22 KiB
TypeScript
327 lines
22 KiB
TypeScript
"use client";
|
|
|
|
import { IProjectAssignment } from '../../type.assignment';
|
|
import { CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../types';
|
|
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, FolderGit2, FileText, ArrowUpRight } from 'lucide-react';
|
|
import Link from 'next/link';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { formatAssignmentDate } from './AssignmentList';
|
|
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
|
|
|
|
interface AssignmentGridProps {
|
|
assignments: IProjectAssignment[];
|
|
clientId?: string;
|
|
onManageTeam?: (assignment: IProjectAssignment) => void;
|
|
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
|
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
|
|
onDelete?: (assignment: IProjectAssignment) => void;
|
|
}
|
|
|
|
export default function AssignmentGrid({
|
|
assignments,
|
|
clientId,
|
|
onManageTeam,
|
|
onUpdateStatus,
|
|
onUpdateAdministrationStatus,
|
|
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_assignment_status?.name || assignment.project?.status;
|
|
|
|
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}`
|
|
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`;
|
|
const promoteAssignmentUrl = !isProject
|
|
? (effectiveClientId
|
|
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true`
|
|
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`)
|
|
: 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">
|
|
{/* Row 1: Assignment Type and Status */}
|
|
<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>
|
|
|
|
{/* Row 2: Assignment Code & Converted Indicator */}
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
|
{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>
|
|
)}
|
|
|
|
<ConvertedAssignmentBadge assignment={assignment} clientId={effectiveClientId} />
|
|
</div>
|
|
</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">{promoteAssignmentUrl && (
|
|
<DropdownMenuItem asChild>
|
|
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
|
|
<ArrowUpRight className="w-4 h-4 text-his" />
|
|
Promote to Project
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
)}
|
|
<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>
|
|
)}
|
|
{onUpdateAdministrationStatus && (
|
|
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
|
|
Update Administration Status
|
|
</DropdownMenuItem>
|
|
)}
|
|
{onUpdateStatus && (
|
|
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
|
Update Technical 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>
|
|
)}
|
|
|
|
{/* Origin IM Reference (for converted assignments without project) */}
|
|
{!assignment.project?.name && (assignment.im?.im_name || (assignment.im_id && assignment.im_name)) && (
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-0.5 min-w-0">
|
|
<FileText className="w-3.5 h-3.5 text-purple-600 dark:text-purple-400 shrink-0" />
|
|
<span className="text-[11px] text-muted-foreground shrink-0">Origin IM:</span>
|
|
{effectiveClientId && (assignment.im_id || assignment.im?.id) ? (
|
|
<Link
|
|
href={`/task/client-detail/${effectiveClientId}/${assignment.im_id || assignment.im?.id}`}
|
|
className="font-medium text-foreground hover:text-purple-600 dark:hover:text-purple-400 truncate hover:underline flex items-center gap-1 min-w-0"
|
|
>
|
|
<span className="truncate">{assignment.im?.im_name || assignment.im_name}</span>
|
|
<ArrowUpRight className="w-3 h-3 shrink-0 opacity-60" />
|
|
</Link>
|
|
) : (
|
|
<span className="font-medium text-foreground truncate min-w-0">{assignment.im?.im_name || assignment.im_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"
|
|
>
|
|
<LazyImage
|
|
src={assignment.client.photo || CLIENT_FALLBACK_IMAGE}
|
|
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
|
alt={assignment.client.name}
|
|
className="w-3.5 h-3.5 rounded-xs bg-transparent shrink-0"
|
|
imgClassName="object-contain"
|
|
/>
|
|
<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-transparent">
|
|
<LazyImage
|
|
src={assignment.end_user?.photo || END_USER_FALLBACK_IMAGE}
|
|
fallbackSrc={END_USER_FALLBACK_IMAGE}
|
|
alt={assignment.end_user.name}
|
|
className="w-full h-full bg-transparent"
|
|
imgClassName="object-contain"
|
|
/>
|
|
</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>
|
|
);
|
|
}
|