diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx index 2cbd39d..8671faa 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx @@ -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 (
diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ProjectMilestoneTimeline.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ProjectMilestoneTimeline.tsx index cef9cb9..65f111c 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ProjectMilestoneTimeline.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/ProjectMilestoneTimeline.tsx @@ -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); diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/page.tsx index 5310544..00362b6 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/page.tsx @@ -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 ( diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx index 59ef240..c6c1301 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx @@ -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( WO Code - - Prefix: {projectCode}- -
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 4c2bd4c..ea7e45d 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 @@ -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); diff --git a/app/(dashboard)/task/component/UpdateTechnicalStatus.tsx b/app/(dashboard)/task/component/UpdateTechnicalStatus.tsx index ae74ca9..e261373 100644 --- a/app/(dashboard)/task/component/UpdateTechnicalStatus.tsx +++ b/app/(dashboard)/task/component/UpdateTechnicalStatus.tsx @@ -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 ( { if (!open && !isSaving) onClose(); }}> @@ -209,20 +218,27 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
{/* Show existing dates overview when adding */} {data.existingDates.length > 0 && data.mode === 'ADD' && ( -
+
Existing Schedules ({data.existingDates.length}) +1 new interval will be added
-
+
{data.existingDates.map((item, idx) => ( - - - {dayjs(item.start_date).format('DD MMM YYYY')} – {dayjs(item.end_date).format('DD MMM YYYY')} - +
+ + {dayjs(item.start_date).format('DD MMM YYYY')} – {dayjs(item.end_date).format('DD MMM YYYY')} +
+ {item.description && ( +

+ "{item.description}" +

+ )} +
))}
@@ -263,7 +279,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
{description.length}/500
@@ -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" /> +

+ Deskripsi ini khusus berlaku untuk rentang tanggal di atas. +

@@ -384,7 +403,7 @@ const UpdateTechnicalStatus: FC = ({ assignmentId, onClose }) => { existingDates: item.dates, initialStartDate: undefined, initialEndDate: undefined, - initialDescription: item.description + initialDescription: '', }); }; @@ -400,7 +419,7 @@ const UpdateTechnicalStatus: FC = ({ 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 = ({ 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 = ({ 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 = ({ assignmentId, onClose }) => {
{hasDates ? ( -
- {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; +
+ {[...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 ( -
-
- - - {start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'} - - {spanDays !== null && ( - - ({spanDays} {spanDays === 1 ? 'day' : 'days'}) - + return ( +
+
+
+ + + {start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'} + + {spanDays !== null && ( + + ({spanDays} {spanDays === 1 ? 'day' : 'days'}) + + )} +
+ +
+ + +
+
+ + {/* Individual date description */} + {dateEntry.description ? ( +
+ Note: + {dateEntry.description} +
+ ) : ( +
+ No description provided for this date. +
)}
- -
- - -
-
- ); - })} + ); + })}
) : ( No dates scheduled )} - - {/* Description / Notes Display */} - {item.description ? ( -
- "{item.description}" -
- ) : null}
@@ -605,21 +643,21 @@ const UpdateTechnicalStatus: FC = ({ assignmentId, onClose }) => { - Delete Schedule Interval + Delete Schedule {deleteTarget && ( <> - Are you sure you want to delete the schedule interval{' '} + Are you sure you want to delete the schedule{' '} {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'} {' '} from {deleteTarget.item.statusName}? - {deleteTarget.item.dates.length === 1 && ( -
- Note: This is the last remaining schedule for this status. Deleting it will also remove the description and progress notes. + {deleteTarget.dateEntry.description && ( +
+ "{deleteTarget.dateEntry.description}"
)} diff --git a/app/(dashboard)/task/component/client/ClientGrid.tsx b/app/(dashboard)/task/component/client/ClientGrid.tsx index 01d9b20..cdef030 100644 --- a/app/(dashboard)/task/component/client/ClientGrid.tsx +++ b/app/(dashboard)/task/component/client/ClientGrid.tsx @@ -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); diff --git a/app/(dashboard)/task/component/client/ClientList.tsx b/app/(dashboard)/task/component/client/ClientList.tsx index 14cb80e..f2f19b4 100644 --- a/app/(dashboard)/task/component/client/ClientList.tsx +++ b/app/(dashboard)/task/component/client/ClientList.tsx @@ -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 ( | 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 } diff --git a/app/(dashboard)/task/utils/assignment-overview-helpers.ts b/app/(dashboard)/task/utils/assignment-overview-helpers.ts index 7c3499b..4e8bcf0 100644 --- a/app/(dashboard)/task/utils/assignment-overview-helpers.ts +++ b/app/(dashboard)/task/utils/assignment-overview-helpers.ts @@ -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; diff --git a/components/ui/badge.tsx b/components/ui/badge.tsx index abbc695..4aa50a7 100644 --- a/components/ui/badge.tsx +++ b/components/ui/badge.tsx @@ -46,13 +46,13 @@ const badgeVariants = cva( adminCompleted: "border-transparent bg-sky-500 text-white dark:bg-sky-600 hover:opacity-85", // Emerald Green // --- TECHNICAL PROGRESSION STATUS VARIANTS --- - techDevelopment: "border-transparent bg-his text-white dark:bg-his hover:opacity-85", // HIS Orange - techSIT: "border-transparent bg-blue-500 text-white dark:bg-blue-600 hover:opacity-85", // Blue - techUAT: "border-transparent bg-purple-500 text-white dark:bg-purple-600 hover:opacity-85", // Purple/Violet - techPTR: "border-transparent bg-teal-500 text-white dark:bg-teal-600 hover:opacity-85", // Mint / Aqua (Teal) - techGoLive: "border-transparent bg-green-500 text-white dark:bg-green-700 hover:opacity-85", // Green - techBAST: "border-transparent bg-yellow-500 text-white dark:bg-yellow-600 hover:opacity-85", // Yellow / Amber (BAST) - techWarranty: "border-transparent bg-sky-500 text-white dark:bg-sky-600 hover:opacity-85", // Sky Blue + techDevelopment: "border-transparent text-white bg-rose-400 dark:bg-rose-600 hover:opacity-85", // HIS Orange + techSIT: "border-transparent text-white bg-orange-400 dark:bg-orange-700 hover:opacity-85", // Blue + techUAT: "border-transparent text-white bg-yellow-400 dark:bg-yellow-500 hover:opacity-85", // Purple/Violet + techPTR: "border-transparent text-white bg-emerald-400 dark:bg-emerald-600 hover:opacity-85", // Mint / Aqua (Teal) + techGoLive: "border-transparent text-white bg-cyan-400 dark:bg-cyan-600 hover:opacity-85", // Green + techBAST: "border-transparent text-white bg-violet-400 dark:bg-violet-600 hover:opacity-85", // Yellow / Amber (BAST) + techWarranty: "border-transparent text-white bg-fuchsia-400 dark:bg-fuchsia-600 hover:opacity-85", // Sky Blue }, }, defaultVariants: {