From 3fbecab072ee58c30cb43f95d1a0b94cdcf66445 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Fri, 16 Oct 2026 15:37:20 +0700 Subject: [PATCH] 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. --- .../[assignment_id]/ActivityHistoryModal.tsx | 48 +- .../[assignment_id]/AddActivityLogModal.tsx | 267 +++++ .../AssignmentDetailComponent.tsx | 126 ++- .../DevelopmentActivityLog.tsx | 57 +- .../ProjectMilestoneTimeline.tsx | 976 ++++++++++-------- .../UpdateRealProgressModal.tsx | 210 ++++ .../[client_id]/[assignment_id]/page.tsx | 2 + app/(dashboard)/task/component/HomeTask.tsx | 8 +- .../client/ClientMilestoneTimeline.tsx | 2 +- app/(dashboard)/task/type.assignment.ts | 3 + .../task/utils/client-overview-helpers.ts | 10 +- components/ui/badge.tsx | 13 +- 12 files changed, 1255 insertions(+), 467 deletions(-) create mode 100644 app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AddActivityLogModal.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/UpdateRealProgressModal.tsx diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ActivityHistoryModal.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ActivityHistoryModal.tsx index cb52b66..3894ae0 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ActivityHistoryModal.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ActivityHistoryModal.tsx @@ -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 ( !isOpen && onClose()}> - + {/* Header */} - - - - Activity Log Details #{historyItem.id} - - + +
+ + + + + Activity Log Details #{historyItem.id} + + {historyItem.type && ( + + )} +
+ {historyItem.description} -
- By: {historyItem.user?.fullname || historyItem.user?.nickname || 'System'} +
+ By: {historyItem.user?.fullname || historyItem.user?.nickname || 'System'} · {dayjs(historyItem.created_at).format('DD MMM YYYY, HH:mm:ss')}
@@ -59,11 +69,11 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
{/* Old Data Panel */} -
-
+
+
Old Data
-
+
                                     {oldData !== null && oldData !== undefined
                                         ? JSON.stringify(oldData, null, 2)
@@ -73,11 +83,11 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
                         
{/* New Data Panel */} -
-
+
+
New Data
-
+
                                     {newData !== null && newData !== undefined
                                         ? JSON.stringify(newData, null, 2)
@@ -89,21 +99,21 @@ export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHis
                 
{/* Footer Actions */} -
+
diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AddActivityLogModal.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AddActivityLogModal.tsx new file mode 100644 index 0000000..2505623 --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AddActivityLogModal.tsx @@ -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('13'); + const [description, setDescription] = useState(''); + 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 ( + !isOpen && !isSubmitting && onClose()}> + + {/* Header */} +
+ + + + + + Add Activity Log + + + Record a manual development update, action, or note for{' '} + {assignmentName} + {assignmentCode && ( + + (#{assignmentCode}) + + )} + . + + +
+ + {/* Form Body */} +
+ {/* Activity Type Field with Badge */} +
+
+ + {isLoadingTypes && ( + + Loading types... + + )} +
+ + +
+ + {/* Description Field */} +
+
+ + + {description.length} / 1000 + +
+