mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 23:16:29 +00:00
Add query-string helper and centralize filtering
Introduce getQueryStringFilteredAssignments in lib/fetchData and use it across task pages to append backend filter params to API requests. Move client/assignment filtering into shared helpers (getFilteredAssignments, getFilteredClients) and remove duplicated local filter logic from client/project pages. Expand searchable fields and adjust getFilteredAssignments signature to accept (list, query, sortBy). Update IClient type and add ProjectStatusSummary. Miscellaneous UI/UX fixes: use fullname in AssignmentTable tooltip, fix debounce usage, pass correct prop to FilterComponent in HomeTask, and normalize isEdit handling in project-assignment page.
This commit is contained in:
@@ -68,4 +68,50 @@ export async function fetchDataWithPost(url: string = '/', payload: any = {}, ca
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
type PageSearchParams = {
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
|
||||
export async function getQueryStringFilteredAssignments(searchParams: PageSearchParams) {
|
||||
const apiParams = new URLSearchParams();
|
||||
|
||||
// Helper function to safely map and append values if they exist
|
||||
const appendIfPresent = (nextJsKey: string, backendApiKey: string) => {
|
||||
const value = searchParams[nextJsKey];
|
||||
if (value) {
|
||||
// const stringValue = Array.isArray(value) ? value.join(',') : value;
|
||||
// apiParams.append(backendApiKey, stringValue);
|
||||
|
||||
value.split(',').forEach(v => {
|
||||
if (v.trim()) apiParams.append(backendApiKey, v.trim())
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// --- 1. Map IDs ---
|
||||
// appendIfPresent('client', 'client_id');
|
||||
// appendIfPresent('end_user', 'end_user_id');
|
||||
appendIfPresent('status', 'project_assignment_status_id');
|
||||
appendIfPresent('users', 'user_id');
|
||||
|
||||
// --- 2. Map Dates (Project) ---
|
||||
appendIfPresent('project_date_from', 'project_start_date');
|
||||
appendIfPresent('project_date_to', 'project_end_date');
|
||||
|
||||
// --- 3. Map Dates (Work Order) ---
|
||||
appendIfPresent('wo_date_from', 'wo_start_date');
|
||||
appendIfPresent('wo_date_to', 'wo_end_date');
|
||||
|
||||
// --- 4. Map Dates (Internal Memo) ---
|
||||
appendIfPresent('im_date_from', 'im_start_date');
|
||||
appendIfPresent('im_date_to', 'im_end_date');
|
||||
|
||||
// Construct the final URL.
|
||||
// If no params exist, apiParams.toString() is empty, so we safely handle the '?'
|
||||
const queryString = apiParams.toString();
|
||||
// const finalUrl = queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
||||
|
||||
return queryString
|
||||
}
|
||||
Reference in New Issue
Block a user