mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
ffcf3c6e58
This commit reorganizes client and project-assignment screens into dedicated grid/list components, adds a shared layout toggle via the URL query string, and updates task pages to render the selected view consistently. It also moves shared client form logic into a client folder, improves status badge formatting, extends LazyImage with custom image classes, and updates the illustration assets and Lucide dependency used in the task UI.
287 lines
19 KiB
TypeScript
287 lines
19 KiB
TypeScript
"use client";
|
|
|
|
import { IProjectAssignment } from '../../type.assignment';
|
|
import { motion } from 'motion/react';
|
|
import { Card900, CardContent } 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, MoreVertical, FolderGit2, FileText, BuildingComplex } from 'lucide-react';
|
|
import Link from 'next/link';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
|
|
export const formatAssignmentDate = (dateStr?: string) => {
|
|
if (!dateStr) return 'N/A';
|
|
const d = new Date(dateStr);
|
|
if (isNaN(d.getTime())) return 'N/A';
|
|
const day = String(d.getDate()).padStart(2, '0');
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
const month = months[d.getMonth()];
|
|
const year = d.getFullYear();
|
|
return `${day} ${month} ${year}`;
|
|
};
|
|
|
|
interface AssignmentListProps {
|
|
assignments: IProjectAssignment[];
|
|
clientId?: string;
|
|
onManageTeam?: (assignment: IProjectAssignment) => void;
|
|
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
|
onDelete?: (assignment: IProjectAssignment) => void;
|
|
}
|
|
|
|
export default function AssignmentList({
|
|
assignments,
|
|
clientId,
|
|
onManageTeam,
|
|
onUpdateStatus,
|
|
onDelete,
|
|
}: AssignmentListProps) {
|
|
return (
|
|
<div className="flex flex-col gap-5">
|
|
{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 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="w-full"
|
|
key={index}
|
|
>
|
|
<Card900 className="group overflow-hidden hover:shadow-md transition-all duration-300 border-border/80 hover:border-his/40 rounded-2xl py-1 bg-card">
|
|
<CardContent className="p-4 sm:p-5 flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
|
{/* Left: Thumbnail & Visual Indicator */}
|
|
<div className="flex items-start gap-4 min-w-0 flex-1">
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="relative w-16 h-16 sm:w-20 sm:h-20 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:border-his/40 group-hover:scale-105 transition-all duration-300"
|
|
>
|
|
<LazyImage
|
|
src={illustrationSrc}
|
|
alt={assignmentType}
|
|
className="w-full h-full bg-transparent"
|
|
imgClassName="object-contain rounded-lg"
|
|
/>
|
|
</Link>
|
|
|
|
{/* Center Details */}
|
|
<div className="min-w-0 flex-1 space-y-1.5">
|
|
{/* Line 1: Type Badge, Status, Code, and Project Reference */}
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Badge
|
|
variant="outline"
|
|
className={`text-[10px] font-semibold px-2 py-0.5 gap-1 ${isProject
|
|
? 'bg-amber-500/15 text-amber-700 dark:text-amber-400 border-amber-500/30'
|
|
: 'bg-purple-500/15 text-purple-700 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} />}
|
|
|
|
{assignmentCode ? (
|
|
<span className="text-[11px] font-mono font-medium px-2 py-0.5 rounded-md bg-muted/80 dark:bg-zinc-800 text-muted-foreground border border-border/60 shrink-0">
|
|
# {assignmentCode}
|
|
</span>
|
|
) : null}
|
|
|
|
|
|
</div>
|
|
|
|
{/* Line 2: Assignment Title */}
|
|
<div>
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="font-semibold text-base sm:text-lg leading-snug text-foreground hover:text-his transition-colors block tracking-tight line-clamp-1 py-0.5"
|
|
>
|
|
{assignmentName}
|
|
</Link>
|
|
{assignment.project?.name && (
|
|
<div className="flex items-center gap-1 text-xs text-muted-foreground ml-auto sm:ml-0 mt-2">
|
|
<FolderGit2 className="w-3.5 h-3.5 text-his shrink-0" />
|
|
<span className="text-[11px] text-muted-foreground hidden sm:inline">Project:</span>
|
|
{projectDetailUrl ? (
|
|
<Link
|
|
href={projectDetailUrl}
|
|
className="font-medium text-foreground hover:text-his truncate hover:underline inline-block"
|
|
>
|
|
{assignment.project.name}
|
|
</Link>
|
|
) : (
|
|
<span className="font-medium text-foreground truncate">{assignment.project.name}</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Line 3: Metadata, Client, End User, Timeline, Notes */}
|
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground pt-0.5">
|
|
{assignment.client?.name && !clientId && (
|
|
<Link
|
|
href={`/task/client-detail/${assignment.client.id}`}
|
|
className="flex items-center gap-1 text-[11px] font-medium text-foreground hover:text-his transition-colors"
|
|
>
|
|
<BuildingComplex className="w-3 h-3 text-muted-foreground" />
|
|
<span className="text-muted-foreground">Client:</span>
|
|
<span className="truncate max-w-50">{assignment.client.name}</span>
|
|
</Link>
|
|
)}
|
|
|
|
{assignment.end_user?.name && (
|
|
<div className="flex items-center gap-1 text-[11px] text-foreground">
|
|
<span className="text-muted-foreground">End User:</span>
|
|
<span className="font-medium truncate max-w-50">{assignment.end_user.name}</span>
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex items-center gap-1 text-[11px] text-muted-foreground">
|
|
<Calendar className="w-3.5 h-3.5 text-muted-foreground/80" />
|
|
<span>
|
|
{formatAssignmentDate(assignmentStartDate)} - {formatAssignmentDate(assignmentEndDate)}
|
|
</span>
|
|
</div>
|
|
|
|
{assignment.note && (
|
|
<span className="text-[11px] italic text-muted-foreground/80 line-clamp-1 max-w-50">
|
|
Note: {assignment.note}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right: Team Stack & Actions */}
|
|
<div className="flex items-center justify-between md:justify-end gap-3 w-full md:w-auto shrink-0 pt-3 md:pt-0 border-t md:border-t-0 border-border/50">
|
|
{/* Team Avatar Stack */}
|
|
<div className="flex -space-x-2 overflow-hidden items-center">
|
|
{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 || 'User'}
|
|
className="inline-block h-8 w-8 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="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background 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-xs text-muted-foreground italic mr-1">No team assigned</span>
|
|
)}
|
|
</div>
|
|
|
|
{/* Action Buttons */}
|
|
<div className="flex items-center gap-1.5">
|
|
{/* <Link href={assignmentDetailUrl}>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="text-xs h-8 px-3 gap-1 hover:text-his hover:border-his/40"
|
|
>
|
|
<span>Details</span>
|
|
<ArrowRight className="w-3 h-3" />
|
|
</Button>
|
|
</Link> */}
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 text-muted-foreground hover:text-foreground rounded-full"
|
|
aria-label="Assignment actions menu"
|
|
>
|
|
<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>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|