mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Propagate assignment dates to ManageTeam
Pass assignment start/end dates into ManageTeam and enforce them in the UI. Updated components (ClientDetailComponent, AssignmentDetailComponent(.old), WorkOrderCard) to provide startDate/endDate props. Modified ManageTeam signature to accept startDate/endDate, added dayjs import to format displayed dates, and implemented disabledDate logic on the DatePicker controls to prevent selecting dates outside the assignment boundaries (normalizing dates to midnight and checking against assignment and user-selected dates). Also removed a stray console.log in AssignmentDetailComponent.old and adjusted ProjectDetailPage to fetch project assignments via the filtered query string (added a console.log(project) for debugging). Files changed: ClientDetailComponent.tsx, AssignmentDetailComponent.old.tsx, AssignmentDetailComponent.tsx, WorkOrderCard.tsx, page.tsx, ManageTeam.tsx.
This commit is contained in:
@@ -347,7 +347,9 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose} />
|
||||
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose}
|
||||
startDate={selectedData?.wo_start_date || selectedData?.im_start_date} endDate={selectedData?.wo_end_date || selectedData?.im_end_date}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -46,8 +46,6 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
setAction(undefined)
|
||||
}
|
||||
|
||||
console.log(assignment)
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.div
|
||||
@@ -237,7 +235,10 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageTeam assignmentId={assignment.id} onClose={handleClose} />
|
||||
<ManageTeam
|
||||
assignmentId={assignment.id} onClose={handleClose}
|
||||
startDate={assignment.wo_start_date || assignment.im_start_date} endDate={assignment.wo_end_date || assignment.im_end_date}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
+4
-1
@@ -219,7 +219,10 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageTeam assignmentId={assignment.id} onClose={handleClose} />
|
||||
<ManageTeam
|
||||
assignmentId={assignment.id} onClose={handleClose}
|
||||
startDate={assignment.wo_start_date || assignment.im_start_date} endDate={assignment.wo_end_date || assignment.im_end_date}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
+3
-1
@@ -142,7 +142,9 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose} />
|
||||
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose}
|
||||
startDate={selectedData?.wo_start_date || selectedData?.im_start_date} endDate={selectedData?.wo_end_date || selectedData?.im_end_date}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<number | null>(null);
|
||||
const [draftData, setDraftData] = useState<Partial<any>>({});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
@@ -178,17 +179,63 @@ export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, on
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.start_date as Date | undefined} setDate={(date) => handleDraftChange("start_date", date as any)} />
|
||||
<DatePicker date={draftData.start_date as Date | undefined} setDate={(date) => 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;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<span className="text-sm">{row.start_date}</span>
|
||||
<span className="text-sm">{row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.end_date as Date | undefined} setDate={(date) => handleDraftChange("end_date", date as any)} />
|
||||
<DatePicker date={draftData.end_date as Date | undefined} setDate={(date) => 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;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<span className="text-sm">{row.end_date}</span>
|
||||
<span className="text-sm">{row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user