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.
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-5 border-border/80 rounded-2xl bg-card gap-4">
|
|
{/* Top Section: 3D Emblem, Badges, and Action Menu */}
|
|
<div className="flex items-start justify-between gap-3">
|
|
<div className="flex items-center gap-3.5 min-w-0">
|
|
{/* 3D App Icon / Emblem */}
|
|
<Link
|
|
href={assignmentDetailUrl}
|
|
className="relative w-14 h-14 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">
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
<Badge
|
|
variant="outline"
|
|
className={`text-[10px] font-semibold tracking-wide px-2 py-0.5 gap-1 ${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="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">
|
|
# {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">
|
|
{/* 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"
|
|
>
|
|
{assignmentName}
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Project Reference */}
|
|
{assignment.project?.name && (
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-0.5">
|
|
<FolderGit2 className="w-3.5 h-3.5 text-his shrink-0" />
|
|
<span className="text-[11px] text-muted-foreground">Project:</span>
|
|
{projectDetailUrl ? (
|
|
<Link
|
|
href={projectDetailUrl}
|
|
className="font-medium text-foreground hover:text-his truncate hover:underline flex items-center gap-1"
|
|
>
|
|
<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">{assignment.project.name}</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Description */}
|
|
{assignmentDesc && (
|
|
<p className="text-xs text-muted-foreground line-clamp-2 leading-relaxed pt-0.5">
|
|
{assignmentDesc}
|
|
</p>
|
|
)}
|
|
|
|
{/* Client & End User Badges */}
|
|
<div className="flex flex-wrap items-center gap-2 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]"
|
|
>
|
|
{assignment.client.photo ?
|
|
<LazyImage
|
|
src={assignment.client.photo}
|
|
alt={assignment.client.name}
|
|
className="w-3 h-3 rounded-xs bg-transparent"
|
|
imgClassName="object-cover"
|
|
/>
|
|
:
|
|
<BuildingComplex className="w-3 h-3 text-muted-foreground" />
|
|
}
|
|
<span className="text-muted-foreground">Client:</span>
|
|
<span className="font-medium truncate max-w-50">{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]">
|
|
<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">End User:</span>
|
|
<span className="font-medium truncate max-w-50">{assignment.end_user.name}</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Footer: Timeline & Team Members */}
|
|
<div className="pt-3.5 border-t border-border/60 flex items-center justify-between gap-3 text-xs">
|
|
<div className="flex items-center gap-1.5 text-muted-foreground">
|
|
<Calendar className="w-3.5 h-3.5 shrink-0 text-muted-foreground/80" />
|
|
<span className="font-medium text-[11px]">
|
|
{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>
|
|
);
|
|
}
|