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 ecdef01..796e014 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -347,7 +347,9 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro } {action === 'MANAGE_EMPLOYEE' ? - + : null } diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.old.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.old.tsx index 73a4edc..b36d52e 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.old.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.old.tsx @@ -46,8 +46,6 @@ export default function AssignmentDetail({ client, initialAssignment: assignment setAction(undefined) } - console.log(assignment) - return ( <> + : 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 41cee88..4beb224 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 @@ -219,7 +219,10 @@ export default function AssignmentDetail({ client, initialAssignment: assignment } {action === 'MANAGE_EMPLOYEE' ? - + : 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 087fd5d..8c20bd8 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 @@ -142,7 +142,9 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP } {action === 'MANAGE_EMPLOYEE' ? - + : null } diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx index a9ab918..b538b13 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx @@ -28,10 +28,11 @@ export default async function ProjectDetailPage({ params, searchParams }: Props) const queryString = getQueryStringFilteredAssignments(searchParams_) const getClientById = fetchData(`/client/${client_id}`) - // const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`) - const getAssignmentByProjectId = fetchData(`/project/${project_id}`) + const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`) + // const getAssignmentByProjectId = fetchData(`/project/${project_id}`) const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]); + console.log(project) // 3. Handle 404 Securely on the server if (!project) { diff --git a/app/(dashboard)/task/component/ManageTeam.tsx b/app/(dashboard)/task/component/ManageTeam.tsx index ad646c4..cb1f881 100644 --- a/app/(dashboard)/task/component/ManageTeam.tsx +++ b/app/(dashboard)/task/component/ManageTeam.tsx @@ -24,6 +24,7 @@ import { ConfirmDelete } from "@/components/modal/ConfirmDelete"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { serverApiCall } from "@/lib/server-api"; +import dayjs from "dayjs"; export interface IProjectAssignmentAssignUserDetail { @@ -48,7 +49,7 @@ export interface Position { -export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, onClose: VoidFunction }) { +export function ManageTeam({ assignmentId, onClose, startDate, endDate }: { assignmentId: number, onClose: VoidFunction, startDate?: any, endDate?: any }) { const [editingId, setEditingId] = useState(null); const [draftData, setDraftData] = useState>({}); const [isSaving, setIsSaving] = useState(false); @@ -178,17 +179,63 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on {isEditing ? - handleDraftChange("start_date", date as any)} /> + 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} + {row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''} } {isEditing ? - handleDraftChange("end_date", date as any)} /> + 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} + {row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''} }