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 a4e6f9f..22c7a76 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -150,7 +150,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
- {assignment?.users?.slice(0, 3).map(empId => { + {assignment?.project_assignment_work_order_detail?.slice(0, 3).map(empId => { const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); return (
@@ -328,7 +328,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: } {action === 'DELETE' ? { router.refresh(); handleClose() }} - title={selectedData?.project.name || selectedData?.im_name!} description={`This action cannot be undone. This will permanently delete and remove project assignment ${selectedData?.project.name || selectedData?.im_name!} from our servers.`} + title={selectedData?.project?.name || selectedData?.im_name!} description={`This action cannot be undone. This will permanently delete and remove project assignment ${selectedData?.project?.name || selectedData?.im_name!} from our servers.`} titleButton={`I understand the consequences, delete this assignment`} /> : null} 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 b69f092..8a5e662 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx @@ -27,8 +27,8 @@ export default async function ClientDetailPage({ params, searchParams }: Props) const getClientById = fetchData(`/client/${client_id}`) - // const getAssignmentsByClient = fetchData(`/client/project-assignment/${client_id}`) - const getAssignmentsByClient = fetchData(`/project-assignment`) + const getAssignmentsByClient = fetchData(`/client/project-assignment/${client_id}`) + // const getAssignmentsByClient = fetchData(`/project-assignment`) const [client, assignmentList] = await Promise.all([getClientById, getAssignmentsByClient]); @@ -43,7 +43,6 @@ export default async function ClientDetailPage({ params, searchParams }: Props) ); } - console.log(assignmentList) const filterData = () => { if (assignmentList && assignmentList.length === 0) return [] // 1. FILTERING diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index a28ca98..8c62c77 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -29,16 +29,16 @@ export default function AssignmentDetail({ client, initialAssignment: assignment const router = useRouter(); - const isProject = assignment.project.code + const isProject = assignment.project?.code const assignmentType = isProject ? 'Project' : 'IM' - const assignmentName = assignment.project.name || assignment.im_name - const assignmentCode = assignment.project.code || assignment.im_code - const assignmentYear = assignment.project.year || assignment.im_year - const assignmentStartDate = assignment.project.start_date || assignment.im_start_date - const assignmentEndDate = assignment.project.end_date || assignment.im_end_date - const assignmentDesc = assignment.project.description || assignment.im_description - const assignmentStatus = assignment.project.status || assignment.project_status.name + const assignmentName = assignment.project?.name || assignment.im_name + const assignmentCode = assignment.project?.code || assignment.im_code + const assignmentYear = assignment.project?.year || assignment.im_year + const assignmentStartDate = assignment.project?.start_date || assignment.im_start_date + const assignmentEndDate = assignment.project?.end_date || assignment.im_end_date + const assignmentDesc = assignment.project?.description || assignment.im_description + const assignmentStatus = assignment.project?.status || assignment.project_status.name const handleClose = () => { setSelectedData(undefined) @@ -147,7 +147,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- {!assignment.wo_code ? ( + {!assignment.wo_name ? ( No work orders defined for this assignment. @@ -258,7 +258,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment } {action === 'MANAGE_EMPLOYEE' ? - + : null } 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 ddd865e..f6ff564 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 @@ -61,7 +61,7 @@ export const assignmentSchema = yup.object({ // Infer the TypeScript type from the Yup schema export type AssignmentFormValues = yup.InferType; -export default function CreateAssignmentForm({ client, clientId, projectList, isEdit, assignmentId }: { client: IClient, projectList: any[], clientId: string, isEdit?: boolean, assignmentId?: string }) { +export default function CreateAssignmentForm({ client, clientId, projectList, isEdit, assignmentId }: { client: IClient, projectList: IProjectAssignment[], clientId: string, isEdit?: boolean, assignmentId?: string }) { const [existAssignment, setIsExistAssignment] = useState(null) const router = useRouter(); @@ -327,7 +327,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
- + {assignmentType === 'Project' && (
@@ -347,20 +347,20 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is { - form.setValue('name', p.name, { shouldValidate: true }); - form.setValue('code', p.code, { shouldValidate: true }); - form.setValue('year', p.year, { shouldValidate: true }); - form.setValue('startDate', p.startDate, { shouldValidate: true }); - form.setValue('endDate', p.endDate, { shouldValidate: true }); - form.setValue('description', p.description, { shouldValidate: true }); + form.setValue('name', p.project?.name, { shouldValidate: true }); + form.setValue('code', p.project?.code, { shouldValidate: true }); + form.setValue('year', p.project?.year, { shouldValidate: true }); + form.setValue('startDate', new Date(p.project?.start_date), { shouldValidate: true }); + form.setValue('endDate', new Date(p.project?.end_date), { shouldValidate: true }); + form.setValue('description', p.project?.description, { shouldValidate: true }); setOpenProjectSearch(false); setIsExistProject(true) - toast.info(`Autofilled details from ${p.name}`); + toast.info(`Autofilled details from ${p.project?.name}`); }} > - - {p.name} + + {p?.project.name} ))} @@ -398,14 +398,14 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is ( Start Date - + )} /> ( End Date - + )} /> diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx index ea258c5..cd7f227 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/page.tsx @@ -12,7 +12,7 @@ export default async function CreateAssignmentPage({ params, searchParams }: Pro const assignmentId = (await searchParams)!.assignment_id const getClient = fetchData(`/client/${client_id}`) - const getProjectByClient = fetchData('/project-assignment') + const getProjectByClient = fetchData(`/client/project-assignment/${client_id}`) const [clientRes, projectList] = await Promise.all([getClient, getProjectByClient]); const client = clientRes && clientRes.length > 0 ? clientRes[0] : clientRes 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 2fd89df..120fd53 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 @@ -1,13 +1,16 @@ "use client" import { useState } from 'react'; -import { ChevronDown, Calendar, FileText, History, Users, StickyNote } from 'lucide-react'; +import { ChevronDown, Calendar, FileText, History, Users, StickyNote, UserPlus, IterationCcw } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import StatusTimeline from './StatusTimeline'; import AssignedPeople from './AssignedPeople'; import BadgeStatus from '@/components/ui/badge-status'; import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment'; +import { useRouter } from 'next/navigation'; +import FormUpdateStatus from '@/app/(dashboard)/task/component/FormUpdateStatus'; +import ManageEmployee from '@/app/(dashboard)/task/component/ManageEmployee'; interface WorkOrderCardProps { workOrder: IProjectAssignment; @@ -17,111 +20,139 @@ interface WorkOrderCardProps { const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) => { const [isOpen, setIsOpen] = useState(defaultOpen); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() + const [selectedData, setSelectedData] = useState() + + const router = useRouter(); const formatDate = (date: string) => new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); + const handleClose = () => { + setSelectedData(undefined) + setAction(undefined) + } + + const handleSuccess = () => { + router.refresh() + handleClose() + } return ( - - {/* Header (always visible) */} -
-
- {/* Index badge */} -
- - {String(index + 1).padStart(2, '0')} - -
- -
-
-

- {workOrder.wo_name} -

- -
-
- - - {workOrder.wo_code} + <> + + {/* Header (always visible) */} +
+
+ {/* Index badge */} +
+ + {String(index + 1).padStart(2, '0')} - - - - {formatDate(workOrder.wo_start_date)} → {formatDate(workOrder.wo_end_date)} +
+ +
+
+

+ {workOrder.wo_name} +

+ +
+
+ + + {workOrder.wo_code} - - - - {workOrder.project_assignment_work_order_detail.length} assigned - + + + + {formatDate(workOrder.wo_start_date)} → {formatDate(workOrder.wo_end_date!)} + + + + + {workOrder.project_assignment_work_order_detail.length} assigned + +
+ + {/* Description */} + {workOrder.wo_description && +

+ {workOrder.wo_description} +

+ } + + {/* Toggle button - full width on mobile */} +
- {/* Description */} - {workOrder.wo_description && -

- {workOrder.wo_description} -

- } + {/* Expandable content */} + {isOpen && +
+ {workOrder.note && +
+ +
+

Note

+

{workOrder.note}

+
+
+ } - {/* Toggle button - full width on mobile */} - -
- - {/* Expandable content */} - {isOpen && -
- {workOrder.note && ( -
- +
+ {/* Status history */}
-

Note

-

{workOrder.note}

-
-
- )} +
+
+ +
+

Status History

+

+ {workOrder.project_assignment_status_detail.length} status changes +

+
+
+ +
-
- {/* Status history */} -
-
-
- -
-
-

Status History

-

- {workOrder.project_assignment_status_detail.length} status changes -

-
+
- -
- {/* Assigned people */} -
-
-
- -
-
-

Assigned People

-

Team members on this work order

+ {/* Assigned people */} +
+
+
+ +
+

Assigned People

+

Team members on this work order

+
+
+
+
-
-
+ } + + + {action === 'UPDATE_STATUS' ? + + : null } - + + {action === 'MANAGE_EMPLOYEE' ? + + : null + } + ); }; diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx index d1cb1e3..632c9f0 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx @@ -2,13 +2,14 @@ import { Button } from '@/components/ui/button'; import Link from 'next/link'; import fetchData from '@/lib/fetchData'; import { ArrowLeft, Briefcase, Calendar, CheckCircle2, ClipboardList, Clock3, Hash, Users } from 'lucide-react'; -import { COMPLETE_STATUS_LIST, IProjectAssignment, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/type.assignment'; +import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment'; import { Card, Card900, CardContent } from '@/components/ui/card'; import WorkOrderCard from './WorkOrderCard'; import { MotionDiv } from '@/components/ui/motion-wrapper'; import { LazyImage } from '@/components/ui/lazy-image'; import { Badge } from '@/components/ui/badge'; import FilterComponent from '@/app/(dashboard)/task/component/FilterComponent'; +import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data'; type Props = { params: Promise<{ client_id: string; project_id: string }> diff --git a/app/(dashboard)/task/component/AssignmentTable.tsx b/app/(dashboard)/task/component/AssignmentTable.tsx index 50e2c13..1c3fe39 100644 --- a/app/(dashboard)/task/component/AssignmentTable.tsx +++ b/app/(dashboard)/task/component/AssignmentTable.tsx @@ -41,21 +41,20 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] } WO Start WO End Last Status + Status Remarks {data.map((assignment, idx) => { - const isProject = assignment.project?.code - return ( - - {assignment.project?.client?.name} + + {assignment.client?.name} - {assignment.project?.client?.end_user_name} + {assignment.client?.end_user?.name} {assignment.im_name} {assignment.im_code || ''} @@ -69,7 +68,7 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] } {assignment.im_end_date ? new Date(assignment.im_end_date).toLocaleDateString() : ''} - + {assignment.project?.name} @@ -95,6 +94,9 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] } + + {assignment.project_assignment_status_detail[0].status_remarks} + @@ -104,11 +106,11 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] } - View Assignment Details + View Assignment Details - {assignment.project?.code ? + {assignment.project?.name ? - View Project Details + View Project Details : null diff --git a/app/(dashboard)/task/component/FilterComponent.tsx b/app/(dashboard)/task/component/FilterComponent.tsx index 29ec3ca..1b40507 100644 --- a/app/(dashboard)/task/component/FilterComponent.tsx +++ b/app/(dashboard)/task/component/FilterComponent.tsx @@ -5,15 +5,18 @@ import { MultiSelect } from '@/components/ui/multi-select'; // Assuming this is import { Search } from 'lucide-react'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; import { type FC, useEffect, useState } from 'react'; -import { STATUS_LIST } from '../type.assignment'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import useDebounce from '@/hooks/useDebounce'; +import { STATUS_LIST } from '../data'; -type Props = {}; +type Props = { + hideStatus?: boolean + hideSort?: boolean +}; -const FilterComponent: FC = ({ }) => { +const FilterComponent: FC = ({ hideStatus, hideSort }) => { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); @@ -75,28 +78,32 @@ const FilterComponent: FC = ({ }) => { />
- ({ label: item, value: item }))} - maxCount={1} - /> + {!hideStatus ? + ({ label: item, value: item }))} + maxCount={1} + /> : null + }
- + {!hideSort ? + : null + }
); } diff --git a/app/(dashboard)/task/component/FormUpdateStatus.tsx b/app/(dashboard)/task/component/FormUpdateStatus.tsx index 0dc8e37..dcbddf2 100644 --- a/app/(dashboard)/task/component/FormUpdateStatus.tsx +++ b/app/(dashboard)/task/component/FormUpdateStatus.tsx @@ -9,9 +9,10 @@ import * as Yup from 'yup' import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { yupResolver } from '@hookform/resolvers/yup'; import { useForm } from 'react-hook-form'; -import { IProjectAssignment, STATUS_LIST } from '../type.assignment'; +import { IProjectAssignment } from '../type.assignment'; import { DatePicker } from '@/components/ui/datepicker'; import { Loader2 } from 'lucide-react'; +import { STATUS_LIST } from '../data'; const validationSchema = Yup.object().shape({ status: Yup.string().required(), diff --git a/app/(dashboard)/task/component/HomeTask.tsx b/app/(dashboard)/task/component/HomeTask.tsx index be6d133..08f108a 100644 --- a/app/(dashboard)/task/component/HomeTask.tsx +++ b/app/(dashboard)/task/component/HomeTask.tsx @@ -8,6 +8,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import FormClient from './FormClient'; +import FilterComponent from './FilterComponent'; interface ShellProps { currentView: 'grid' | 'table'; @@ -25,21 +26,10 @@ export default function HomeTask({ currentView, currentQuery }: ShellProps) { const handleTabChange = (view: string) => { const params = new URLSearchParams(searchParams!); params.set('view', view); + params.delete('status'); router.push(`${pathname}?${params.toString()}`); }; - // Update URL when typing (Debouncing recommended for production) - const handleSearch = (term: string) => { - const params = new URLSearchParams(searchParams!); - if (term) { - params.set('q', term); - } else { - params.delete('q'); - } - // Use replace so we don't clutter the browser history with every keystroke - router.replace(`${pathname}?${params.toString()}`); - }; - return ( <>
@@ -62,15 +52,7 @@ export default function HomeTask({ currentView, currentQuery }: ShellProps) {
-
- - handleSearch(e.target.value)} - /> -
+ {showForm && setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />} diff --git a/app/(dashboard)/task/component/ManageEmployee.tsx b/app/(dashboard)/task/component/ManageEmployee.tsx index 47ab24c..bada3c9 100644 --- a/app/(dashboard)/task/component/ManageEmployee.tsx +++ b/app/(dashboard)/task/component/ManageEmployee.tsx @@ -5,8 +5,7 @@ import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog" import { Button } from '@/components/ui/button'; -import { cn } from '@/lib/utils'; -import { Check, Loader2 } from 'lucide-react'; +import { Loader2 } from 'lucide-react'; import { useFetchWithAxios } from '@/lib/axios/useFetch'; import { IUser } from '@/app/admin/administration/user/component/type'; import { LazyImage } from '@/components/ui/lazy-image'; @@ -111,14 +110,14 @@ const ManageEmployee: FC = ({ title, onCancel, onSuccess }) => { Employee to Assign * - { const user = option.originalData as IUser; return (
- +
{user.fullname} diff --git a/app/(dashboard)/task/data.ts b/app/(dashboard)/task/data.ts new file mode 100644 index 0000000..832a320 --- /dev/null +++ b/app/(dashboard)/task/data.ts @@ -0,0 +1,90 @@ +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.end_user_name?.toLowerCase().includes(query!) + ); + + processedData = processedData.sort((a, b) => { + 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, status?: 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.im_name?.toLowerCase().includes(query)) || + (item.im_code?.toLowerCase().includes(query)) || + (item.project?.name?.toLowerCase().includes(query!)) || + (item.project?.code?.toLowerCase().includes(query!)) || + (item.wo_name?.toLowerCase().includes(query!)) || + (item.wo_code?.toLowerCase().includes(query!)) + ); + + // --- Status Filter --- + const itemStatus = item.project_status?.name?.toLowerCase(); + const matchesStatus = activeStatuses.length === 0 || (itemStatus && activeStatuses.includes(itemStatus)); + + return matchesSearch && matchesStatus; + }); + + // 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; +} \ No newline at end of file diff --git a/app/(dashboard)/task/page.tsx b/app/(dashboard)/task/page.tsx index 0a48cb4..802f8cc 100644 --- a/app/(dashboard)/task/page.tsx +++ b/app/(dashboard)/task/page.tsx @@ -4,39 +4,30 @@ import HomeTask from './component/HomeTask'; import ClientGrid from './component/ClientGrid'; import AssignmentTable from './component/AssignmentTable'; import fetchData from '@/lib/fetchData'; -import { IClient } from './types'; -import { IProjectAssignment } from './type.assignment'; +import { getFilteredAssignments, getFilteredClients } from './data'; type Props = { - searchParams: Promise<{ view?: string; q?: string }> + searchParams: Promise<{ view?: string; q?: string, status?: string, sort?: string }> }; export default async function ClientsPage({ searchParams }: Props) { const params = await searchParams; + const view = params.view === 'table' ? 'table' : 'grid'; const query = (params.q || '').toLowerCase(); + const status = (params.status || '').toLowerCase(); + const sort = (params.sort || '').toLowerCase(); + const sortBy = sort || 'default'; const getClient = fetchData('/client') const getAssignment = fetchData('/project-assignment') - // Wait for the promises to resolve const [allClients, allAssignments] = await Promise.all([getClient, getAssignment]); - // 3. Process Data for Grid View - const filteredClients = allClients.filter((c: IClient) => - c.name.toLowerCase().includes(query) || - c.endUser.toLowerCase().includes(query) - ); - - const flattenedAssignments = allAssignments.filter((c: IProjectAssignment) => - c.project?.name?.toLowerCase().includes(query) || - c.project?.name?.toLowerCase().includes(query) || - c.im_name?.toLowerCase().includes(query) || - c.im_code?.toLowerCase().includes(query) || - c.wo_name?.toLowerCase().includes(query) || - c.wo_code?.toLowerCase().includes(query) - ); + console.log(allAssignments) + const filteredClients = getFilteredClients(allClients, query, sortBy) + const filterAssignments = getFilteredAssignments(allAssignments, query, status, sortBy) return (
@@ -49,7 +40,7 @@ export default async function ClientsPage({ searchParams }: Props) { {view === 'grid' ? : - + }
diff --git a/app/(dashboard)/task/type.assignment.ts b/app/(dashboard)/task/type.assignment.ts index 1111175..ced6fc3 100644 --- a/app/(dashboard)/task/type.assignment.ts +++ b/app/(dashboard)/task/type.assignment.ts @@ -1,29 +1,38 @@ -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 interface IProjectAssignment { id: number - im_code: any - im_description: any - im_end_date: any - im_name: any - im_start_date: any - im_year: any + im_code?: any + im_description?: any + im_end_date?: any + im_name?: any + im_start_date?: any + im_year?: any note: string - project: Project + client: Client + project?: Project project_status: ProjectStatus wo_code: string wo_description: string wo_name: string - wo_end_date: string + wo_start_date: string + wo_end_date?: string wo_warranty: any project_assignment_status_detail: ProjectAssignmentStatusDetail[] project_assignment_work_order_detail: any[] status: Status - wo_start_date: string created_at: string - users: any[] +} + +export interface Client { + id: number + code: string + name: string + end_user: EndUser +} + +export interface EndUser { + id: number + code: string + name: string } export interface Project { diff --git a/app/(dashboard)/task/types.ts b/app/(dashboard)/task/types.ts index 0565f99..77975f8 100644 --- a/app/(dashboard)/task/types.ts +++ b/app/(dashboard)/task/types.ts @@ -8,9 +8,6 @@ export type IEndUser = { export type IClient = { id?: string; name: string; - endUser: string; - imageUrl: string; - createdAt?: string; end_user_id?: number photo?: string code?: string @@ -86,21 +83,4 @@ export const DUMMY_EMPLOYEES: IEmployee[] = [ { id: 'e3', name: 'Mike Johnson', role: 'UI/UX Designer', avatar: 'https://i.pravatar.cc/150?u=e3', email: 'mike@example.com' }, { id: 'e4', name: 'Sarah Wilson', role: 'QA Engineer', avatar: 'https://i.pravatar.cc/150?u=e4', email: 'sarah@example.com' }, { id: 'e5', name: 'Alex Brown', role: 'Backend Developer', avatar: 'https://i.pravatar.cc/150?u=e5', email: 'alex@example.com' }, -]; - -export const INITIAL_CLIENTS: IClient[] = [ - { - id: 'c1', - name: 'TechCorp Solutions', - endUser: 'Global Logistics Inc.', - imageUrl: 'https://picsum.photos/seed/tech/200/200', - createdAt: new Date().toISOString(), - }, - { - id: 'c2', - name: 'Creative Agency', - endUser: 'Fashion Brand X', - imageUrl: 'https://picsum.photos/seed/creative/200/200', - createdAt: new Date().toISOString(), - }, -]; +]; \ No newline at end of file diff --git a/components/modal/ConfirmDeleteWithInput.tsx b/components/modal/ConfirmDeleteWithInput.tsx index 35dfe75..6f36363 100644 --- a/components/modal/ConfirmDeleteWithInput.tsx +++ b/components/modal/ConfirmDeleteWithInput.tsx @@ -78,7 +78,7 @@ export function ConfirmDeleteWithInput({ endpoint, title, titleButton, descripti
-
+
(