mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
6f52078aa5
This commit refreshes the client project assignment UI with a new dashboard summary, streamlined card layouts, and shared assignment overview helpers. It adds phase/progress tracking, delivery health indicators, and improved team/status calculations across the assignment grid and list views. It also updates the project assignment type definitions and bumps the app version.
355 lines
22 KiB
TypeScript
355 lines
22 KiB
TypeScript
"use client";
|
|
|
|
import { IProjectAssignment } from '../../type.assignment';
|
|
import { motion } from 'motion/react';
|
|
import { Card900 } from '@/components/ui/card';
|
|
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 { Calendar, MoreVertical, ArrowUpRight } from 'lucide-react';
|
|
import Link from 'next/link';
|
|
import { cn } from '@/lib/utils';
|
|
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import {
|
|
getAssignmentOverview,
|
|
ProgressColorConfig,
|
|
formatAssignmentDate
|
|
} from '../../utils/assignment-overview-helpers';
|
|
import { END_USER_FALLBACK_IMAGE } from '../../types';
|
|
|
|
const STEPPER_STAGES = ['Dev', 'SIT', 'UAT', 'PTR', 'Live'] as const;
|
|
|
|
function CompactPhaseStepper({ phaseIndex, progressColor }: { phaseIndex: number; progressColor: ProgressColorConfig }) {
|
|
return (
|
|
<div className="relative pt-2 pb-0.5 w-full">
|
|
{/* Background Rail Line */}
|
|
<div className="absolute top-3.5 left-2 right-2 h-0.5 bg-muted dark:bg-zinc-800" />
|
|
|
|
{/* Active Colored Fill Line */}
|
|
<div
|
|
className={`absolute top-3.5 left-2 h-0.5 ${progressColor.barColor} transition-all duration-300`}
|
|
style={{ width: `${Math.min(100, Math.max(0, (phaseIndex / 4) * 100))}%` }}
|
|
/>
|
|
|
|
{/* 5 Milestone Stage Nodes */}
|
|
<div className="relative flex items-center justify-between">
|
|
{STEPPER_STAGES.map((stage, i) => {
|
|
const isCompleted = i < phaseIndex;
|
|
const isActive = i === phaseIndex;
|
|
|
|
return (
|
|
<div key={stage} className="flex flex-col items-center gap-1.5 z-10">
|
|
{isActive ? (
|
|
<div className={`w-3.5 h-3.5 rounded-full flex items-center justify-center ${progressColor.glowRing} ${progressColor.activeDot} transition-transform`}>
|
|
<div className="w-1.5 h-1.5 rounded-full bg-white shadow-xs" />
|
|
</div>
|
|
) : isCompleted ? (
|
|
<div className={`w-2.5 h-2.5 rounded-full ${progressColor.barColor} transition-colors`} />
|
|
) : (
|
|
<div className="w-2 h-2 rounded-full bg-muted-foreground/30 dark:bg-zinc-700 transition-colors" />
|
|
)}
|
|
|
|
<span className={cn(
|
|
"text-[10px] tracking-tight font-medium transition-colors",
|
|
isActive
|
|
? `${progressColor.textColor} font-bold`
|
|
: isCompleted
|
|
? "text-foreground dark:text-zinc-300"
|
|
: "text-muted-foreground/60 dark:text-zinc-500"
|
|
)}>
|
|
{stage}
|
|
</span>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
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-5 auto-rows-fr">
|
|
{assignments.map((assignment, index) => {
|
|
const item = getAssignmentOverview(assignment, index);
|
|
|
|
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 = !item.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;
|
|
|
|
const illustrationSrc = item.isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
|
|
|
|
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={assignment.id || index}
|
|
>
|
|
<Card900 className="h-full group hover:border-his/50 transition-all duration-300 hover:shadow-xl hover:-translate-y-0.5 flex flex-col justify-between p-4 sm:p-5 border-border/80 rounded-2xl bg-card gap-4 min-w-0">
|
|
|
|
{/* Top Section: Emblem, Badges & Action Menu */}
|
|
<div className="flex items-start justify-between gap-3 min-w-0">
|
|
<div className="flex items-start gap-3 min-w-0 flex-1">
|
|
{/* 3D Dossier Folder Thumbnail */}
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="relative w-12 h-12 sm:w-14 sm:h-14 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={item.assignmentType}
|
|
className="w-full h-full bg-transparent"
|
|
imgClassName="object-contain rounded-xl"
|
|
/>
|
|
</Link>
|
|
|
|
{/* Badges Stack */}
|
|
<div className="min-w-0 space-y-1.5 flex-1">
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
|
{/* Type Pill */}
|
|
<span className={cn(
|
|
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium border",
|
|
item.isProject
|
|
? "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25"
|
|
: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/25"
|
|
)}>
|
|
<span className={cn("h-1.5 w-1.5 rounded-full", item.isProject ? "bg-amber-500" : "bg-purple-500")} />
|
|
<span>{item.assignmentType}</span>
|
|
</span>
|
|
|
|
{/* Project Status Badge matching technical status badge colors */}
|
|
<BadgeStatus status={item.projectStatusName} />
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1.5 flex-wrap">
|
|
{/* Code Pill with Tooltip */}
|
|
{item.code ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="font-mono text-[11px] font-medium text-muted-foreground/80 px-1.5 py-0.5 rounded-md bg-muted/60 dark:bg-zinc-800/80 border border-border/70 shrink-0 cursor-help hover:border-border transition-colors">
|
|
# {item.code}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Assignment Code</p>
|
|
<p className="text-[11px] font-mono text-muted-foreground">{item.code}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
) : null}
|
|
|
|
<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>
|
|
|
|
{/* Middle Section: Title, End User & Date with Tooltips */}
|
|
<div className="space-y-2 flex-1 min-w-0">
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="font-bold text-base leading-snug text-foreground hover:text-his transition-colors block line-clamp-2 tracking-tight wrap-break-word"
|
|
>
|
|
{item.title}
|
|
</Link>
|
|
|
|
<div className="space-y-1 text-xs text-muted-foreground pt-0.5">
|
|
{item.endUserName &&
|
|
<div className="flex items-center gap-1.5 min-w-0">
|
|
<LazyImage
|
|
src={item.endUserPhoto}
|
|
fallbackSrc={END_USER_FALLBACK_IMAGE}
|
|
alt={item.endUserName}
|
|
className="w-4 h-4 bg-transparent"
|
|
imgClassName="object-contain object-left group-hover/logo:scale-105 transition-transform"
|
|
/>
|
|
<span className="font-medium text-foreground truncate">
|
|
End User: {item.endUserName}
|
|
</span>
|
|
</div>
|
|
}
|
|
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="flex items-center gap-1.5 shrink-0 cursor-help hover:text-foreground transition-colors">
|
|
<Calendar className="w-3.5 h-3.5 text-muted-foreground/70 shrink-0" />
|
|
<span>{item.formattedDateRange}</span>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Assignment Timeline</p>
|
|
<p className="text-[11px] text-muted-foreground mt-1">
|
|
Start: <span className="text-primary">{item.startDate ? formatAssignmentDate(item.startDate) : 'Start date not set'}</span>
|
|
</p>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
End: <span className="text-primary">{item.endDate ? formatAssignmentDate(item.endDate) : 'End date not set'}</span>
|
|
</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Progress & Stepper Section */}
|
|
<div className="space-y-2 pt-2 border-t border-border/60">
|
|
<div className="flex items-center justify-between text-xs font-mono font-medium">
|
|
<span className="text-muted-foreground">{item.daysRatioText}</span>
|
|
<div className="h-1.5 rounded-full bg-muted dark:bg-zinc-800 flex-1 mx-2.5 overflow-hidden">
|
|
<div
|
|
className={`h-full rounded-full ${item.progressColor.barColor} transition-all duration-500`}
|
|
style={{ width: `${item.progressPercent}%` }}
|
|
/>
|
|
</div>
|
|
<span className="text-foreground font-bold">{item.progressPercent}%</span>
|
|
</div>
|
|
|
|
<CompactPhaseStepper phaseIndex={item.phaseIndex} progressColor={item.progressColor} />
|
|
</div>
|
|
|
|
{/* Footer: Delivery Health Badge & Team Avatars */}
|
|
<div className="pt-3 border-t border-border/60 flex items-center justify-between gap-2 text-xs">
|
|
<div className="space-y-1 min-w-0 flex-1">
|
|
<span className={cn(
|
|
"inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[11px] font-medium",
|
|
item.healthBadgeClass
|
|
)}>
|
|
<span className={cn("h-1.5 w-1.5 rounded-full", item.healthDotClass)} />
|
|
<span>{item.healthStatus}</span>
|
|
</span>
|
|
<p className="text-[11px] text-muted-foreground truncate">{item.remainingText}</p>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1.5 shrink-0">
|
|
{item.teamMembers.length > 0 ? (
|
|
<>
|
|
<div className="flex -space-x-1.5 overflow-hidden items-center">
|
|
{item.teamMembers.slice(0, 3).map((m, mIdx) => (
|
|
<Tooltip key={m.id || mIdx}>
|
|
<TooltipTrigger asChild>
|
|
<div className="inline-block relative">
|
|
<LazyImage
|
|
src={m.avatar ? `${process.env.BASE_URL_IMG}/${m.avatar}` : '/assets/no-avatar.jpg'}
|
|
alt={m.name}
|
|
className="inline-block h-6 w-6 rounded-full border border-card bg-muted cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p className="text-xs font-semibold text-popover-foreground">{m.name}</p>
|
|
<p className="text-[10px] text-muted-foreground">{m.position || 'Team Member'}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
))}
|
|
</div>
|
|
<span className="text-[11px] font-medium text-muted-foreground">{item.teamCount}p</span>
|
|
</>
|
|
) : (
|
|
<span className="text-[11px] text-muted-foreground/70 italic">None</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|