+
{/* Continuous 2-Month Horizontal Rail */}
{/* Gradient Segments connecting Hari Ini -> Agenda 1 -> Agenda 2 -> ... */}
@@ -200,7 +200,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl
{/* If no milestones in range, show gentle notice */}
{!hasAgendas && (
-
+
No upcoming milestones in the next 2 months
From 47076b1d09c6fa632e48fdf9b47b2d6a77f3187d Mon Sep 17 00:00:00 2001
From: Ichsan Kurniawan <43689091+ichsankurnia@users.noreply.github.com>
Date: Wed, 4 Nov 2026 16:03:26 +0700
Subject: [PATCH 2/4] Improve task search and filtering
Search clients and assignments by employee, add end-user filters to client details, and refine filter options and sorting behavior.
---
.../(main)/ClientDetailComponent.tsx | 30 +++++-
.../task/component/FilterComponent.tsx | 15 ++-
.../task/component/FilterModal.tsx | 49 +++++----
app/(dashboard)/task/component/HomeTask.tsx | 11 +--
app/(dashboard)/task/data.ts | 99 +++++++++++++------
app/(dashboard)/task/error.tsx | 2 +-
6 files changed, 141 insertions(+), 65 deletions(-)
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 ba68b10..f81746a 100644
--- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx
+++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx
@@ -1,11 +1,11 @@
"use client";
-import { useState } from 'react';
+import { useState, useMemo } from 'react';
import { Briefcase } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import Link from 'next/link';
-import { IProjectAssignment } from '../../../type.assignment';
+import { EndUser, IProjectAssignment } from '../../../type.assignment';
import { useRouter, useSearchParams } from 'next/navigation';
import dynamic from 'next/dynamic';
import FilterComponent from '../../../component/FilterComponent';
@@ -89,13 +89,35 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
setAction(undefined);
};
+ const uniqueEndUsers = useMemo(() => {
+ const seen = new Set
();
+ const result: EndUser[] = [];
+
+ for (const item of assignmentLists) {
+ const endUser = item?.end_user;
+ if (!endUser) continue;
+ const key = String(endUser.id ?? endUser.code ?? endUser.name ?? '');
+ if (key && !seen.has(key)) {
+ seen.add(key);
+ result.push(endUser);
+ }
+ }
+
+ return result;
+ }, [assignmentLists]);
+
return (
{/* --- PROJECT ASSIGNMENT DASHBOARD STATS --- */}
{/* --- FILTER & SEARCH TOOLBAR --- */}
-
+
{/* --- EMPTY STATE --- */}
{assignmentLists.length === 0 ? (
@@ -199,4 +221,4 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
) : null}
);
-}
\ No newline at end of file
+}
diff --git a/app/(dashboard)/task/component/FilterComponent.tsx b/app/(dashboard)/task/component/FilterComponent.tsx
index 714af28..b7c80a6 100644
--- a/app/(dashboard)/task/component/FilterComponent.tsx
+++ b/app/(dashboard)/task/component/FilterComponent.tsx
@@ -11,6 +11,8 @@ import {
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import useDebounce from '@/hooks/useDebounce';
+import { EndUser } from '../type.assignment';
+import { IEndUser } from '../types';
const FilterModal = dynamic(
() => import('./FilterModal').then((mod) => mod.FilterModal),
@@ -26,6 +28,7 @@ const FilterModal = dynamic(
);
type Props = {
+ endUserList?: (EndUser | IEndUser)[]
hideClient?: boolean
hideEndUser?: boolean
hideStatus?: boolean;
@@ -41,6 +44,7 @@ type Props = {
};
const FilterComponent: FC = ({
+ endUserList,
hideFilterModal,
hideClient,
hideEndUser,
@@ -52,7 +56,7 @@ const FilterComponent: FC = ({
hideCategory,
hideSort,
showLayoutToggle,
- placeholder = "Search client...",
+ placeholder = "Search client or employee...",
}) => {
const router = useRouter();
const pathname = usePathname();
@@ -60,6 +64,7 @@ const FilterComponent: FC = ({
const currentQuery = searchParams?.get('q') || '';
const currentSort = searchParams?.get('sort') || '';
+ const sortValue = (currentSort === 'active_first' || !currentSort) ? 'default' : currentSort;
const currentLayout = searchParams?.get('layout') === 'grid' ? 'grid' : 'list';
const [searchText, setSearchText] = useState(currentQuery);
@@ -117,6 +122,7 @@ const FilterComponent: FC = ({
{!hideFilterModal ?
@@ -159,12 +165,11 @@ const FilterComponent: FC = ({
) : null}
{!hideSort ? (
- : null
}
{!hideCategory ?
-
+
-
+
Project
@@ -232,7 +247,7 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true,
}
{!hideStatus ?
-
+
= ({ hideClient = true, hideEndUser = true,
placeholder='Select user to filter'
value={assignedToFilter}
onChange={setAssignedToFilter}
- options={userList && userList.length > 0 ? userList.map((item: IUser) => ({ label: item.name, value: String(item.id) })) : []}
+ options={userList && userList?.user && userList?.user?.length > 0 ? userList?.user?.map((item: IUser) => ({ label: item.fullname, value: String(item.id) })) : []}
maxCount={1}
/>
: null
@@ -267,4 +282,4 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true,
);
-}
\ No newline at end of file
+}
diff --git a/app/(dashboard)/task/component/HomeTask.tsx b/app/(dashboard)/task/component/HomeTask.tsx
index f77d796..1b2b90f 100644
--- a/app/(dashboard)/task/component/HomeTask.tsx
+++ b/app/(dashboard)/task/component/HomeTask.tsx
@@ -91,16 +91,6 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) {
{card.value}
- {/* {card.trend && (
-
-
- ↑ {card.trend}
-
-
- vs last month
-
-
- )} */}
@@ -113,6 +103,7 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) {
{showForm && (
diff --git a/app/(dashboard)/task/data.ts b/app/(dashboard)/task/data.ts
index a33b053..4db1e72 100644
--- a/app/(dashboard)/task/data.ts
+++ b/app/(dashboard)/task/data.ts
@@ -6,19 +6,48 @@ export const COMPLETE_STATUS_LIST = ['BAST', 'WARRANTY', 'END OF SUPPORT']
export const ONPROGRESS_STATUS_LIST = ['ON PROGRESS', 'ON GOING', 'HALTED', 'ISSUE', 'SIT', 'UAT', 'PTR']
export const getFilteredClients = (clientLists: IClient[], query?: string, sortBy?: string) => {
- let processedData = clientLists.filter((c) =>
- c.name.toLowerCase().includes(query!) ||
- c.code?.toLowerCase().includes(query!) ||
- c.description?.toLowerCase().includes(query!)
- );
+ if (!clientLists || !Array.isArray(clientLists) || clientLists.length === 0) return [];
+
+ const q = (query || '').toLowerCase().trim();
+
+ let processedData = clientLists.filter((c) => {
+ if (!q) return true;
+
+ const matchesClientName = c.name?.toLowerCase().includes(q);
+ const matchesClientCode = c.code?.toLowerCase().includes(q);
+ const matchesClientDesc = typeof c.description === 'string' && c.description.toLowerCase().includes(q);
+
+ const matchesEmployee = c.users?.some((u) =>
+ u?.fullname?.toLowerCase().includes(q) ||
+ u?.nickname?.toLowerCase().includes(q) ||
+ u?.name?.toLowerCase().includes(q)
+ );
+
+ return Boolean(matchesClientName || matchesClientCode || matchesClientDesc || matchesEmployee);
+ });
+
+ // If searching by employee, prioritize matching users to the front of avatars
+ if (q) {
+ processedData = processedData.map((c) => {
+ if (!c.users || c.users.length <= 1) return c;
+ const hasMatchingUser = c.users.some((u) =>
+ u?.fullname?.toLowerCase().includes(q) ||
+ u?.nickname?.toLowerCase().includes(q) ||
+ u?.name?.toLowerCase().includes(q)
+ );
+ if (!hasMatchingUser) return c;
+
+ const sortedUsers = [...c.users].sort((a, b) => {
+ const aMatch = (a?.fullname?.toLowerCase().includes(q) || a?.nickname?.toLowerCase().includes(q) || a?.name?.toLowerCase().includes(q)) ? 1 : 0;
+ const bMatch = (b?.fullname?.toLowerCase().includes(q) || b?.nickname?.toLowerCase().includes(q) || b?.name?.toLowerCase().includes(q)) ? 1 : 0;
+ return bMatch - aMatch;
+ });
+
+ return { ...c, users: sortedUsers };
+ });
+ }
processedData = processedData.sort((a, b) => {
- if (sortBy === 'active_first') {
- const aActive = (a.status_name || '').toLowerCase() === 'active' ? 1 : 0;
- const bActive = (b.status_name || '').toLowerCase() === 'active' ? 1 : 0;
- return bActive - aActive;
- }
-
if (sortBy === 'latest') {
return new Date(b.created_at!).getTime() - new Date(a.created_at!).getTime();
}
@@ -39,7 +68,8 @@ export const getFilteredClients = (clientLists: IClient[], query?: string, sortB
return aCount - bCount; // Lowest count first
}
- return 0; // 'default' - keeps original array order
+ // 'default', 'alphabet', or fallback: sort alphabetically by client name (A-Z)
+ return (a.name || '').trim().localeCompare((b.name || '').trim(), undefined, { sensitivity: 'base', numeric: true });
});
return processedData;
@@ -48,23 +78,30 @@ export const getFilteredClients = (clientLists: IClient[], query?: string, sortB
export const getFilteredAssignments = (assignmentList: IProjectAssignment[], query?: string, sortBy?: string) => {
if (assignmentList && assignmentList.length === 0) return []
- // const activeStatuses = status ? status.toLowerCase()?.split(',') : [];
+ const q = (query || '').toLowerCase().trim();
// 1. FILTERING
let processedData = assignmentList?.filter((item) => {
- const matchesSearch = query === '' || (
- (item.client.name?.toLowerCase().includes(query!)) ||
- (item.client.code?.toLowerCase().includes(query!)) ||
- (item.end_user.name?.toLowerCase().includes(query!)) ||
- (item.end_user.code?.toLowerCase().includes(query!)) ||
- (item.im_name?.toLowerCase().includes(query)) ||
- (item.im_code?.toLowerCase().includes(query)) ||
- (item.im_description?.toLowerCase().includes(query)) ||
- (item.project?.name?.toLowerCase().includes(query!)) ||
- (item.project?.code?.toLowerCase().includes(query!)) ||
- (item.project?.description?.toLowerCase().includes(query!)) ||
- (item.wo_name?.toLowerCase().includes(query!)) ||
- (item.wo_code?.toLowerCase().includes(query!))
+ if (!q) return true;
+
+ const matchesSearch = (
+ (item.client?.name?.toLowerCase().includes(q)) ||
+ (item.client?.code?.toLowerCase().includes(q)) ||
+ (item.end_user?.name?.toLowerCase().includes(q)) ||
+ (item.end_user?.code?.toLowerCase().includes(q)) ||
+ (item.im_name?.toLowerCase().includes(q)) ||
+ (item.im_code?.toLowerCase().includes(q)) ||
+ (item.im_description?.toLowerCase().includes(q)) ||
+ (item.project?.name?.toLowerCase().includes(q)) ||
+ (item.project?.code?.toLowerCase().includes(q)) ||
+ (item.project?.description?.toLowerCase().includes(q)) ||
+ (item.wo_name?.toLowerCase().includes(q)) ||
+ (item.wo_code?.toLowerCase().includes(q)) ||
+ (item.project_assignment_work_order_detail?.some((wo) =>
+ wo.user?.fullname?.toLowerCase().includes(q) ||
+ wo.user?.nickname?.toLowerCase().includes(q) ||
+ wo.user?.name?.toLowerCase().includes(q)
+ ))
);
// --- Status Filter ---
@@ -72,7 +109,7 @@ export const getFilteredAssignments = (assignmentList: IProjectAssignment[], que
// const matchesStatus = activeStatuses.length === 0 || (itemStatus && activeStatuses.includes(itemStatus));
// return matchesSearch && matchesStatus;
- return matchesSearch;
+ return Boolean(matchesSearch);
});
// 2. SORTING
@@ -97,8 +134,14 @@ export const getFilteredAssignments = (assignmentList: IProjectAssignment[], que
return aCount - bCount; // Lowest count first
}
+ if (sortBy === 'alphabet') {
+ const nameA = a.project?.name || a.wo_name || a.im_name || a.client?.name || '';
+ const nameB = b.project?.name || b.wo_name || b.im_name || b.client?.name || '';
+ return nameA.trim().localeCompare(nameB.trim(), undefined, { sensitivity: 'base', numeric: true });
+ }
+
return 0; // 'default' - keeps original array order
});
return processedData;
-}
\ No newline at end of file
+}
diff --git a/app/(dashboard)/task/error.tsx b/app/(dashboard)/task/error.tsx
index 7347e1f..43d4aa0 100644
--- a/app/(dashboard)/task/error.tsx
+++ b/app/(dashboard)/task/error.tsx
@@ -356,7 +356,7 @@ export default function TaskError({ error, reset }: TaskErrorProps) {
Technical Support
- If this message persists after several retries, copy the diagnostic report below and share it with the dev team.
+ If this message persists after several retries, copy the diagnostic report above and share it with the dev team.