Align technical status schedules and UI

This commit updates the technical status flow to support the newer `data` payload format while preserving legacy `date` handling across timelines, overview helpers, and assignment detail views. It also adds per-interval descriptions for date ranges, improves schedule editing/deletion UX, and refreshes status badge colors and default work-order/client fallback values for a more consistent experience.
This commit is contained in:
Ichsan Kurniawan
2026-10-15 13:23:51 +07:00
parent e8818bc234
commit e7c6f1b17b
11 changed files with 160 additions and 111 deletions
@@ -30,6 +30,7 @@ export default async function ClientDetailPage({ params, searchParams }: Props)
const [client, assignmentList] = await Promise.all([getClientById, getAssignmentsByClient]);
console.log(assignmentList)
if (!client) {
return (
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
@@ -17,8 +17,9 @@ interface ProjectMilestoneTimelineProps {
function formatDetailDate(detail?: ProjectAssignmentStatusDetail | null): string {
if (!detail) return '';
if (Array.isArray(detail.date) && detail.date.length > 0) {
const validDates = detail.date.filter((d) => Boolean(d?.start_date || d?.end_date));
const dateArray = Array.isArray(detail.data) ? detail.data : Array.isArray(detail.date) ? detail.date : null;
if (dateArray && dateArray.length > 0) {
const validDates = dateArray.filter((d) => Boolean(d?.start_date || d?.end_date));
if (validDates.length > 0) {
const first = validDates[0];
const last = validDates[validDates.length - 1];
@@ -96,8 +97,9 @@ export function ProjectMilestoneTimeline({
const devDates = useMemo(() => {
const list: string[] = [];
if (devDetail) {
if (Array.isArray(devDetail.date) && devDetail.date.length > 0) {
devDetail.date.forEach((item) => {
const dateArray = Array.isArray(devDetail.data) ? devDetail.data : Array.isArray(devDetail.date) ? devDetail.date : null;
if (dateArray && dateArray.length > 0) {
dateArray.forEach((item) => {
if (item?.start_date && dayjs(item.start_date).isValid()) {
const f = dayjs(item.start_date).format('D MMM YYYY');
if (!list.includes(f)) list.push(f);
@@ -15,6 +15,7 @@ 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 (
@@ -103,7 +103,7 @@ export default function ProjectAssignmentForm(
description: '',
workOrder: {
name: '',
code: '',
code: 'WO-01',
description: '',
}
},
@@ -115,7 +115,7 @@ export default function ProjectAssignmentForm(
const { data: clientList, mutate: mutateClientList } = useFetchWithAxios('/client')
const { data: endUserList, mutate: mutateEndUserList } = useFetchWithAxios('/end-user')
const { data: projectList, mutate: mutateProjectList } = useFetchWithAxios(`/client/project/${formValues.client_id}`)
const { data: projectList } = useFetchWithAxios(`/client/project/${formValues.client_id}`)
// Sync work order name when "Same as Project Name" is enabled
useEffect(() => {
@@ -333,8 +333,11 @@ export default function ProjectAssignmentForm(
async function getWOCode() {
const res = await serverApiCall('GET', `/project-assignment/project-sequences?project_id=${isExistProject?.id}`)
if (res.success) form.setValue('workOrder.code' as any, String((res.data as any)?.data))
else form.setValue('workOrder.code' as any, "")
if (res.success) {
const squence = (res.data as any)?.data > 9 ? `WO-${(res.data as any)?.data}` : `WO-0${(res.data as any)?.data}`
form.setValue('workOrder.code' as any, squence)
}
else form.setValue('workOrder.code' as any, "WO-01")
}
getWOCode();
@@ -631,7 +634,7 @@ export default function ProjectAssignmentForm(
setOpenProjectSearch(false);
setIsExistProject(p);
toast.info(`Autofilled details from ${p.name}`, { duration: 1500 });
toast.info(`Autofilled details from ${p.name}`, { duration: 1200 });
}}
className="cursor-pointer py-2.5 px-3"
>
@@ -702,7 +705,7 @@ export default function ProjectAssignmentForm(
setOpenProjectSearch(false);
setIsExistProject(p);
toast.info(`Switched project to ${p.name}`, { duration: 1500 });
toast.info(`Switched project to ${p.name}`, { duration: 1200 });
}}
className="cursor-pointer py-2.5 px-3"
>
@@ -929,9 +932,6 @@ export default function ProjectAssignmentForm(
<FormLabel className="text-sm font-semibold text-foreground">
WO Code
</FormLabel>
<span className="text-[11px] text-muted-foreground font-mono">
Prefix: <strong className="text-foreground">{projectCode}-</strong>
</span>
</div>
<FormControl>
<InputGroup>
@@ -64,7 +64,7 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
setAction(undefined);
};
const statusList = workOrder.project_assignment_status_detail?.filter(status => Boolean(status.start_date || (Array.isArray(status.date) && status.date.length > 0))) || [];
const statusList = workOrder.project_assignment_status_detail?.filter(status => Boolean(status.start_date || (Array.isArray(status.data) && status.data.length > 0) || (Array.isArray(status.date) && status.date.length > 0))) || [];
const team = workOrder.project_assignment_work_order_detail ?? [];
const span = formatSpan(workOrder.wo_start_date, workOrder.wo_end_date);
const shownAvatars = team.slice(0, 4);
@@ -34,6 +34,7 @@ import dayjs from 'dayjs';
export interface IDateInterval {
start_date: string;
end_date: string;
description?: string;
}
export interface IProjectAssignmentTimeline {
@@ -41,6 +42,7 @@ export interface IProjectAssignmentTimeline {
start_date: string | null;
end_date: string | null;
date?: IDateInterval[] | string | null;
data?: IDateInterval[] | string | null;
description?: string | null;
updated_at?: string | null;
project_assignment_status: ProjectAssignmentStatus;
@@ -81,7 +83,7 @@ interface ModalState {
function extractDatesFromRow(row: any): IDateInterval[] {
if (!row) return [];
let rawDate = row.date;
let rawDate = row.data ?? row.date;
if (typeof rawDate === 'string') {
try {
rawDate = JSON.parse(rawDate);
@@ -95,7 +97,12 @@ function extractDatesFromRow(row: any): IDateInterval[] {
.filter(Boolean)
.map((item: any) => ({
start_date: item?.start_date ? dayjs(item.start_date).format('YYYY-MM-DD') : '',
end_date: item?.end_date ? dayjs(item.end_date).format('YYYY-MM-DD') : ''
end_date: item?.end_date ? dayjs(item.end_date).format('YYYY-MM-DD') : '',
description: typeof item?.description === 'string'
? item.description.trim()
: typeof row.description === 'string'
? row.description.trim()
: '',
}))
.filter((d: IDateInterval) => Boolean(d.start_date || d.end_date));
}
@@ -103,7 +110,8 @@ function extractDatesFromRow(row: any): IDateInterval[] {
if (row.start_date || row.end_date) {
return [{
start_date: row.start_date ? dayjs(row.start_date).format('YYYY-MM-DD') : '',
end_date: row.end_date ? dayjs(row.end_date).format('YYYY-MM-DD') : ''
end_date: row.end_date ? dayjs(row.end_date).format('YYYY-MM-DD') : '',
description: typeof row.description === 'string' ? row.description.trim() : '',
}];
}
@@ -154,6 +162,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
const newInterval: IDateInterval = {
start_date: startDate ? dayjs(startDate).format('YYYY-MM-DD') : '',
end_date: endDate ? dayjs(endDate).format('YYYY-MM-DD') : '',
description: description.trim(),
};
// Retain all existing dates and append the new one
finalDates.push(newInterval);
@@ -161,6 +170,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
const updatedInterval: IDateInterval = {
start_date: startDate ? dayjs(startDate).format('YYYY-MM-DD') : '',
end_date: endDate ? dayjs(endDate).format('YYYY-MM-DD') : '',
description: description.trim(),
};
// Update only the targeted date, preserve all other existing dates
finalDates = finalDates.map((item, idx) =>
@@ -171,8 +181,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
const submitPayload = {
project_assignment_technical_status_id: Number(data.technicalId),
project_assignment_status_detail_id: Number(data.detailId),
date: finalDates,
description: description.trim()
data: finalDates,
};
const res = await serverApiCall('PUT', `/project-assignment/technical-status/${assignmentId}`, submitPayload);
@@ -192,8 +201,8 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
const modalTitle = data.mode === 'ADD' ? 'Add Schedule' : 'Edit Schedule';
const modalDescription = data.mode === 'ADD'
? `Add a new schedule interval for ${data.statusName}. Previously recorded dates will be retained.`
: `Update the selected schedule interval and deliverable notes.`;
? `Add a new schedule interval and description for ${data.statusName}. Previously recorded dates will be retained.`
: `Update the selected schedule interval and description.`;
return (
<Dialog open={true} onOpenChange={(open) => { if (!open && !isSaving) onClose(); }}>
@@ -209,20 +218,27 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
<div className="space-y-4 py-2">
{/* Show existing dates overview when adding */}
{data.existingDates.length > 0 && data.mode === 'ADD' && (
<div className="rounded-md border border-border/60 bg-muted/30 p-2.5 space-y-1.5">
<div className="rounded-md border border-border/60 bg-muted/30 p-2.5 space-y-2">
<div className="flex items-center justify-between text-xs text-muted-foreground font-medium">
<span>Existing Schedules ({data.existingDates.length})</span>
<span className="text-[11px] text-his font-normal">+1 new interval will be added</span>
</div>
<div className="flex flex-wrap gap-1.5">
<div className="space-y-1.5 max-h-36 overflow-y-auto pr-0.5">
{data.existingDates.map((item, idx) => (
<span
<div
key={idx}
className="inline-flex items-center gap-1.5 px-2 py-0.5 rounded text-[11px] font-mono border border-border/60 bg-background text-muted-foreground"
className="p-1.5 rounded text-xs border border-border/60 bg-background text-muted-foreground space-y-0.5"
>
<Calendar className="size-3 text-muted-foreground/70" />
{dayjs(item.start_date).format('DD MMM YYYY')} – {dayjs(item.end_date).format('DD MMM YYYY')}
</span>
<div className="flex items-center gap-1.5 font-mono text-foreground font-medium text-[11px]">
<Calendar className="size-3 text-muted-foreground/70" />
{dayjs(item.start_date).format('DD MMM YYYY')} – {dayjs(item.end_date).format('DD MMM YYYY')}
</div>
{item.description && (
<p className="text-[11px] text-muted-foreground line-clamp-1 italic pl-4.5">
"{item.description}"
</p>
)}
</div>
))}
</div>
</div>
@@ -263,7 +279,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
<div className="space-y-1.5">
<div className="flex items-center justify-between">
<label className="text-xs font-medium text-foreground">
Description & Progress Notes
Description & Progress Notes for this Interval
</label>
<span className="text-[11px] text-muted-foreground">{description.length}/500</span>
</div>
@@ -272,9 +288,12 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
onChange={(e) => setDescription(e.target.value)}
maxLength={500}
rows={3}
placeholder="Deliverable summary or progress notes..."
placeholder="Deskripsi kegiatan atau milestone untuk interval tanggal ini..."
className="text-sm resize-none"
/>
<p className="text-[11px] text-muted-foreground">
Deskripsi ini khusus berlaku untuk rentang tanggal di atas.
</p>
</div>
</div>
@@ -384,7 +403,7 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
existingDates: item.dates,
initialStartDate: undefined,
initialEndDate: undefined,
initialDescription: item.description
initialDescription: '',
});
};
@@ -400,7 +419,7 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
editIndex: dateIndex,
initialStartDate: targetDate?.start_date ? new Date(targetDate.start_date) : undefined,
initialEndDate: targetDate?.end_date ? new Date(targetDate.end_date) : undefined,
initialDescription: item.description
initialDescription: targetDate?.description || '',
});
};
@@ -412,14 +431,11 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
setIsDeleting(true);
const remainingDates = item.dates.filter((_, idx) => idx !== removeIndex);
// If the remaining dates are empty (last date removed), also clear the description
const finalDescription = remainingDates.length === 0 ? '' : item.description.trim();
const submitPayload = {
project_assignment_technical_status_id: Number(item.technicalId),
project_assignment_status_detail_id: Number(item.detailId),
date: remainingDates,
description: finalDescription
data: remainingDates,
};
const res = await serverApiCall('PUT', `/project-assignment/technical-status/${assignmentId}`,
@@ -429,11 +445,7 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
setIsDeleting(false);
if (res.success) {
toast.success(
remainingDates.length === 0
? 'Schedule interval and notes removed'
: 'Schedule interval removed'
);
toast.success('Schedule interval removed');
setDeleteTarget(null);
mutate();
router.refresh();
@@ -505,53 +517,79 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
<TableCell className="align-top py-3">
<div className="space-y-2">
{hasDates ? (
<div className="space-y-1.5">
{item.dates.map((dateEntry, idx) => {
const start = dateEntry.start_date ? dayjs(dateEntry.start_date) : null;
const end = dateEntry.end_date ? dayjs(dateEntry.end_date) : null;
const spanDays = start && end ? end.diff(start, 'day') + 1 : null;
<div className="space-y-2">
{[...item.dates]
.map((dateEntry, originalIndex) => ({ dateEntry, originalIndex }))
.sort((a, b) => {
const timeA = a.dateEntry.start_date ? dayjs(a.dateEntry.start_date).valueOf() : 0;
const timeB = b.dateEntry.start_date ? dayjs(b.dateEntry.start_date).valueOf() : 0;
return timeA - timeB;
})
.map(({ dateEntry, originalIndex }, idx) => {
const start = dateEntry.start_date ? dayjs(dateEntry.start_date) : null;
const end = dateEntry.end_date ? dayjs(dateEntry.end_date) : null;
const spanDays = start && end ? end.diff(start, 'day') + 1 : null;
return (
<div
key={idx}
className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-2 rounded-md bg-muted/30 border border-border/60 hover:bg-muted/40 transition-colors"
>
<div className="flex items-center gap-2 font-mono text-xs text-foreground min-w-0">
<Calendar className="size-3.5 text-his shrink-0" />
<span className="font-medium">
{start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'}
</span>
{spanDays !== null && (
<span className="font-sans text-[11px] text-muted-foreground">
({spanDays} {spanDays === 1 ? 'day' : 'days'})
</span>
return (
<div
key={idx}
className="p-2.5 rounded-lg bg-muted/30 border border-border/70 hover:bg-muted/40 transition-colors space-y-2"
>
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<div className="flex items-center gap-2 font-mono text-xs text-foreground min-w-0">
<Calendar className="size-3.5 text-his shrink-0" />
<span className="font-semibold">
{start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'}
</span>
{spanDays !== null && (
<span className="font-sans text-[11px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-normal">
({spanDays} {spanDays === 1 ? 'day' : 'days'})
</span>
)}
</div>
<div className="flex items-center gap-1 shrink-0 self-end sm:self-center">
<Button
variant="outline"
size="sm"
className="h-7 w-7 p-0 text-teal-600 hover:text-teal-700 hover:bg-teal-50 dark:hover:bg-teal-950/40"
onClick={() => handleEditExistingDate(item, originalIndex)}
title="Edit schedule & description"
>
<Edit2 className="size-3.5" />
</Button>
<Button
variant="outline"
size="sm"
className="h-7 w-7 p-0 text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/40"
onClick={() => setDeleteTarget({ item, index: originalIndex, dateEntry })}
title="Delete this schedule"
>
<Trash2 className="size-3.5" />
</Button>
</div>
</div>
{/* Individual date description */}
{dateEntry.description ? (
<div className="rounded border border-border/50 bg-background/80 px-2.5 py-1.5 text-xs text-muted-foreground leading-relaxed wrap-break-word">
<span className="text-foreground/80 font-medium">Note: </span>
{dateEntry.description}
</div>
) : (
<div className="text-[11px] text-muted-foreground/60 italic pl-0.5">
No description provided for this date.
</div>
)}
</div>
<div className="flex items-center gap-1 shrink-0 self-end sm:self-center">
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEditExistingDate(item, idx)}>
<Edit2 className="size-3.5" />
</Button>
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeleteTarget({ item, index: idx, dateEntry })}>
<Trash2 className="size-3.5" />
</Button>
</div>
</div>
);
})}
);
})}
</div>
) : (
<span className="text-xs text-muted-foreground/70 italic py-1 block">
No dates scheduled
</span>
)}
{/* Description / Notes Display */}
{item.description ? (
<div className="rounded-md border border-border/40 bg-muted/20 px-2.5 py-1.5 text-xs text-muted-foreground leading-relaxed wrap-break-word italic">
"{item.description}"
</div>
) : null}
</div>
</TableCell>
@@ -605,21 +643,21 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
<AlertDialogHeader>
<AlertDialogTitle className="flex items-center gap-2 text-destructive">
<Trash2 className="size-4" />
Delete Schedule Interval
Delete Schedule
</AlertDialogTitle>
<AlertDialogDescription className="space-y-2 pt-1 text-left">
{deleteTarget && (
<>
<span>
Are you sure you want to delete the schedule interval{' '}
Are you sure you want to delete the schedule{' '}
<strong className="font-mono text-foreground">
{deleteTarget.dateEntry.start_date ? dayjs(deleteTarget.dateEntry.start_date).format('DD MMM YYYY') : 'TBD'} – {deleteTarget.dateEntry.end_date ? dayjs(deleteTarget.dateEntry.end_date).format('DD MMM YYYY') : 'Present'}
</strong>{' '}
from <strong className="text-foreground">{deleteTarget.item.statusName}</strong>?
</span>
{deleteTarget.item.dates.length === 1 && (
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-700 dark:text-amber-400 mt-3">
<strong>Note:</strong> This is the last remaining schedule for this status. Deleting it will also remove the description and progress notes.
{deleteTarget.dateEntry.description && (
<div className="rounded-md border border-border/60 bg-muted/40 p-2 text-xs text-muted-foreground italic mt-2">
"{deleteTarget.dateEntry.description}"
</div>
)}
</>
@@ -35,9 +35,9 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
const milestones = getClientMilestones(client);
const activeMilestone = milestones[1] || milestones[0];
const totalProjects = client.total_project ?? 6;
const assignedPeople = client.total_user_assigned || client.users?.length || 14;
const activeWorkOrders = client.total_work_order ?? 5;
const totalProjects = client.total_project ?? 0;
const assignedPeople = client.total_user_assigned || client.users?.length || 0;
const activeWorkOrders = client.total_work_order ?? 0;
// Pick top stages with activity (or top 3)
const topStages = stages.filter((s) => s.count > 0).slice(0, 7);
@@ -35,9 +35,9 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
const milestones = getClientMilestones(client);
const maxStageCount = Math.max(...stages.map((s) => s.count), 1);
const totalProjects = client.total_project ?? 6;
const assignedPeople = client.total_user_assigned || client.users?.length || 14;
const activeWorkOrders = client.total_work_order ?? 5;
const totalProjects = client.total_project ?? 0;
const assignedPeople = client.total_user_assigned || client.users?.length || 0;
const activeWorkOrders = client.total_work_order ?? 0;
return (
<motion.div
+2 -1
View File
@@ -93,7 +93,8 @@ export interface ProjectAssignmentStatusDetail {
end_date?: string | null
start_date?: string | null
updated_at?: string | null
date?: Array<{ start_date?: string; end_date?: string }> | string | null
date?: Array<{ start_date?: string; end_date?: string; description?: string }> | string | null
data?: Array<{ start_date?: string; end_date?: string; description?: string }> | string | null
description?: string | null
project_assignment_status: ProjectAssignmentStatus
}
@@ -161,10 +161,12 @@ export function formatRelativeTime(dateStr?: string): string {
export const hasAssignedDates = (d: any): boolean => {
if (!d) return false;
if (d.start_date || d.end_date) return true;
if (Array.isArray(d.date) && d.date.length > 0) {
return d.date.some((item: any) => Boolean(item?.start_date || item?.end_date));
const dateArray = Array.isArray(d.data) ? d.data : Array.isArray(d.date) ? d.date : null;
if (dateArray && dateArray.length > 0) {
return dateArray.some((item: any) => Boolean(item?.start_date || item?.end_date));
}
if (typeof d.date === 'string' && d.date.trim().length > 0) return true;
if (typeof d.data === 'string' && d.data.trim().length > 0) return true;
return false;
};
@@ -232,15 +234,18 @@ export function resolveProjectStatus(assignment: IProjectAssignment, indexFallba
activeDetail = d;
break;
}
} else if (Array.isArray(d.date)) {
const matchInterval = d.date.some((item: any) => {
const s = item?.start_date ? new Date(item.start_date).getTime() : null;
const e = item?.end_date ? new Date(item.end_date).getTime() : null;
return s && e && now >= s && now <= e;
});
if (matchInterval) {
activeDetail = d;
break;
} else {
const dateArray = Array.isArray(d.data) ? d.data : Array.isArray(d.date) ? d.date : null;
if (dateArray) {
const matchInterval = dateArray.some((item: any) => {
const s = item?.start_date ? new Date(item.start_date).getTime() : null;
const e = item?.end_date ? new Date(item.end_date).getTime() : null;
return s && e && now >= s && now <= e;
});
if (matchInterval) {
activeDetail = d;
break;
}
}
}
}
@@ -408,8 +413,9 @@ export function getPtrEndDate(assignment: IProjectAssignment): number | null {
latestTime = parseTime(ptrDetail.end_date);
}
if (Array.isArray(ptrDetail.date) && ptrDetail.date.length > 0) {
ptrDetail.date.forEach((item: any) => {
const ptrDates = Array.isArray(ptrDetail.data) ? ptrDetail.data : Array.isArray(ptrDetail.date) ? ptrDetail.date : null;
if (ptrDates && ptrDates.length > 0) {
ptrDates.forEach((item: any) => {
const t = parseTime(item?.end_date || item?.start_date);
if (t && (!latestTime || t > latestTime)) {
latestTime = t;