From c6aa1c912a29096fdc00e4bed70fd843f11323c5 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Tue, 13 Oct 2026 13:29:37 +0700 Subject: [PATCH] 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. --- .../project-assignment/AssignmentGrid.tsx | 36 ++- .../project-assignment/AssignmentList.tsx | 3 + .../ConvertedAssignmentBadge.tsx | 238 ++++++++++++++++++ app/(dashboard)/task/type.assignment.ts | 10 + 4 files changed, 282 insertions(+), 5 deletions(-) create mode 100644 app/(dashboard)/task/component/project-assignment/ConvertedAssignmentBadge.tsx diff --git a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx index 89b3d4f..b606adf 100644 --- a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx +++ b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx @@ -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 */}
+ {/* Row 1: Assignment Type and Status */}
}
- {assignmentCode && ( - - # {assignmentCode} - - )} + {/* Row 2: Assignment Code & Converted Indicator */} +
+ {assignmentCode && ( + + # {assignmentCode} + + )} + + +
@@ -207,6 +214,25 @@ export default function AssignmentGrid({ )} + {/* Origin IM Reference (for converted assignments without project) */} + {!assignment.project?.name && (assignment.im?.im_name || (assignment.im_id && assignment.im_name)) && ( +
+ + Origin IM: + {effectiveClientId && (assignment.im_id || assignment.im?.id) ? ( + + {assignment.im?.im_name || assignment.im_name} + + + ) : ( + {assignment.im?.im_name || assignment.im_name} + )} +
+ )} + {/* Description */} {assignmentDesc && (

diff --git a/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx b/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx index 445557d..3baed7b 100644 --- a/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx +++ b/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx @@ -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({ {assignmentType} + + {assignmentStatus && } {assignmentCode ? ( diff --git a/app/(dashboard)/task/component/project-assignment/ConvertedAssignmentBadge.tsx b/app/(dashboard)/task/component/project-assignment/ConvertedAssignmentBadge.tsx new file mode 100644 index 0000000..65d9f4a --- /dev/null +++ b/app/(dashboard)/task/component/project-assignment/ConvertedAssignmentBadge.tsx @@ -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 ( + + + 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}`} + > + + Converted from IM + + + + 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 */} +

+
+ + + Originating Memo + +
+ {imCode && ( + + #{imCode} + + )} +
+ + {/* Body: Title, Period, and Description callout */} +
+
+

+ {imName} +

+ {(imStartDate || imEndDate) && ( +

+ + + {formatAssignmentDate(imStartDate)} – {formatAssignmentDate(imEndDate)} + +

+ )} +
+ + {imDescription ? ( +
+

+ {imDescription} +

+
+ ) : null} +
+ + {/* Footer: Direct Navigation Action */} + {imDetailUrl && ( +
+ + View Internal Memo + + +
+ )} + + + ); + } + + // --- RENDER CASE 2: IM Assignment that has been converted to Project(s) --- + return ( + + + 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}`} + > + + + Converted to {listWo.length} Project{listWo.length > 1 ? 's' : ''} + + + + + 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 */} +
+
+ + + Converted Work Orders + + + {listWo.length} + +
+ + Click row to open + +
+ + {/* Body: High-craft flat row list (NO box-in-box nesting!) */} +
+ {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 = ( +
+ {/* Top Line: Title, Code Tag, Arrow Cue */} +
+
+ + {woTitle} + + +
+ + {woItem.project_assignment_status?.name && ( +
+ +
+ )} +
+ + {/* Bottom Line: Clean Schedule & Status Badge */} +
+
+ + + {formatAssignmentDate(woItem.wo_start_date)} – {formatAssignmentDate(woItem.wo_end_date)} + +
+
+
+ ); + + if (woDetailUrl) { + return ( + + {RowContent} + + ); + } + + return ( +
+ {RowContent} +
+ ); + })} +
+ + {/* Footer: Quiet context summary */} +
+ Generated from this Internal Memo + + {listWo.length} {listWo.length === 1 ? 'assignment' : 'assignments'} + +
+
+
+ ); +} diff --git a/app/(dashboard)/task/type.assignment.ts b/app/(dashboard)/task/type.assignment.ts index 82e7160..f32781f 100644 --- a/app/(dashboard)/task/type.assignment.ts +++ b/app/(dashboard)/task/type.assignment.ts @@ -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