Add assignment progress and activity logging

Add modals for updating real progress and recording activity logs, and enhance the milestone timeline with date-based positioning and activity details. Update dashboard metrics to show active internal memos.
This commit is contained in:
Ichsan Kurniawan
2026-10-16 15:37:20 +07:00
parent f2e9136e47
commit 3fbecab072
12 changed files with 1255 additions and 467 deletions
@@ -8,6 +8,8 @@ import { Check, Copy, FileText } from 'lucide-react';
import dayjs from 'dayjs';
import { DialogDescription } from '@radix-ui/react-dialog';
import BadgeStatus from '@/components/ui/badge-status';
interface ActivityHistoryModalProps {
historyItem: IProjectAssignmentHistory | null;
open: boolean;
@@ -27,6 +29,7 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
id: historyItem.id,
description: historyItem.description,
created_at: historyItem.created_at,
type: historyItem.type,
user: historyItem.user,
old_data: oldData,
new_data: newData,
@@ -38,18 +41,25 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
return (
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
<DialogContent className="sm:max-w-4xl max-h-[90vh] sm:max-h-[90vh] flex flex-col p-6 bg-zinc-950 border border-zinc-800 text-zinc-100 rounded-xl shadow-2xl">
<DialogContent className="sm:max-w-4xl max-h-[90vh] sm:max-h-[95vh] flex flex-col p-6 bg-card border border-border/80 rounded-2xl shadow-2xl">
{/* Header */}
<DialogHeader className="space-y-1 pb-4 border-b border-zinc-800">
<DialogTitle className="flex items-center gap-2">
<FileText className="h-5 w-5 text-his" />
Activity Log Details #{historyItem.id}
</DialogTitle>
<DialogDescription className="text-xs text-zinc-400 leading-relaxed">
<DialogHeader className="space-y-1.5 pb-4 border-b border-border/70 dark:border-zinc-800">
<div className="flex items-center justify-between gap-3">
<DialogTitle className="flex items-center gap-2.5 font-bold text-foreground dark:text-zinc-100">
<span className="flex h-8 w-8 items-center justify-center rounded-xl bg-his/10 text-his">
<FileText className="h-4 w-4" />
</span>
Activity Log Details #{historyItem.id}
</DialogTitle>
{historyItem.type && (
<BadgeStatus status={historyItem.type} />
)}
</div>
<DialogDescription className="text-sm text-muted-foreground leading-relaxed">
{historyItem.description}
</DialogDescription>
<div className="flex items-center gap-3 pt-1 text-[11px] font-mono">
<span>By: {historyItem.user?.fullname || historyItem.user?.nickname || 'System'}</span>
<div className="flex items-center gap-3 pt-1 text-[11px] font-mono text-muted-foreground">
<span>By: <span className="font-semibold text-foreground dark:text-zinc-200">{historyItem.user?.fullname || historyItem.user?.nickname || 'System'}</span></span>
<span>·</span>
<span>{dayjs(historyItem.created_at).format('DD MMM YYYY, HH:mm:ss')}</span>
</div>
@@ -59,11 +69,11 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
<div className="flex-1 overflow-y-auto py-4 space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Old Data Panel */}
<div className="flex flex-col rounded-lg border border-zinc-800 bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2 border-b border-zinc-800 bg-zinc-900 text-xs font-mono font-medium text-zinc-400">
<div className="flex flex-col rounded-xl border border-border/70 bg-muted/20 dark:border-zinc-800 dark:bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2.5 border-b border-border/70 bg-muted/50 dark:border-zinc-800 dark:bg-zinc-900 text-xs font-mono font-semibold text-muted-foreground dark:text-zinc-400">
Old Data
</div>
<div className="p-3.5 font-mono text-xs text-zinc-300 max-h-[50vh] overflow-auto">
<div className="p-3.5 font-mono text-xs text-foreground/90 dark:text-zinc-300 max-h-[50vh] overflow-auto">
<pre className="whitespace-pre-wrap">
{oldData !== null && oldData !== undefined
? JSON.stringify(oldData, null, 2)
@@ -73,11 +83,11 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
</div>
{/* New Data Panel */}
<div className="flex flex-col rounded-lg border border-zinc-800 bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2 border-b border-zinc-800 bg-zinc-900 text-xs font-mono font-medium text-zinc-400">
<div className="flex flex-col rounded-xl border border-border/70 bg-muted/20 dark:border-zinc-800 dark:bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2.5 border-b border-border/70 bg-muted/50 dark:border-zinc-800 dark:bg-zinc-900 text-xs font-mono font-semibold text-muted-foreground dark:text-zinc-400">
New Data
</div>
<div className="p-3.5 font-mono text-xs text-zinc-300 max-h-[50vh] overflow-auto">
<div className="p-3.5 font-mono text-xs text-foreground/90 dark:text-zinc-300 max-h-[50vh] overflow-auto">
<pre className="whitespace-pre-wrap">
{newData !== null && newData !== undefined
? JSON.stringify(newData, null, 2)
@@ -89,21 +99,21 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
</div>
{/* Footer Actions */}
<div className="pt-4 border-t border-zinc-800 flex items-center justify-between">
<div className="pt-4 border-t border-border/70 dark:border-zinc-800 flex items-center justify-between">
<Button
variant="outline"
size="sm"
onClick={copyFullJson}
className="gap-1.5 text-xs border-zinc-700 bg-zinc-900 hover:bg-zinc-800 text-zinc-300"
className="gap-1.5 text-xs border-border/80 hover:bg-muted font-medium text-foreground dark:border-zinc-700 dark:bg-zinc-900 dark:hover:bg-zinc-800 dark:text-zinc-300"
>
{copied ? <Check className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5" />}
{copied ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
<span>{copied ? 'Copied' : 'Copy JSON'}</span>
</Button>
<Button
variant="default"
size="sm"
onClick={onClose}
className="text-xs bg-zinc-800 hover:bg-zinc-700 text-zinc-100"
className="text-xs bg-zinc-900 hover:bg-zinc-800 text-zinc-50 dark:bg-zinc-800 dark:hover:bg-zinc-700 dark:text-zinc-100"
>
Close
</Button>
@@ -0,0 +1,267 @@
"use client";
import { useState, useMemo } from 'react';
import { useRouter } from 'next/navigation';
import { useFetchWithAxios } from '@/lib/axios/useFetch';
import { serverApiCall } from '@/lib/server-api';
import { toast } from 'sonner';
import {
Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
} from '@/components/ui/select';
import BadgeStatus from '@/components/ui/badge-status';
import { FilePlus2, Loader2, Save } from 'lucide-react';
export interface IActivityLogType {
id: number;
name: string;
description?: string | null;
remark?: string | null;
type?: string;
}
const FALLBACK_LOG_TYPES: IActivityLogType[] = [
{ id: 13, name: 'update', description: 'General update on assignment progress', type: 'log' },
{ id: 14, name: 'action', description: 'Action item completed or undertaken', type: 'log' },
{ id: 15, name: 'issue', description: 'Blocker, bug, or risk encountered', type: 'log' },
{ id: 16, name: 'system', description: 'System or administrative event', type: 'log' },
];
interface AddActivityLogModalProps {
assignmentId: number;
assignmentName?: string;
assignmentCode?: string;
open: boolean;
onClose: () => void;
onSuccess?: () => void;
}
export default function AddActivityLogModal({
assignmentId,
assignmentName = 'Project Assignment',
assignmentCode,
open,
onClose,
onSuccess,
}: AddActivityLogModalProps) {
const router = useRouter();
const [selectedTypeId, setSelectedTypeId] = useState<string>('13');
const [description, setDescription] = useState<string>('');
const [isSubmitting, setIsSubmitting] = useState(false);
// Fetch types from GET v1/project-assignment-status?type=log
const { data: fetchedData, isLoading: isLoadingTypes } = useFetchWithAxios(
open ? '/project-assignment-status?type=log' : null
);
const logTypes: IActivityLogType[] = useMemo(() => {
if (Array.isArray(fetchedData) && fetchedData.length > 0) {
return fetchedData;
}
if (fetchedData && Array.isArray((fetchedData as any)?.data) && (fetchedData as any).data.length > 0) {
return (fetchedData as any).data;
}
return FALLBACK_LOG_TYPES;
}, [fetchedData]);
const activeType = useMemo(() => {
return logTypes.find((t) => String(t.id) === selectedTypeId) || logTypes[0];
}, [logTypes, selectedTypeId]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!assignmentId) {
toast.error('Invalid assignment ID');
return;
}
if (!description.trim()) {
toast.error('Description is required', {
description: 'Please describe the activity, update, or action taken.',
});
return;
}
setIsSubmitting(true);
const typeName = activeType?.name || 'update';
const payload = {
project_assignment_id: Number(assignmentId),
type: typeName,
project_assignment_status_id: activeType?.id ? Number(activeType.id) : undefined,
description: description.trim(),
};
// Try primary endpoint POST /project-assignment/history
let res = await serverApiCall('POST', '/project-assignment/history', payload);
// Fallback endpoint if 404
if (!res.success && res.message?.includes('404')) {
res = await serverApiCall('POST', `/project-assignment/${assignmentId}/history`, payload);
}
setIsSubmitting(false);
if (res.success) {
toast.success('Activity log added successfully', {
description: `Recorded "${typeName}" log for this assignment.`,
});
setDescription('');
onClose();
if (onSuccess) {
onSuccess();
} else {
router.refresh();
}
} else {
toast.error('Failed to add activity log', {
description: res.message || 'An unexpected error occurred while saving the log.',
});
}
};
return (
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && !isSubmitting && onClose()}>
<DialogContent className="sm:max-w-lg p-0 overflow-hidden border border-border/80 bg-card text-foreground rounded-2xl shadow-2xl">
{/* Header */}
<div className="border-b border-border/70 bg-muted/40 px-6 py-5">
<DialogHeader className="space-y-1.5 text-left">
<DialogTitle className="flex items-center gap-2.5 font-bold text-foreground">
<span className="flex h-8 w-8 items-center justify-center rounded-xl bg-his/10 text-his">
<FilePlus2 className="h-4 w-4" />
</span>
Add Activity Log
</DialogTitle>
<DialogDescription className="text-muted-foreground leading-relaxed">
Record a manual development update, action, or note for{' '}
<span className="font-semibold text-foreground">{assignmentName}</span>
{assignmentCode && (
<span className="ml-1 font-mono text-muted-foreground">
(#{assignmentCode})
</span>
)}
.
</DialogDescription>
</DialogHeader>
</div>
{/* Form Body */}
<form onSubmit={handleSubmit} className="space-y-5 px-6 pb-5 pt-0">
{/* Activity Type Field with Badge */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="log-type-select" className="text-xs font-semibold text-foreground">
Activity Type <span className="text-destructive">*</span>
</Label>
{isLoadingTypes && (
<span className="text-[11px] text-muted-foreground flex items-center gap-1 font-mono">
<Loader2 className="h-3 w-3 animate-spin" /> Loading types...
</span>
)}
</div>
<Select
value={selectedTypeId}
onValueChange={setSelectedTypeId}
disabled={isSubmitting}
>
<SelectTrigger id="log-type-select" className="w-full h-10 text-sm">
<SelectValue placeholder="Select activity type">
{activeType && (
<div className="flex items-center justify-between gap-3 w-full pr-2">
<span className="capitalize font-medium">{activeType.name}</span>
<BadgeStatus status={activeType.name} />
</div>
)}
</SelectValue>
</SelectTrigger>
<SelectContent>
{logTypes.map((type) => (
<SelectItem
key={type.id}
value={String(type.id)}
className="py-2.5 cursor-pointer"
>
<div className="flex items-center justify-between gap-4 w-full">
<div className="flex flex-col text-left">
<span className="font-medium text-foreground capitalize text-xs">
{type.name}
</span>
{type.description && type.description !== type.name && (
<span className="text-[11px] text-muted-foreground line-clamp-1">
{type.description}
</span>
)}
</div>
<BadgeStatus status={type.name} />
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* Description Field */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="log-description" className="text-xs font-semibold text-foreground">
Description <span className="text-destructive">*</span>
</Label>
<span className="text-[11px] text-muted-foreground font-mono">
{description.length} / 1000
</span>
</div>
<Textarea
id="log-description"
value={description}
onChange={(e) => setDescription(e.target.value.slice(0, 1000))}
placeholder="Detail the activity, bug fix, deployment action, or task completed..."
rows={4}
required
disabled={isSubmitting}
className="text-xs leading-relaxed resize-none"
/>
<p className="text-[11px] text-muted-foreground leading-normal">
This activity entry will appear in the Development Activity Log history timeline.
</p>
</div>
{/* Footer Actions */}
<DialogFooter className="gap-2 pt-2 border-t border-border/70">
<Button
type="button"
variant="outline"
onClick={onClose}
disabled={isSubmitting}
className="text-xs"
>
Cancel
</Button>
<Button
type="submit"
disabled={isSubmitting || !description.trim()}
className="text-xs gap-1.5 bg-his hover:bg-his/90 text-white font-medium shadow-md shadow-his/20"
>
{isSubmitting ? (
<>
<Loader2 className="h-3.5 w-3.5 animate-spin" />
Saving...
</>
) : (
<>
<Save className="h-3.5 w-3.5" />
Save Activity
</>
)}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -6,7 +6,7 @@ import { useRouter } from 'next/navigation';
import dayjs from 'dayjs';
import {
ArrowLeft, ArrowUpRight, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText,
FolderGit2, LayoutGrid, List, Mail, Phone, UserPlus, Users,
FolderGit2, Gauge, LayoutGrid, List, Mail, Pencil, Phone, UserPlus, Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card900 } from '@/components/ui/card';
@@ -59,6 +59,11 @@ const UpdateTechnicalStatus = dynamic(
{ ssr: false, loading: () => <ModalActionLoader /> }
);
const UpdateRealProgressModal = dynamic(
() => import('./UpdateRealProgressModal'),
{ ssr: false, loading: () => <ModalActionLoader /> }
);
interface Props {
client: IClient | undefined;
initialAssignment: IProjectAssignment;
@@ -82,15 +87,13 @@ function formatSpan(start?: string | null, end?: string | null) {
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
const router = useRouter();
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>();
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | 'UPDATE_REAL_PROGRESS' | undefined>();
const [showAllTeam, setShowAllTeam] = useState(false);
const [teamView, setTeamView] = useState<'grid' | 'list'>('list');
const isWorkOrder = !!assignment.wo_name;
const assignmentType = isWorkOrder ? 'Work Order' : 'Internal Memo';
const illustrationSrc = isWorkOrder
? '/assets/illustrations/work_order.jpg'
: '/assets/illustrations/internal_memo.jpg';
const illustrationSrc = isWorkOrder ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
const assignmentName = assignment.wo_name || assignment.im_name || 'Untitled Assignment';
const assignmentCode = assignment.wo_code || assignment.im_code;
@@ -132,7 +135,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
className="group inline-flex items-center gap-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
<ArrowLeft className="h-4 w-4 transition-transform duration-300 group-hover:-translate-x-0.5" />
<span>Back to: {owner?.name ?? 'PT. TELEKOMUNIKASI SELULAR'}</span>
<span>Back to: {owner?.name ?? '---'}</span>
</Link>
</Reveal>
@@ -186,7 +189,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
{/* Assignment Description */}
{assignmentDesc ? (
<p className="max-w-[70ch] text-sm leading-relaxed text-muted-foreground wrap-break-word">
<p className="w-full text-sm leading-relaxed text-muted-foreground wrap-break-word">
{assignmentDesc}
</p>
) : null}
@@ -194,6 +197,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</div>
{/* Action Buttons: Keep Promote to Project (if IM), Update Technical Status, Update Admin Status */}
{/* Action Buttons: Administration & Technical status (+ Promote if IM) */}
<div className="flex flex-wrap sm:flex-nowrap items-center gap-2.5 w-full md:w-auto shrink-0">
{!isWorkOrder && (
<Button
@@ -225,30 +229,91 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</div>
</div>
{/* Progress Project Bar */}
<div className="space-y-2">
<div className="flex items-center justify-between gap-4">
<span className="text-xs font-semibold text-foreground tracking-wide">
Progress Project
</span>
<div className="flex items-center gap-3 flex-1 max-w-3xl">
{/* Progress Section: Side-by-Side Real Progress & Days Elapsed */}
<div className="space-y-3 pt-2">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* 1. Real Progress Card */}
<div className="rounded-xl border border-border/70 bg-muted/20 p-3.5 space-y-2.5">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2">
<span className="flex h-6 w-6 items-center justify-center rounded-lg bg-his/10 text-his">
<Gauge className="h-3.5 w-3.5" />
</span>
<span className="text-xs font-semibold text-foreground tracking-wide">
Real Progress
</span>
<span className="text-[10px] font-mono font-medium text-his bg-his/10 px-1.5 py-0.5 rounded">
Actual Work
</span>
</div>
{/* Percentage & Trigger Button next to Real Progress */}
<div className="flex items-center gap-2">
<span className="font-mono text-sm font-extrabold text-foreground">
{assignment.progress ?? 0}%
</span>
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setAction('UPDATE_REAL_PROGRESS')}
className="h-6.5 px-2 text-[11px] font-medium hover:border-his/40 hover:bg-his hover:text-white transition-all shadow-2xs gap-1"
title="Update real progress and notes"
>
<Pencil className="size-3" />
<span>Update</span>
</Button>
</div>
</div>
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
<div
className="h-full rounded-full transition-all duration-700 ease-out bg-his"
style={{
width: `${Math.min(100, Math.max(0, assignment.progress ?? 0))}%`,
boxShadow: `0 0 10px rgba(234, 81, 44, 0.45)`,
}}
/>
</div>
</div>
{/* 2. Days Elapsed Card */}
<div className="rounded-xl border border-border/70 bg-muted/20 p-3.5 space-y-2.5">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2">
<span className="flex h-6 w-6 items-center justify-center rounded-lg bg-muted text-muted-foreground">
<Clock className="h-3.5 w-3.5" />
</span>
<span className="text-xs font-semibold text-muted-foreground tracking-wide">
Days Elapsed
</span>
<span className="text-[10px] font-mono text-muted-foreground bg-muted/60 px-1.5 py-0.5 rounded">
Timeline
</span>
</div>
<div className="flex items-center gap-2">
<span className="font-mono text-sm font-bold text-foreground">
{overview.progressPercent}%
</span>
<span className="font-mono text-[11px] text-muted-foreground">
({remainingText})
</span>
</div>
</div>
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
<div
className="h-full rounded-full transition-all duration-700 ease-out"
style={{
width: `${overview.progressPercent}%`,
backgroundColor: overview.progressColor.hex,
boxShadow: `0 0 10px ${overview.progressColor.hex}88`,
boxShadow: `0 0 8px ${overview.progressColor.hex}66`,
}}
/>
</div>
<span className="font-mono text-sm font-bold text-foreground shrink-0 w-10 text-right">
{overview.progressPercent}%
</span>
</div>
</div>
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground pt-1">
{/* Timeline Date Range & Total Days */}
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground pt-0.5 px-0.5">
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 shrink-0 cursor-help hover:text-foreground transition-colors">
@@ -296,7 +361,13 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
{/* 3. Development Activity Log (with pagination & clean modal) */}
<Reveal delay={0.12}>
<DevelopmentActivityLog history={assignment.project_assignment_history} />
<DevelopmentActivityLog
history={assignment.project_assignment_history}
assignmentId={assignment.id}
assignmentName={assignmentName}
assignmentCode={assignmentCode}
onLogAdded={() => router.refresh()}
/>
</Reveal>
{/* 4. Client and End User + Project in 2-Column Grid (Preserving exact original card style) */}
@@ -545,6 +616,21 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
endDate={assignment.wo_end_date || assignment.im_end_date}
/>
) : null}
{action === 'UPDATE_REAL_PROGRESS' ? (
<UpdateRealProgressModal
assignmentId={assignment.id}
assignmentName={assignmentName}
assignmentCode={assignmentCode}
currentProgress={assignment.progress}
open={action === 'UPDATE_REAL_PROGRESS'}
onClose={handleClose}
onSuccess={() => {
router.refresh();
handleClose();
}}
/>
) : null}
</>
);
}
@@ -3,8 +3,9 @@
import { useState } from 'react';
import dynamic from 'next/dynamic';
import { IProjectAssignmentHistory } from '../../../type.assignment';
import { FileText, ChevronRight, ChevronLeft, History } from 'lucide-react';
import { FileText, ChevronRight, ChevronLeft, History, Plus } from 'lucide-react';
import { Button } from '@/components/ui/button';
import BadgeStatus from '@/components/ui/badge-status';
import dayjs from 'dayjs';
const ActivityHistoryModal = dynamic(
@@ -12,12 +13,28 @@ const ActivityHistoryModal = dynamic(
{ ssr: false }
);
const AddActivityLogModal = dynamic(
() => import('./AddActivityLogModal'),
{ ssr: false }
);
interface DevelopmentActivityLogProps {
history?: IProjectAssignmentHistory[];
assignmentId?: number;
assignmentName?: string;
assignmentCode?: string;
onLogAdded?: () => void;
}
export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogProps) {
export function DevelopmentActivityLog({
history = [],
assignmentId,
assignmentName,
assignmentCode,
onLogAdded,
}: DevelopmentActivityLogProps) {
const [selectedItem, setSelectedItem] = useState<IProjectAssignmentHistory | null>(null);
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage, setItemsPerPage] = useState(5);
@@ -57,7 +74,7 @@ export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogP
return (
<>
<section className="rounded-2xl border border-border/80 bg-card p-5 sm:p-6 transition-all duration-200">
<div className="mb-4 flex items-center justify-between gap-3">
<div className="mb-4 flex items-center justify-between gap-3 flex-wrap">
<h2 className="flex items-center gap-2.5 text-base font-semibold tracking-tight text-foreground">
<span className="flex h-7 w-7 items-center justify-center rounded-lg bg-muted text-muted-foreground">
<FileText className="h-4 w-4" />
@@ -69,6 +86,18 @@ export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogP
</span>
)}
</h2>
{assignmentId && (
<Button
type="button"
size="sm"
onClick={() => setIsAddModalOpen(true)}
className="h-8 gap-1.5 bg-his hover:bg-his/90 text-white font-medium text-xs shadow-xs transition-transform active:scale-[0.98]"
>
<Plus className="h-3.5 w-3.5" />
<span>Add Activity Log</span>
</Button>
)}
</div>
{totalItems === 0 ? (
@@ -114,8 +143,14 @@ export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogP
</div>
</td>
{/* Type Column: Left blank per instruction */}
<td className="py-3.5 px-4 text-muted-foreground/40 font-mono"></td>
{/* Type Column with BadgeStatus */}
<td className="py-3.5 px-4 whitespace-nowrap">
{item.type ? (
<BadgeStatus status={item.type} />
) : (
<span className="text-muted-foreground/40 text-[11px] font-mono">—</span>
)}
</td>
{/* Description Column */}
<td className="py-3.5 px-4 text-foreground/90 font-normal leading-relaxed group-hover:text-foreground transition-colors">
@@ -217,6 +252,18 @@ export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogP
open={!!selectedItem}
onClose={() => setSelectedItem(null)}
/>
{/* Modal for adding manual activity log */}
{assignmentId && (
<AddActivityLogModal
assignmentId={assignmentId}
assignmentName={assignmentName}
assignmentCode={assignmentCode}
open={isAddModalOpen}
onClose={() => setIsAddModalOpen(false)}
onSuccess={onLogAdded}
/>
)}
</>
);
}
@@ -0,0 +1,210 @@
"use client";
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { serverApiCall } from '@/lib/server-api';
import { toast } from 'sonner';
import {
Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { Gauge, Loader2, Save } from 'lucide-react';
interface UpdateRealProgressModalProps {
assignmentId: number;
assignmentName: string;
assignmentCode?: string;
currentProgress?: number | null;
open: boolean;
onClose: () => void;
onSuccess?: () => void;
}
export default function UpdateRealProgressModal({
assignmentId,
assignmentName,
assignmentCode,
currentProgress = 0,
open,
onClose,
onSuccess,
}: UpdateRealProgressModalProps) {
const router = useRouter();
const initialVal = typeof currentProgress === 'number' && !isNaN(currentProgress)
? Math.min(100, Math.max(0, currentProgress))
: 0;
const [progress, setProgress] = useState<number>(initialVal);
const [description, setDescription] = useState<string>('');
const [isSaving, setIsSaving] = useState(false);
const presetValues = [0, 25, 50, 75, 100];
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!assignmentId) {
toast.error('Invalid assignment ID');
return;
}
setIsSaving(true);
const payload = {
project_assignment_id: Number(assignmentId),
progress: Number(progress),
description: description.trim(),
};
const res = await serverApiCall('PUT', `/project-assignment/progress/${assignmentId}`, payload);
setIsSaving(false);
if (res.success) {
toast.success('Real progress updated successfully', {
description: `Progress updated to ${progress}%`,
});
onClose();
if (onSuccess) {
onSuccess();
} else {
router.refresh();
}
} else {
toast.error('Failed to update progress', {
description: res.message || 'An unexpected error occurred',
});
}
};
return (
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && !isSaving && onClose()}>
<DialogContent className="sm:max-w-lg p-0 overflow-hidden border border-border/80 bg-card rounded-2xl shadow-2xl">
{/* Header */}
<div className="border-b border-border/70 bg-muted/40 px-6 py-5">
<DialogHeader className="space-y-1.5 text-left">
<DialogTitle className="flex items-center gap-2.5 font-bold text-foreground">
<span className="flex h-8 w-8 items-center justify-center rounded-xl bg-his/10 text-his">
<Gauge className="h-4 w-4" />
</span>
Update Real Progress
</DialogTitle>
<DialogDescription className="text-muted-foreground leading-relaxed">
Set the current completion percentage and notes for{' '}
<span className="font-semibold text-foreground">{assignmentName}</span>
{assignmentCode && (
<span className="ml-1 font-mono text-muted-foreground">
(#{assignmentCode})
</span>
)}
.
</DialogDescription>
</DialogHeader>
</div>
{/* Form Body */}
<form onSubmit={handleSubmit} className="space-y-5 px-6 py-5">
{/* Draggable Progress Control */}
<div className="space-y-3 rounded-xl border border-border/70 bg-muted/20 p-4">
<div className="flex items-center justify-between">
<Label htmlFor="progress-slider" className="text-xs font-semibold text-foreground">
Completion Percentage
</Label>
<div className="flex items-center gap-1.5 font-mono">
<span className="text-2xl font-extrabold text-primary tracking-tight">
{progress}%
</span>
</div>
</div>
{/* Interactive Range Slider */}
<div className="relative py-2">
<input
id="progress-slider"
type="range"
min={0}
max={100}
step={1}
value={progress}
onChange={(e) => setProgress(Number(e.target.value))}
disabled={isSaving}
className="w-full h-2.5 bg-zinc-200 dark:bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-his focus:outline-none focus:ring-2 focus:ring-his/30 transition-all"
/>
</div>
{/* Quick Presets */}
<div className="flex items-center justify-between gap-1 pt-1">
{presetValues.map((val) => (
<button
key={val}
type="button"
onClick={() => setProgress(val)}
disabled={isSaving}
className={`px-2.5 py-1 text-[11px] font-mono rounded-md border transition-all ${progress === val
? 'bg-his text-white border-his font-bold shadow-xs'
: 'bg-background hover:bg-muted text-muted-foreground border-border/70 hover:text-foreground'
}`}
>
{val}%
</button>
))}
</div>
</div>
{/* Description Field */}
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="progress-description" className="text-xs font-semibold text-foreground">
Progress Notes / Description
</Label>
<span className="text-[11px] text-muted-foreground font-mono">
{description.length} / 500
</span>
</div>
<Textarea
id="progress-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Describe current achievements, modules completed, or status notes..."
rows={3}
maxLength={500}
disabled={isSaving}
className="text-xs resize-none"
/>
</div>
{/* Footer Actions */}
<DialogFooter className="gap-2 pt-2 border-t border-border/70">
<Button
type="button"
variant="outline"
onClick={onClose}
disabled={isSaving}
className="text-xs"
>
Cancel
</Button>
<Button
type="submit"
disabled={isSaving}
className="text-xs gap-1.5 bg-his hover:bg-his/90 text-white font-medium shadow-md shadow-his/20"
>
{isSaving ? (
<>
<Loader2 className="h-3.5 w-3.5 animate-spin" />
Saving...
</>
) : (
<>
<Save className="h-3.5 w-3.5" />
Save Progress
</>
)}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -15,6 +15,8 @@ export default async function AssignmentDetailPage({ params }: Props) {
const [client, assignment] = await Promise.all([getClientById, getAssignmentById]);
console.log(assignment)
// 3. Handle 404 Securely on the server
if (!assignment) {
return (
+4 -4
View File
@@ -2,7 +2,7 @@
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Plus, Building2, FolderGit2, Users, FileText, TrendingUp } from 'lucide-react';
import { Plus, Building2, FolderGit2, FileText, ClipboardClock } from 'lucide-react';
import { motion } from 'motion/react';
import { Button } from '@/components/ui/button';
import { Card900 } from '@/components/ui/card';
@@ -35,9 +35,9 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) {
trend: stats.projectsTrend,
},
{
title: 'Assigned Personnel',
value: stats.assignedPersonnel,
icon: Users,
title: 'Active Internal Memos',
value: stats.activeInternalMemos,
icon: ClipboardClock,
trend: stats.personnelTrend,
},
{
@@ -200,7 +200,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl
{/* If no milestones in range, show gentle notice */}
{!hasAgendas && (
<div className="absolute inset-0 flex items-center justify-center pointer-events-none">
<span className={`text-[10px] text-muted-foreground/70 italic ${!isGrid ? 'mt-6' : 'mt-18'} select-none whitespace-nowrap`}>
<span className={`text-[10px] text-muted-foreground/70 italic ${!isGrid ? 'mt-8' : 'mt-18'} select-none whitespace-nowrap`}>
No upcoming milestones in the next 2 months
</span>
</div>
+3
View File
@@ -32,6 +32,8 @@ export interface IProjectAssignment {
wo_start_date: string
wo_end_date?: string
wo_warranty: any
progress?: number | null
file_bast?: string | null
project_assignment_status_detail: ProjectAssignmentStatusDetail[]
project_assignment_work_order_detail: ProjectAssignmentWorkOrderDetail[]
project_assignment_history?: IProjectAssignmentHistory[]
@@ -43,6 +45,7 @@ export interface IProjectAssignmentHistory {
id: number
project_assignment_id: number
description: string
type?: string | null
old_data: any
new_data: any
created_at: string
@@ -23,7 +23,7 @@ export interface Milestone {
export interface OverviewStats {
totalClients: number;
activeProjects: number;
assignedPersonnel: number;
activeInternalMemos: number;
activeWorkOrders: number;
projectsTrend: string;
personnelTrend: string;
@@ -37,14 +37,14 @@ export interface OverviewStats {
export function calculateOverviewStats(clients: IClient[]): OverviewStats {
const totalClients = clients.length;
const realProjects = clients.reduce((sum, c) => sum + (c.total_project || 0), 0);
const realPersonnel = clients.reduce((sum, c) => sum + (c.total_user_assigned || c.users?.length || 0), 0);
const realInternalMemos = clients.reduce((sum, c) => sum + (c.total_im || 0), 0);
const realWorkOrders = clients.reduce((sum, c) => sum + (c.total_work_order || 0), 0);
return {
totalClients: totalClients || 8,
activeProjects: realProjects > 0 ? realProjects : 37,
assignedPersonnel: realPersonnel > 0 ? realPersonnel : 72,
activeWorkOrders: realWorkOrders > 0 ? realWorkOrders : 28,
activeProjects: realProjects > 0 ? realProjects : 0,
activeInternalMemos: realInternalMemos > 0 ? realInternalMemos : 0,
activeWorkOrders: realWorkOrders > 0 ? realWorkOrders : 0,
projectsTrend: '+19%',
personnelTrend: '+14%',
workOrdersTrend: '+27%',
+12 -1
View File
@@ -53,6 +53,12 @@ const badgeVariants = cva(
techGoLive: "border-transparent text-white bg-cyan-400 dark:bg-cyan-600 hover:opacity-85", // Green
techBAST: "border-transparent text-white bg-violet-400 dark:bg-violet-600 hover:opacity-85", // Yellow / Amber (BAST)
techWarranty: "border-transparent text-white bg-fuchsia-400 dark:bg-fuchsia-600 hover:opacity-85", // Sky Blue
// --- ACTIVITY LOG TYPE VARIANTS ---
logUpdate: "border-transparent bg-sky-500 text-white dark:bg-sky-600 hover:opacity-85",
logAction: "border-transparent bg-emerald-500 text-white dark:bg-emerald-600 hover:opacity-85",
logIssue: "border-transparent bg-red-500 text-white dark:bg-red-600 hover:opacity-85",
logSystem: "border-transparent text-white bg-his hover:opacity-85",
},
},
defaultVariants: {
@@ -83,7 +89,7 @@ export const STATUS_BADGE_MAP: Record<string, VariantProps<typeof badgeVariants>
"cancelled": "adminCancelled",
"canceled": "adminCancelled",
"cancel": "adminCancelled",
"issue": "adminCancelled",
"issue": "logIssue",
// 5. Completed -> Emerald Green
"completed": "adminCompleted",
@@ -91,6 +97,11 @@ export const STATUS_BADGE_MAP: Record<string, VariantProps<typeof badgeVariants>
"done": "adminCompleted",
"success": "adminCompleted",
// 6. Activity Log Types
"update": "logUpdate",
"action": "logAction",
"system": "logSystem",
// Technical progression stages based on color reference:
// 1. Development -> Orange
"development": "techDevelopment",