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 22c7a76..8f1a453 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -1,4 +1,3 @@ -// app/task/client-detail/[clientId]/project-assignments-client.tsx "use client" import { useState } from 'react'; @@ -12,7 +11,6 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import Link from 'next/link'; -import { DUMMY_EMPLOYEES } from '../../../types'; import { LazyImage } from '@/components/ui/lazy-image'; import { IProjectAssignment } from '../../../type.assignment'; import ManageEmployee from '../../../component/ManageEmployee'; @@ -24,10 +22,10 @@ import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInpu interface Props { clientId: string; - initialAssignments: IProjectAssignment[]; + assignmentLists: IProjectAssignment[]; } -export default function ClientDetailComponent({ clientId, initialAssignments }: Props) { +export default function ClientDetailComponent({ clientId, assignmentLists }: Props) { const [viewMode, setViewMode] = useState<'grid' | 'table'>('grid'); const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'DELETE' | undefined>() const [selectedData, setSelectedData] = useState() @@ -57,7 +55,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: - {initialAssignments.length} Total + {assignmentLists.length} Total @@ -66,7 +64,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: {/* --- EMPTY STATE --- */} - {initialAssignments.length === 0 ? + {assignmentLists.length === 0 ?
@@ -83,11 +81,11 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: - : viewMode === 'grid' ? + : viewMode === 'grid' ? /* --- GRID VIEW --- */
- {initialAssignments.map((assignment) => { + {assignmentLists.map((assignment) => { const isProject = assignment.project?.code const assignmentType = isProject ? 'Project' : 'IM' @@ -130,14 +128,10 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: } {assignment.wo_name && -

- WO: {assignment.wo_name} -

+

WO: {assignment.wo_name}

} -

- {assignmentDesc} -

+

{assignmentDesc}

@@ -150,18 +144,17 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
- {assignment?.project_assignment_work_order_detail?.slice(0, 3).map(empId => { - const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); + {assignment?.project_assignment_work_order_detail?.map((user, key) => { return ( -
+
- - + +
-

{emp?.name}

-

{emp?.role}

+

{user?.user.fullname}

+

{user?.user.role?.name}

@@ -197,7 +190,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: Edit Assignment - e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees + e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Team e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('DELETE') }} className="text-destructive">Delete @@ -210,8 +203,8 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: ) })}
- : + : /* --- TABLE VIEW --- */
@@ -234,12 +227,13 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: WO Code WO Start WO End + Team Status - {initialAssignments.map((assignment) => { + {assignmentLists.map((assignment) => { return ( {assignment.im_name} @@ -278,6 +272,33 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : ''} + +
+ {assignment?.project_assignment_work_order_detail?.map((user, key) => { + return ( +
+ + + + + +
+

{user?.user.fullname}

+

{user?.user.role?.name}

+
+
+
+
+ ); + })} + {assignment.project_assignment_work_order_detail?.length > 3 && ( +
+ +{assignment.project_assignment_work_order_detail?.length - 3} +
+ )} + {assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && No employees assigned} +
+
@@ -302,7 +323,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: Edit Assignment - e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Add Team + e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Team e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Status e.stopPropagation()} onSelect={() => { setSelectedData(assignment); setAction('DELETE') }} className="text-destructive">Delete diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx index b47ee23..6eea194 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.dummy.tsx @@ -277,7 +277,7 @@ export default function ClientDetailPage({ params }: Props) { Edit Assignment handleOpenEmployeeDialog(assignment)}> - Manage Employees + Manage Team Archive @@ -354,7 +354,7 @@ export default function ClientDetailPage({ params }: Props) { Edit Assignment handleOpenEmployeeDialog(assignment)}> - Manage Employees + Manage Team Archive 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 8a5e662..eafbb30 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx @@ -124,7 +124,7 @@ export default async function ClientDetailPage({ params, searchParams }: Props) {/* Pass the server-fetched data as props */}
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 8c62c77..2784f2b 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 @@ -2,7 +2,7 @@ "use client" import { motion } from 'motion/react'; -import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle, UserPlus, ExternalLink } from 'lucide-react'; +import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle, UserPlus, ExternalLink, Mail, Phone } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle, CardDescription, Card900 } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; @@ -17,6 +17,9 @@ import FormUpdateStatus from '../../../component/FormUpdateStatus'; import BadgeStatus from '@/components/ui/badge-status'; import Link from 'next/link'; import ManageEmployee from '../../../component/ManageEmployee'; +import dayjs from 'dayjs'; +import { LazyImage } from '@/components/ui/lazy-image'; +import AssignedPeople from '../project-detail/[project_id]/AssignedPeople'; interface Props { client: IClient | undefined; @@ -147,13 +150,13 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- {!assignment.wo_name ? ( + {!assignment.wo_name ? No work orders defined for this assignment. - ) : ( + :
@@ -175,37 +178,22 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- {/* WO Status History Mini-Timeline */} - {assignment.project_assignment_status_detail && assignment.project_assignment_status_detail.length > 0 && ( -
-
-

Team

- -
-
- {assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && No employees assigned} - {assignment.project_assignment_work_order_detail.map((history) => ( -
-
-
-
- {history.status} - {new Date(history.date_status_changed).toLocaleDateString()} -
-

{history.status_remarks}

-
-
- ))} -
+
+
+

Team

+
- )} +
+ + +
- )} + }
@@ -231,12 +219,12 @@ export default function AssignmentDetail({ client, initialAssignment: assignment {history.status} - + {new Date(history.date_status_changed).toLocaleDateString()}

{history.status_remarks}

-

+

Recorded: {new Date(history.created_at!).toLocaleString()}

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 f6ff564..23b2439 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 @@ -114,13 +114,13 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is setIsFullLoading(false) if (res.success) { const data: IProjectAssignment = res.data.data - form.setValue('type', data.project.code ? 'Project' : 'IM') - form.setValue('name', data.project.name || data.im_name) - form.setValue('code', data.project.code || data.im_code) - form.setValue('year', data.project.year || data.im_year) - form.setValue('startDate', data.project.start_date || data.im_start_date) - form.setValue('endDate', data.project.end_date || data.im_end_date) - form.setValue('description', data.project.description || data.im_description) + form.setValue('type', data.project?.code ? 'Project' : 'IM') + form.setValue('name', data.project?.name || data.im_name) + form.setValue('code', data.project?.code || data.im_code) + form.setValue('year', data.project?.year || data.im_year) + form.setValue('startDate', data.project?.start_date || data.im_start_date) + form.setValue('endDate', data.project?.end_date || data.im_end_date) + form.setValue('description', data.project?.description || data.im_description) form.setValue('workOrder.name' as any, data.wo_name) form.setValue('workOrder.code' as any, data.wo_code) @@ -347,12 +347,12 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is { - 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 }); + 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) @@ -360,7 +360,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is }} > - {p?.project.name} + {p?.project?.name!} ))} 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 cd7f227..d71cad2 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 @@ -1,5 +1,6 @@ import fetchData from "@/lib/fetchData"; import ProjectAssignmentForm from "./ProjectAssignmentForm"; +import { IProjectAssignment } from "../../../type.assignment"; type Props = { params: Promise<{ client_id: string }> @@ -19,7 +20,7 @@ export default async function CreateAssignmentPage({ params, searchParams }: Pro return (
- 0 ? projectList.filter((item: IProjectAssignment) => item.project?.name) : []} isEdit={isEdit ? true : false} assignmentId={assignmentId as any} />
diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx index c3b90e9..76d46ba 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx @@ -1,52 +1,35 @@ +import { ProjectAssignmentWorkOrderDetail } from '@/app/(dashboard)/task/type.assignment'; +import { Badge } from '@/components/ui/badge'; +import { LazyImage } from '@/components/ui/lazy-image'; +import dayjs from 'dayjs'; import { Mail, Phone, Calendar } from 'lucide-react'; -interface AssignedPeopleProps { - people: any[]; +interface Props { + people: ProjectAssignmentWorkOrderDetail[]; } -const avatarGradients = [ - 'from-rose-500 to-pink-600', - 'from-sky-500 to-blue-600', - 'from-amber-500 to-orange-600', - 'from-emerald-500 to-green-600', - 'from-violet-500 to-purple-600', - 'from-cyan-500 to-teal-600', -]; - -const getInitials = (name: string) => - name.split(' ').map((n) => n[0]).slice(0, 2).join('').toUpperCase(); - -const AssignedPeople = ({ people }: AssignedPeopleProps) => { +const AssignedPeople = ({ people }: Props) => { if (people.length === 0) { return ( -
- No people assigned yet +
+ No team assigned yet
); } - const formatDate = (date: string) => - new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); - return (
{/* Stacked avatars */}
- {people.slice(0, 5).map((person, i) => ( -
- {getInitials(person.name)} -
- ))} - {people.length > 5 && ( + {people.slice(0, 5).map((user, i) => + + )} + {people.length > 5 &&
+{people.length - 5}
- )} + }

{people.length} People

@@ -56,32 +39,22 @@ const AssignedPeople = ({ people }: AssignedPeopleProps) => { {/* Detailed list */}
- {people.map((person, i) => ( -
-
- {getInitials(person.name)} -
- + {people.map((user, i) => ( +
+
-

{person.name}

- - {person.role} - +

{user.user.fullname}

+ {user.user.role?.name}
- {person.email} + {user.user.email} - {person.phone} + {user.user.phone_number}
@@ -92,7 +65,7 @@ const AssignedPeople = ({ people }: AssignedPeopleProps) => { - {formatDate(person.assigned_date)} + {user.assigned_date ? dayjs(user.assigned_date).format('MMMM DD, YYYY') : 'N/A'}
diff --git a/app/(dashboard)/task/component/ClientGrid.tsx b/app/(dashboard)/task/component/ClientGrid.tsx index 82ca642..39c5c36 100644 --- a/app/(dashboard)/task/component/ClientGrid.tsx +++ b/app/(dashboard)/task/component/ClientGrid.tsx @@ -13,7 +13,7 @@ import { import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; -import { DUMMY_EMPLOYEES, IClient } from '../types'; +import { IClient } from '../types'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import FormClient from './FormClient'; @@ -48,6 +48,7 @@ export default function ClientGrid({ clients, assignments }: { clients: IClient[ // const woCount = clientAssignments.reduce((acc, a) => acc + a.workOrders.length, 0); const woCount = client.total_work_order const assignedEmployeeIds = Array.from(new Set(clientAssignments.flatMap(a => a.assignedEmployees))); + console.log(client) return ( A dedicated team of{" "} {assignedEmployeeIds.length} experts is handling{" "} - {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.endUser}. + {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.end_user_name}. )} @@ -118,30 +119,29 @@ export default function ClientGrid({ clients, assignments }: { clients: IClient[
Assigned Team
- {assignedEmployeeIds.slice(0, 5).map((empId) => { - const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); + {client.users?.slice(0, 5).map((user, key) => { return ( -
+
- -

{emp?.name}

-

{emp?.role}

+

{user?.fullname}

+

{user?.role?.name}

); })} - {assignedEmployeeIds.length > 5 && ( + {client.users?.length! > 5 && (
- +{assignedEmployeeIds.length - 5} + +{client.users?.length! - 5}
)} - {assignedEmployeeIds.length === 0 && ( + {client.users?.length === 0 && ( No team assigned )}
diff --git a/app/(dashboard)/task/component/FormUpdateStatus.tsx b/app/(dashboard)/task/component/FormUpdateStatus.tsx index dcbddf2..396302e 100644 --- a/app/(dashboard)/task/component/FormUpdateStatus.tsx +++ b/app/(dashboard)/task/component/FormUpdateStatus.tsx @@ -12,10 +12,15 @@ import { useForm } from 'react-hook-form'; import { IProjectAssignment } from '../type.assignment'; import { DatePicker } from '@/components/ui/datepicker'; import { Loader2 } from 'lucide-react'; -import { STATUS_LIST } from '../data'; +import { useFetchWithAxios } from '@/lib/axios/useFetch'; +import { IStatus } from '../types'; +import { Skeleton } from '@/components/ui/skeleton'; +import { serverApiCall } from '@/lib/server-api'; +import { toast } from 'sonner'; +import dayjs from 'dayjs'; const validationSchema = Yup.object().shape({ - status: Yup.string().required(), + project_status_id: Yup.string().required(), date: Yup.date().required('Date is required'), note: Yup.string().optional().default(''), }); @@ -32,12 +37,29 @@ type Props = { const FormUpdateStatus: FC = ({ title, data, onCancel, onSuccess }) => { const [isLoading, setIsLoading] = useState(false) + const { data: statusList, isLoading: isLoadingStatus } = useFetchWithAxios('/project-status') const form = useForm({ resolver: yupResolver(validationSchema), }); const onSubmit = async (payload: FormDataType) => { + setIsLoading(true); + const newPayload = { + "project_status_id": Number(payload.project_status_id), + "date": dayjs(payload.date).format('YYYY-MM-DD'), + "note": payload.note, + "remarks": payload.note + } + const res = await serverApiCall('PUT', `/project-assignment/status/${data?.id}`, newPayload) + + setIsLoading(false) + if (res.success) { + toast.success('Client saved successfully') + onSuccess!() + } else { + toast.error(`Fail to save client`, { description: `(${res.code || '-'}) ${res.message}` }) + } } return ( @@ -50,56 +72,66 @@ const FormUpdateStatus: FC = ({ title, data, onCancel, onSuccess }) => { Update the current status for {title} -
- -
- ( - - Status - + {isLoadingStatus ? +
+ + + + + +
+ : + + +
+ ( + + Status + + + + )} + /> + ( + + Start Date + - )} - /> - ( - - Start Date - - - - )} /> + )} /> - ( - - Note / Remarks - -