mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 19:46:28 +00:00
9a04ba7738
This update redesigns the task dashboard around client overview metrics, adding summary cards, project status breakdowns, and milestone timelines for each client. It also adds an active-first sort option, supports customizable search placeholders, and passes the full client list into the dashboard while wrapping the client views in Suspense for smoother loading.
104 lines
4.3 KiB
TypeScript
104 lines
4.3 KiB
TypeScript
import { IProjectAssignment } from "./type.assignment";
|
|
import { IClient } from "./types";
|
|
|
|
export const STATUS_LIST = ["Not Started", "On Progress", "On Going", "Halted", "Issue", "SIT", "UAT", "PTR", "BAST", "Warranty", "End Of Support", "Canceled"]
|
|
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!)
|
|
);
|
|
|
|
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();
|
|
}
|
|
|
|
if (sortBy === 'oldest') {
|
|
return new Date(a.created_at!).getTime() - new Date(b.created_at!).getTime();
|
|
}
|
|
|
|
if (sortBy === 'participants_desc') {
|
|
const aCount = a.users?.length || 0;
|
|
const bCount = b.users?.length || 0;
|
|
return bCount - aCount; // Highest count first
|
|
}
|
|
|
|
if (sortBy === 'participants_asc') {
|
|
const aCount = a.users?.length || 0;
|
|
const bCount = b.users?.length || 0;
|
|
return aCount - bCount; // Lowest count first
|
|
}
|
|
|
|
return 0; // 'default' - keeps original array order
|
|
});
|
|
|
|
return processedData;
|
|
}
|
|
|
|
export const getFilteredAssignments = (assignmentList: IProjectAssignment[], query?: string, sortBy?: string) => {
|
|
if (assignmentList && assignmentList.length === 0) return []
|
|
|
|
// const activeStatuses = status ? status.toLowerCase()?.split(',') : [];
|
|
|
|
// 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!))
|
|
);
|
|
|
|
// --- Status Filter ---
|
|
// const itemStatus = item.project_assignment_status?.name?.toLowerCase();
|
|
// const matchesStatus = activeStatuses.length === 0 || (itemStatus && activeStatuses.includes(itemStatus));
|
|
|
|
// return matchesSearch && matchesStatus;
|
|
return matchesSearch;
|
|
});
|
|
|
|
// 2. SORTING
|
|
processedData = processedData?.sort((a: IProjectAssignment, b: IProjectAssignment) => {
|
|
if (sortBy === 'latest') {
|
|
return new Date(b.created_at).getTime() - new Date(a.created_at).getTime();
|
|
}
|
|
|
|
if (sortBy === 'oldest') {
|
|
return new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
|
|
}
|
|
|
|
if (sortBy === 'participants_desc') {
|
|
const aCount = a.project_assignment_work_order_detail?.length || 0;
|
|
const bCount = b.project_assignment_work_order_detail?.length || 0;
|
|
return bCount - aCount; // Highest count first
|
|
}
|
|
|
|
if (sortBy === 'participants_asc') {
|
|
const aCount = a.project_assignment_work_order_detail?.length || 0;
|
|
const bCount = b.project_assignment_work_order_detail?.length || 0;
|
|
return aCount - bCount; // Lowest count first
|
|
}
|
|
|
|
return 0; // 'default' - keeps original array order
|
|
});
|
|
|
|
return processedData;
|
|
} |