mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Add ConvertedAssignmentBadge and IM conversion UI
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.
This commit is contained in:
@@ -17,6 +17,7 @@ import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText,
|
||||
import Link from 'next/link';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { formatAssignmentDate } from './AssignmentList';
|
||||
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
|
||||
|
||||
interface AssignmentGridProps {
|
||||
assignments: IProjectAssignment[];
|
||||
@@ -88,6 +89,7 @@ export default function AssignmentGrid({
|
||||
|
||||
{/* 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"
|
||||
@@ -103,11 +105,16 @@ export default function AssignmentGrid({
|
||||
{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>
|
||||
)}
|
||||
{/* 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>
|
||||
|
||||
@@ -207,6 +214,25 @@ export default function AssignmentGrid({
|
||||
</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">
|
||||
|
||||
@@ -15,6 +15,7 @@ import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex, ArrowUpRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
|
||||
|
||||
export const formatAssignmentDate = (dateStr?: string) => {
|
||||
if (!dateStr) return 'N/A';
|
||||
@@ -108,6 +109,8 @@ export default function AssignmentList({
|
||||
<span>{assignmentType}</span>
|
||||
</Badge>
|
||||
|
||||
<ConvertedAssignmentBadge assignment={assignment} clientId={effectiveClientId} />
|
||||
|
||||
{assignmentStatus && <BadgeStatus status={assignmentStatus} />}
|
||||
|
||||
{assignmentCode ? (
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
"use client";
|
||||
|
||||
import Link from 'next/link';
|
||||
import { IProjectAssignment } from '../../type.assignment';
|
||||
import {
|
||||
HoverCard,
|
||||
HoverCardTrigger,
|
||||
HoverCardContent,
|
||||
} from '@/components/ui/hover-card';
|
||||
import {
|
||||
FileText,
|
||||
ArrowUpRight,
|
||||
FolderGit2,
|
||||
Calendar,
|
||||
ArrowRight,
|
||||
} from 'lucide-react';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { formatAssignmentDate } from './AssignmentList';
|
||||
|
||||
interface ConvertedAssignmentBadgeProps {
|
||||
assignment: IProjectAssignment;
|
||||
clientId?: string | number;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function ConvertedAssignmentBadge({
|
||||
assignment,
|
||||
clientId,
|
||||
className = '',
|
||||
}: ConvertedAssignmentBadgeProps) {
|
||||
const isProject = !!assignment.wo_name;
|
||||
const effectiveClientId = clientId || assignment.client?.id;
|
||||
|
||||
// --- CASE 1: Project Assignment converted from an IM ---
|
||||
const isConvertedFromIM = Boolean(isProject && (assignment.im_id || assignment.im));
|
||||
const imData = assignment.im;
|
||||
const imId = assignment.im_id || imData?.id;
|
||||
const imName = imData?.im_name || assignment.im_name || 'Internal Memo';
|
||||
const imCode = imData?.im_code || assignment.im_code;
|
||||
const imStartDate = imData?.im_start_date || assignment.im_start_date;
|
||||
const imEndDate = imData?.im_end_date || assignment.im_end_date;
|
||||
const imDescription = imData?.im_description || assignment.im_description;
|
||||
const imDetailUrl = effectiveClientId && imId ? `/task/client-detail/${effectiveClientId}/${imId}` : null;
|
||||
|
||||
// --- CASE 2: IM Assignment that has been converted to 1 or more Projects ---
|
||||
const listWo = assignment.list_wo || [];
|
||||
const isConvertedIM = Boolean(!isProject && listWo.length > 0);
|
||||
|
||||
// If neither condition applies, render nothing
|
||||
if (!isConvertedFromIM && !isConvertedIM) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- RENDER CASE 1: Project Assignment converted from an IM ---
|
||||
if (isConvertedFromIM) {
|
||||
return (
|
||||
<HoverCard openDelay={120} closeDelay={150}>
|
||||
<HoverCardTrigger asChild>
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className={`inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-purple-500/10 text-purple-700 dark:text-purple-400 border border-purple-500/25 hover:bg-purple-500/20 hover:border-purple-500/40 transition-all cursor-pointer shrink-0 select-none ${className}`}
|
||||
>
|
||||
<ArrowUpRight className="w-3 h-3 text-purple-600 dark:text-purple-400 shrink-0" />
|
||||
<span>Converted from IM</span>
|
||||
</span>
|
||||
</HoverCardTrigger>
|
||||
|
||||
<HoverCardContent
|
||||
align="start"
|
||||
sideOffset={8}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="w-80 sm:w-92 p-0 shadow-2xl border-border/80 bg-popover/98 backdrop-blur-md rounded-xl overflow-hidden z-50 text-left"
|
||||
>
|
||||
{/* Header: Origin indicator & IM Code */}
|
||||
<div className="px-3.5 py-3 border-b border-border/60 bg-muted/20 flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5 text-purple-600 dark:text-purple-400">
|
||||
<FileText className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="text-[10px] font-mono font-semibold tracking-wider">
|
||||
Originating Memo
|
||||
</span>
|
||||
</div>
|
||||
{imCode && (
|
||||
<span className="text-[10px] font-mono font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground border border-border/60 shrink-0">
|
||||
#{imCode}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Body: Title, Period, and Description callout */}
|
||||
<div className="p-3.5 space-y-3">
|
||||
<div>
|
||||
<h4 className="text-sm font-semibold text-foreground leading-snug line-clamp-2 wrap-break-word">
|
||||
{imName}
|
||||
</h4>
|
||||
{(imStartDate || imEndDate) && (
|
||||
<p className="text-[11px] text-muted-foreground pt-1 flex items-center gap-1.5">
|
||||
<Calendar className="w-3 h-3 text-muted-foreground/70 shrink-0" />
|
||||
<span>
|
||||
{formatAssignmentDate(imStartDate)} – {formatAssignmentDate(imEndDate)}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{imDescription ? (
|
||||
<div className="border-l-2 border-purple-500/40 pl-2.5 py-0.5">
|
||||
<p className="text-xs text-muted-foreground leading-relaxed line-clamp-3 whitespace-pre-wrap">
|
||||
{imDescription}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Footer: Direct Navigation Action */}
|
||||
{imDetailUrl && (
|
||||
<div className="px-3.5 py-2.5 border-t border-border/60 bg-muted/30 flex items-center justify-end">
|
||||
<Link
|
||||
href={imDetailUrl}
|
||||
className="group inline-flex items-center gap-1 text-[11px] font-semibold text-his hover:text-his/90 transition-colors"
|
||||
>
|
||||
<span>View Internal Memo</span>
|
||||
<ArrowRight className="w-3 h-3 group-hover:translate-x-0.5 transition-transform" />
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</HoverCardContent>
|
||||
</HoverCard>
|
||||
);
|
||||
}
|
||||
|
||||
// --- RENDER CASE 2: IM Assignment that has been converted to Project(s) ---
|
||||
return (
|
||||
<HoverCard openDelay={120} closeDelay={150}>
|
||||
<HoverCardTrigger asChild>
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className={`inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border border-emerald-500/25 hover:bg-emerald-500/20 hover:border-emerald-500/40 transition-all cursor-pointer shrink-0 select-none ${className}`}
|
||||
>
|
||||
<FolderGit2 className="w-3 h-3 text-emerald-600 dark:text-emerald-400 shrink-0" />
|
||||
<span>
|
||||
Converted to {listWo.length} Project{listWo.length > 1 ? 's' : ''}
|
||||
</span>
|
||||
</span>
|
||||
</HoverCardTrigger>
|
||||
|
||||
<HoverCardContent
|
||||
align="start"
|
||||
sideOffset={8}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="w-88 sm:w-104 p-0 shadow-2xl border-border/80 bg-popover/98 backdrop-blur-md rounded-xl overflow-hidden z-50 text-left"
|
||||
>
|
||||
{/* Header: Title, Total Count, and Shortcut Hint */}
|
||||
<div className="px-4 py-3.5 border-b border-border/60 bg-muted/20 flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<FolderGit2 className="w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0" />
|
||||
<span className="text-[10px] font-mono font-semibold tracking-wider text-emerald-600 dark:text-emerald-400">
|
||||
Converted Work Orders
|
||||
</span>
|
||||
<span className="text-[10px] font-semibold px-1.5 py-0.2 rounded-full bg-emerald-500/15 text-emerald-700 dark:text-emerald-300 border border-emerald-500/25">
|
||||
{listWo.length}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground/70 hidden sm:inline select-none">
|
||||
Click row to open
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Body: High-craft flat row list (NO box-in-box nesting!) */}
|
||||
<div className="divide-y divide-border/40 max-h-72 overflow-y-auto">
|
||||
{listWo.map((woItem, i) => {
|
||||
const woDetailUrl = effectiveClientId && woItem.id ? `/task/client-detail/${effectiveClientId}/${woItem.id}` : null;
|
||||
const woTitle = woItem.wo_name || woItem.project?.name || 'Untitled Project';
|
||||
|
||||
const RowContent = (
|
||||
<div className="px-4 py-2.5 hover:bg-muted/50 dark:hover:bg-zinc-800/50 transition-colors group/row">
|
||||
{/* Top Line: Title, Code Tag, Arrow Cue */}
|
||||
<div className="flex items-center justify-between gap-2.5">
|
||||
<div className="min-w-0 flex-1 flex items-center gap-1.5">
|
||||
<span className="font-semibold text-xs text-foreground group-hover/row:text-his transition-colors truncate">
|
||||
{woTitle}
|
||||
</span>
|
||||
<ArrowUpRight className="w-3 h-3 text-muted-foreground/60 opacity-0 group-hover/row:opacity-100 group-hover/row:text-his transition-all shrink-0 -translate-x-0.5 group-hover/row:translate-x-0" />
|
||||
</div>
|
||||
|
||||
{woItem.project_assignment_status?.name && (
|
||||
<div className="shrink-0">
|
||||
<BadgeStatus status={woItem.project_assignment_status.name} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Bottom Line: Clean Schedule & Status Badge */}
|
||||
<div className="flex items-center justify-between gap-2 pt-1 text-[11px] text-muted-foreground">
|
||||
<div className="flex items-center gap-1.5 truncate">
|
||||
<Calendar className="w-3 h-3 text-muted-foreground/70 shrink-0" />
|
||||
<span className="truncate">
|
||||
{formatAssignmentDate(woItem.wo_start_date)} – {formatAssignmentDate(woItem.wo_end_date)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (woDetailUrl) {
|
||||
return (
|
||||
<Link
|
||||
key={woItem.id || i}
|
||||
href={woDetailUrl}
|
||||
className="block no-underline"
|
||||
>
|
||||
{RowContent}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={woItem.id || i}>
|
||||
{RowContent}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Footer: Quiet context summary */}
|
||||
<div className="px-4 py-3 border-t border-border/60 bg-muted/20 flex items-center justify-between text-[11px] text-muted-foreground/80">
|
||||
<span>Generated from this Internal Memo</span>
|
||||
<span className="font-mono text-[10px]">
|
||||
{listWo.length} {listWo.length === 1 ? 'assignment' : 'assignments'}
|
||||
</span>
|
||||
</div>
|
||||
</HoverCardContent>
|
||||
</HoverCard>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,16 @@ import { IUser } from "@/app/admin/administration/user/component/type"
|
||||
export interface IProjectAssignment {
|
||||
id: number
|
||||
im_id?: any
|
||||
im?: {
|
||||
id: number
|
||||
im_code?: string | null
|
||||
im_name?: string | null
|
||||
im_description?: string | null
|
||||
im_end_date?: string | null
|
||||
im_start_date?: string | null
|
||||
im_year?: any
|
||||
} | null
|
||||
list_wo?: IProjectAssignment[]
|
||||
im_code?: any
|
||||
im_description?: any
|
||||
im_end_date?: any
|
||||
|
||||
Reference in New Issue
Block a user