diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx index 9723fc1..b6d0bac 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -11,6 +11,7 @@ import { useRouter, useSearchParams } from 'next/navigation'; import FilterComponent from '../../../component/FilterComponent'; import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput'; import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus'; +import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus'; import { ManageTeam } from '../../../component/ManageTeam'; import AssignmentGrid from '../../../component/project-assignment/AssignmentGrid'; import AssignmentList from '../../../component/project-assignment/AssignmentList'; @@ -26,7 +27,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro const urlLayout = searchParams?.get('layout') as 'grid' | 'list' | null; const [viewMode] = useState<'grid' | 'list'>(urlLayout || 'list'); - const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'DELETE' | undefined>(); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | 'DELETE' | undefined>(); const [selectedData, setSelectedData] = useState(); const activeLayout = urlLayout || viewMode; @@ -75,6 +76,10 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro setSelectedData(a); setAction('MANAGE_EMPLOYEE'); }} + onUpdateAdministrationStatus={(a) => { + setSelectedData(a); + setAction('UPDATE_ADMIN_STATUS'); + }} onUpdateStatus={(a) => { setSelectedData(a); setAction('UPDATE_STATUS'); @@ -92,6 +97,10 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro setSelectedData(a); setAction('MANAGE_EMPLOYEE'); }} + onUpdateAdministrationStatus={(a) => { + setSelectedData(a); + setAction('UPDATE_ADMIN_STATUS'); + }} onUpdateStatus={(a) => { setSelectedData(a); setAction('UPDATE_STATUS'); @@ -112,6 +121,18 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro /> ) : null} + {action === 'UPDATE_ADMIN_STATUS' && selectedData ? ( + { + router.refresh(); + handleClose(); + }} + /> + ) : null} + {action === 'UPDATE_STATUS' && selectedData ? ( ) : null} diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index 7446397..9d11605 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -12,9 +12,10 @@ import { useState, type ReactNode } from 'react'; import Link from 'next/link'; +import { useRouter } from 'next/navigation'; import dayjs from 'dayjs'; import { - ArrowLeft, Briefcase, Calendar, ChevronDown, Clock, ExternalLink, FileText, + ArrowLeft, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText, FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users, } from 'lucide-react'; import { Button } from '@/components/ui/button'; @@ -26,6 +27,7 @@ import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../. import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment'; import { ManageTeam } from '../../../component/ManageTeam'; import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus'; +import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus'; import Reveal from '@/components/ui/reveal'; interface Props { @@ -56,7 +58,8 @@ function formatSpan(start?: string | null, end?: string | null) { } export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) { - const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>(); + const router = useRouter(); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>(); const [showAllTeam, setShowAllTeam] = useState(false); const [teamView, setTeamView] = useState<'grid' | 'list'>('list'); @@ -142,13 +145,23 @@ export default function AssignmentDetail({ client, initialAssignment: assignment - +
+ + +
@@ -410,6 +423,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment + {action === 'UPDATE_ADMIN_STATUS' ? ( + { + router.refresh(); + handleClose(); + }} + /> + ) : null} + {action === 'UPDATE_STATUS' ? ( ) : null} diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx index 37fbdce..94ba271 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx @@ -5,6 +5,7 @@ import { motion, AnimatePresence, useReducedMotion } from 'motion/react'; import { Calendar, ChevronDown, + ClipboardCheck, History, IterationCcw, StickyNote, @@ -18,6 +19,7 @@ import AssignedPeople from './AssignedPeople'; import BadgeStatus from '@/components/ui/badge-status'; import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment'; import UpdateTimelineStatus from '@/app/(dashboard)/task/component/UpdateTechnicalStatus'; +import UpdateAdministrationStatus from '@/app/(dashboard)/task/component/UpdateAdministrationStatus'; import { ManageTeam } from '@/app/(dashboard)/task/component/ManageTeam'; import { cn } from '@/lib/utils'; import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data'; @@ -31,7 +33,7 @@ interface WorkOrderCardProps { export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) { const [isOpen, setIsOpen] = useState(defaultOpen); - const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>(); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>(); const [selectedData, setSelectedData] = useState(); const reduce = useReducedMotion(); @@ -231,18 +233,32 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: title="Assignment Timeline" badgeText={`${statusList.length} stages`} action={ - +
+ + +
} /> @@ -293,6 +309,14 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: {/* Modals */} + {action === 'UPDATE_ADMIN_STATUS' && selectedData ? ( + + ) : null} + {action === 'UPDATE_STATUS' && selectedData ? ( ) : null} diff --git a/app/(dashboard)/task/component/ManageTeam.tsx b/app/(dashboard)/task/component/ManageTeam.tsx index 5974b1a..e53c186 100644 --- a/app/(dashboard)/task/component/ManageTeam.tsx +++ b/app/(dashboard)/task/component/ManageTeam.tsx @@ -2,7 +2,8 @@ import { useState } from "react"; import { - Edit2, Trash2, Save, X, Loader2, UserPlus + Edit2, Trash2, Save, X, Loader2, UserPlus, + UserGroup } from "lucide-react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow @@ -114,182 +115,193 @@ export function ManageTeam({ assignmentId, onClose, startDate, endDate }: { assi return ( <> { if (!open) onClose(); }}> - -
- - Manage Team - - Add team members and manage who is working on each project assignment. - - - + +
+
+ + + + Manage Team + + + Add team members and manage who is working on each project assignment. + + + +
-
- - - - Name - Start Date - End Date - Status - Action - - - - {isLoading ? + +
+
+
+ - - - - - + Name + Start Date + End Date + Status + Action - : - existUserAssign.length === 0 ? + + + {isLoading ? - -
- No team members have been added yet.
Create a team to get started with project assignments - -
+ + + +
: - existUserAssign.map((row: IProjectAssignmentAssignUserDetail) => { - const isEditing = editingId === row.id; - const isOtherRowEditing = editingId !== null && editingId !== row.id; + existUserAssign.length === 0 ? + + +
+ No team members have been added yet.
Create a team to get started with project assignments + +
+
+
+ : + existUserAssign.map((row: IProjectAssignmentAssignUserDetail) => { + const isEditing = editingId === row.id; + const isOtherRowEditing = editingId !== null && editingId !== row.id; - return ( - - -
- - - {row.user.fullname?.charAt(0)} - -
-
- {row.user.fullname} - {row.user.position?.name} + return ( + + +
+ + + {row.user.fullname?.charAt(0)} + +
+
+ {row.user.fullname} + {row.user.position?.name} +
+ {row.user.email}
- {row.user.email}
-
- + - - {isEditing ? - handleDraftChange("start_date", date as any)} - disabledDate={(date: Date) => { - // const assStartDate = startDate - // const assEndDate = endDate - - // return assStartDate ? (date <= new Date(assStartDate) || date > new Date(assEndDate)) : false; - if (!startDate || !endDate) return false; - - // 1. Normalize all dates to midnight (00:00:00) to strip out time differences - const targetDate = new Date(date).setHours(0, 0, 0, 0); - const minDate = new Date(startDate).setHours(0, 0, 0, 0); - const maxDate = new Date(endDate).setHours(0, 0, 0, 0); - - // 2. Disable if strictly BEFORE (<) the start date, or strictly AFTER (>) the end date - return targetDate < minDate || targetDate > maxDate; - }} - /> - : - {row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''} - } - - - - {isEditing ? - handleDraftChange("end_date", date as any)} - disabledDate={(date: Date) => { - // 1. Normalize the calendar date we are currently checking - const targetDate = new Date(date).setHours(0, 0, 0, 0); - - const assStartDate = startDate; - const assEndDate = endDate; - const userStartDate = draftData.start_date; - - // 2. Check against the User's selected Start Date (if it exists) - if (userStartDate) { - const minUserDate = new Date(userStartDate).setHours(0, 0, 0, 0); - if (targetDate < minUserDate) return true; // Disable if before user's start date - } - - // 3. Check against the overall Assignment Start boundary (if it exists) - if (assStartDate) { - const minAssDate = new Date(assStartDate).setHours(0, 0, 0, 0); - if (targetDate < minAssDate) return true; // Disable if before assignment start limit - } - - // 4. Check against the overall Assignment End boundary (if it exists) - if (assEndDate) { - const maxAssDate = new Date(assEndDate).setHours(0, 0, 0, 0); - if (targetDate > maxAssDate) return true; // Disable if AFTER assignment end limit - } - - // If it passes all existing checks, it is a valid date! - return false; - }} - /> - : - {row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''} - } - - - - {isEditing ? - - : - {row.status} - } - - - -
+ {isEditing ? - <> - - - + handleDraftChange("start_date", date as any)} + disabledDate={(date: Date) => { + // const assStartDate = startDate + // const assEndDate = endDate + + // return assStartDate ? (date <= new Date(assStartDate) || date > new Date(assEndDate)) : false; + if (!startDate || !endDate) return false; + + // 1. Normalize all dates to midnight (00:00:00) to strip out time differences + const targetDate = new Date(date).setHours(0, 0, 0, 0); + const minDate = new Date(startDate).setHours(0, 0, 0, 0); + const maxDate = new Date(endDate).setHours(0, 0, 0, 0); + + // 2. Disable if strictly BEFORE (<) the start date, or strictly AFTER (>) the end date + return targetDate < minDate || targetDate > maxDate; + }} + /> : - !isOtherRowEditing && ( + {row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''} + } + + + + {isEditing ? + handleDraftChange("end_date", date as any)} + disabledDate={(date: Date) => { + // 1. Normalize the calendar date we are currently checking + const targetDate = new Date(date).setHours(0, 0, 0, 0); + + const assStartDate = startDate; + const assEndDate = endDate; + const userStartDate = draftData.start_date; + + // 2. Check against the User's selected Start Date (if it exists) + if (userStartDate) { + const minUserDate = new Date(userStartDate).setHours(0, 0, 0, 0); + if (targetDate < minUserDate) return true; // Disable if before user's start date + } + + // 3. Check against the overall Assignment Start boundary (if it exists) + if (assStartDate) { + const minAssDate = new Date(assStartDate).setHours(0, 0, 0, 0); + if (targetDate < minAssDate) return true; // Disable if before assignment start limit + } + + // 4. Check against the overall Assignment End boundary (if it exists) + if (assEndDate) { + const maxAssDate = new Date(assEndDate).setHours(0, 0, 0, 0); + if (targetDate > maxAssDate) return true; // Disable if AFTER assignment end limit + } + + // If it passes all existing checks, it is a valid date! + return false; + }} + /> + : + {row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''} + } + + + + {isEditing ? + + : + {row.status} + } + + + +
+ {isEditing ? <> - - - ) - } -
-
- - ); - }) - } - -
+ : + !isOtherRowEditing && ( + <> + + + + ) + } +
+ + + ); + }) + } + + +
+ + +
+ + +
- - -
diff --git a/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx b/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx new file mode 100644 index 0000000..00cdaa6 --- /dev/null +++ b/app/(dashboard)/task/component/UpdateAdministrationStatus.tsx @@ -0,0 +1,267 @@ +"use client"; + +import { useState, useEffect, useMemo, useTransition } from 'react'; +import { useRouter } from 'next/navigation'; +import { IProjectAssignment } from '../type.assignment'; +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 { ClipboardCheck, Loader2 } from 'lucide-react'; + +export interface IMasterStatus { + id: number; + name: string; + description?: string | null; + remark?: string | null; + type?: string; +} + + +interface UpdateAdministrationStatusProps { + assignmentId?: number; + assignment?: IProjectAssignment; + onClose: () => void; + onSuccess?: () => void; +} + +export default function UpdateAdministrationStatus({ + assignmentId: propAssignmentId, + assignment, + onClose, + onSuccess, +}: UpdateAdministrationStatusProps) { + const router = useRouter(); + const [isPending, startTransition] = useTransition(); + const [isSubmitting, setIsSubmitting] = useState(false); + + const effectiveId = propAssignmentId ?? assignment?.id; + const assignmentName = assignment?.wo_name || assignment?.im_name || assignment?.project?.name || (effectiveId ? `Assignment #${effectiveId}` : 'Project Assignment'); + const assignmentCode = assignment?.wo_code || assignment?.im_code || assignment?.project?.code; + + const { data: fetchedStatuses, isLoading: isLoadingStatuses } = useFetchWithAxios('/project-assignment-status?type=master'); + + const statusList: IMasterStatus[] = Array.isArray(fetchedStatuses) && fetchedStatuses.length > 0 ? fetchedStatuses : []; + + const initialStatusId = useMemo(() => { + if (assignment?.project_assignment_status?.id) { + return String(assignment.project_assignment_status.id); + } + + if ((assignment as any)?.project_assignment_status_id) { + return String((assignment as any).project_assignment_status_id); + } + + const currentName = assignment?.project_assignment_status?.name || (assignment as any)?.status?.name || (assignment as any)?.status; + + if (currentName && statusList.length > 0) { + const findStatus = statusList.find((s) => s.name?.toLowerCase().trim() === String(currentName).toLowerCase().trim()); + if (findStatus) return String(findStatus.id); + } + + if (statusList.length > 0 && statusList[0]?.id) { + return String(statusList[0].id); + } + + return ''; + }, [assignment, statusList]); + + const [selectedStatusId, setSelectedStatusId] = useState(initialStatusId); + const [description, setDescription] = useState(assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || ''); + + useEffect(() => { + if (initialStatusId) { + setSelectedStatusId(initialStatusId); + } + }, [initialStatusId]); + + useEffect(() => { + const initialRemark = assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || ''; + setDescription(initialRemark); + }, [assignment]); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!effectiveId) { + toast.error('Invalid assignment identifier'); + return; + } + + if (!selectedStatusId) { + toast.error('Please select an administrative status'); + return; + } + + setIsSubmitting(true); + try { + const payload = { + project_assignment_status_id: Number(selectedStatusId), + remark: description.trim(), + description: description.trim(), + note: description.trim(), + }; + + const res = await serverApiCall('PUT', `/project-assignment/status/${effectiveId}`, payload); + + if (res.success) { + toast.success('Administration status updated successfully'); + startTransition(() => { + router.refresh(); + }); + onSuccess?.(); + onClose(); + } else { + toast.error('Failed to update administration status', { + description: res.message || 'An unexpected error occurred.', + }); + } + } catch (err: any) { + toast.error('An error occurred while saving status', { + description: err?.message || 'Please try again later.', + }); + } finally { + setIsSubmitting(false); + } + }; + + const isBusy = isSubmitting || isPending; + + return ( + !open && !isBusy && onClose()}> + + {/* Modal Header */} +
+ + + + Update Administration Status + + + Update the overarching lifecycle stage and audit notes for{' '} + + {assignmentName} + + {assignmentCode && + + (# {assignmentCode}) + + } + . + + +
+ + {/* Form Body */} +
+ {/* Current Status Reference Card */} + {assignment?.project_assignment_status?.name && ( +
+ Current Status + +
+ )} + + {/* Status Select Field */} +
+
+ + {isLoadingStatuses && ( + + Loading options... + + )} +
+ + +
+ + {/* Description / Notes Field */} +
+
+ + + {description.length} / 500 + +
+