mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 17:26:28 +00:00
update logic, ui
This commit is contained in:
@@ -150,7 +150,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
<div className="flex items-center gap-2">
|
||||
<Users className="w-4 h-4" />
|
||||
<div className="flex -space-x-2">
|
||||
{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 (
|
||||
<div key={empId}>
|
||||
@@ -328,7 +328,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/project-assignment/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { 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}
|
||||
</>
|
||||
|
||||
@@ -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
|
||||
|
||||
+10
-10
@@ -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
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{!assignment.wo_code ? (
|
||||
{!assignment.wo_name ? (
|
||||
<Card className="border-dashed bg-accent/10">
|
||||
<CardContent className="py-10 text-center text-muted-foreground">
|
||||
No work orders defined for this assignment.
|
||||
@@ -258,7 +258,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageEmployee data={assignment} title={assignment.wo_name} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
<ManageEmployee data={assignment} title={assignment.project?.name ? assignment.wo_name : assignment.im_name} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
</>
|
||||
|
||||
+13
-13
@@ -61,7 +61,7 @@ export const assignmentSchema = yup.object({
|
||||
// Infer the TypeScript type from the Yup schema
|
||||
export type AssignmentFormValues = yup.InferType<typeof assignmentSchema>;
|
||||
|
||||
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<IProjectAssignment | null>(null)
|
||||
|
||||
const router = useRouter();
|
||||
@@ -327,7 +327,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1 relative">
|
||||
<FormControl>
|
||||
<Input placeholder="e.g Software Development Sem 1 PO 4200049718..." {...field} />
|
||||
<Input placeholder="e.g Software Development Sem 1 PO 4200049718..." {...field} disabled={isExistProject} />
|
||||
</FormControl>
|
||||
{assignmentType === 'Project' && (
|
||||
<div className="absolute right-2 top-1/2 -translate-y-1/2">
|
||||
@@ -347,20 +347,20 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<CommandItem
|
||||
key={p.id}
|
||||
onSelect={() => {
|
||||
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}`);
|
||||
}}
|
||||
>
|
||||
<Check className={cn("mr-2 h-4 w-4", field.value === p.name ? "opacity-100" : "opacity-0")} />
|
||||
{p.name}
|
||||
<Check className={cn("mr-2 h-4 w-4", field.value === p.project?.name ? "opacity-100" : "opacity-0")} />
|
||||
{p?.project.name}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
@@ -398,14 +398,14 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<FormField control={form.control} name="startDate" disabled={isExistProject} render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Start Date</FormLabel>
|
||||
<DatePicker date={field.value} setDate={field.onChange} />
|
||||
<DatePicker date={field.value} setDate={field.onChange} disabled={isExistProject} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="endDate" disabled={isExistProject} render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>End Date</FormLabel>
|
||||
<DatePicker date={field.value as Date | undefined} setDate={field.onChange} />
|
||||
<DatePicker date={field.value as Date | undefined} setDate={field.onChange} disabled={isExistProject} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
|
||||
@@ -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
|
||||
|
||||
+116
-85
@@ -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<IProjectAssignment>()
|
||||
|
||||
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 (
|
||||
<Card900 className="overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm hover:shadow-xl transition-all text-sm border-l-4 border-l-primary">
|
||||
{/* Header (always visible) */}
|
||||
<div className="p-4 sm:p-6">
|
||||
<div className="flex items-start gap-3 sm:gap-4">
|
||||
{/* Index badge */}
|
||||
<div className={`w-10 h-10 sm:w-12 sm:h-12 shrink-0 rounded-xl bg-zinc-500 text-primary flex items-center justify-center shadow-lg`}>
|
||||
<span className="text-sm sm:text-lg font-bold text-white">
|
||||
{String(index + 1).padStart(2, '0')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start gap-2 flex-wrap mb-1.5">
|
||||
<h3 className="text-base sm:text-xl font-bold text-foreground wrap-break-word flex-1 min-w-0">
|
||||
{workOrder.wo_name}
|
||||
</h3>
|
||||
<BadgeStatus status={workOrder.project_status.name} />
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-3 text-muted-foreground sm:flex-wrap">
|
||||
<span className="inline-flex items-center gap-1.5 font-mono">
|
||||
<FileText className="w-3 h-3 shrink-0" />
|
||||
{workOrder.wo_code}
|
||||
<>
|
||||
<Card900 className="overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm hover:shadow-xl transition-all text-sm border-l-4 border-l-primary">
|
||||
{/* Header (always visible) */}
|
||||
<div className="p-4 sm:p-6">
|
||||
<div className="flex items-start gap-3 sm:gap-4">
|
||||
{/* Index badge */}
|
||||
<div className={`w-10 h-10 sm:w-12 sm:h-12 shrink-0 rounded-xl bg-zinc-500 text-primary flex items-center justify-center shadow-lg`}>
|
||||
<span className="text-sm sm:text-lg font-bold text-white">
|
||||
{String(index + 1).padStart(2, '0')}
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5 min-w-0">
|
||||
<Calendar className="w-3 h-3 shrink-0" />
|
||||
<span className="truncate">
|
||||
{formatDate(workOrder.wo_start_date)} → {formatDate(workOrder.wo_end_date)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start gap-2 flex-wrap mb-1.5">
|
||||
<h3 className="text-base sm:text-xl font-bold text-foreground wrap-break-word flex-1 min-w-0">
|
||||
{workOrder.wo_name}
|
||||
</h3>
|
||||
<BadgeStatus status={workOrder.project_status.name} />
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-3 text-muted-foreground sm:flex-wrap">
|
||||
<span className="inline-flex items-center gap-1.5 font-mono">
|
||||
<FileText className="w-3 h-3 shrink-0" />
|
||||
{workOrder.wo_code}
|
||||
</span>
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Users className="w-3 h-3 shrink-0" />
|
||||
{workOrder.project_assignment_work_order_detail.length} assigned
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5 min-w-0">
|
||||
<Calendar className="w-3 h-3 shrink-0" />
|
||||
<span className="truncate">
|
||||
{formatDate(workOrder.wo_start_date)} → {formatDate(workOrder.wo_end_date!)}
|
||||
</span>
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Users className="w-3 h-3 shrink-0" />
|
||||
{workOrder.project_assignment_work_order_detail.length} assigned
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
{workOrder.wo_description &&
|
||||
<p className="text-sm text-muted-foreground mt-3 sm:mt-4 sm:ml-16 wrap-break-word">
|
||||
{workOrder.wo_description}
|
||||
</p>
|
||||
}
|
||||
|
||||
{/* Toggle button - full width on mobile */}
|
||||
<Button variant='secondary' size="sm" onClick={() => setIsOpen((v) => !v)} className="w-full sm:w-auto mt-4 sm:ml-16">
|
||||
<ChevronDown
|
||||
className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
{isOpen ? 'Hide details' : 'View details'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
{workOrder.wo_description &&
|
||||
<p className="text-sm text-muted-foreground mt-3 sm:mt-4 sm:ml-16 wrap-break-word">
|
||||
{workOrder.wo_description}
|
||||
</p>
|
||||
}
|
||||
{/* Expandable content */}
|
||||
{isOpen &&
|
||||
<div className="border-t border-border/60 bg-muted/10 p-4 sm:p-6 animate-fade-in">
|
||||
{workOrder.note &&
|
||||
<div className="mb-6 flex items-start gap-3 p-3 rounded-lg bg-amber-500/5 border border-amber-500/20">
|
||||
<StickyNote className="w-4 h-4 text-amber-400 shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<p className="font-semibold uppercase tracking-wider text-amber-400 mb-0.5">Note</p>
|
||||
<p className="text-sm text-foreground/90">{workOrder.note}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
{/* Toggle button - full width on mobile */}
|
||||
<Button variant="outline" size="sm" onClick={() => setIsOpen((v) => !v)} className="w-full sm:w-auto mt-4 sm:ml-16">
|
||||
<ChevronDown
|
||||
className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
{isOpen ? 'Hide details' : 'View details'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Expandable content */}
|
||||
{isOpen &&
|
||||
<div className="border-t border-border/60 bg-muted/10 p-4 sm:p-6 animate-fade-in">
|
||||
{workOrder.note && (
|
||||
<div className="mb-6 flex items-start gap-3 p-3 rounded-lg bg-amber-500/5 border border-amber-500/20">
|
||||
<StickyNote className="w-4 h-4 text-amber-400 shrink-0 mt-0.5" />
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Status history */}
|
||||
<div>
|
||||
<p className="font-semibold uppercase tracking-wider text-amber-400 mb-0.5">Note</p>
|
||||
<p className="text-sm text-foreground/90">{workOrder.note}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className='flex items-center justify-between mb-6'>
|
||||
<div className="flex items-center gap-3 sm:gap-4">
|
||||
<History className="w-5 h-5" />
|
||||
<div>
|
||||
<h4 className="text-base font-bold text-foreground">Status History</h4>
|
||||
<p className="text-muted-foreground">
|
||||
{workOrder.project_assignment_status_detail.length} status changes
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button size='sm' onClick={() => { setAction('UPDATE_STATUS'); setSelectedData(workOrder) }}><IterationCcw /> Update Status</Button>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Status history */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<div className="w-8 h-8 rounded-lg bg-linear-to-br from-primary/20 to-primary/10 flex items-center justify-center ring-1 ring-primary/20">
|
||||
<History className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-base font-bold text-foreground">Status History</h4>
|
||||
<p className="text-muted-foreground">
|
||||
{workOrder.project_assignment_status_detail.length} status changes
|
||||
</p>
|
||||
</div>
|
||||
<StatusTimeline history={workOrder.project_assignment_status_detail} />
|
||||
</div>
|
||||
<StatusTimeline history={workOrder.project_assignment_status_detail} />
|
||||
</div>
|
||||
|
||||
{/* Assigned people */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-6">
|
||||
<div className="w-8 h-8 rounded-lg bg-linear-to-br from-emerald-500/20 to-emerald-500/10 flex items-center justify-center ring-1 ring-emerald-500/20">
|
||||
<Users className="w-4 h-4 text-emerald-400" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-base font-bold text-foreground">Assigned People</h4>
|
||||
<p className="text-muted-foreground">Team members on this work order</p>
|
||||
{/* Assigned people */}
|
||||
<div>
|
||||
<div className='flex items-center justify-between mb-6'>
|
||||
<div className="flex items-center gap-3 sm:gap-4">
|
||||
<Users className="w-5 h-5" />
|
||||
<div>
|
||||
<h4 className="text-base font-bold text-foreground">Assigned People</h4>
|
||||
<p className="text-muted-foreground">Team members on this work order</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button size='sm' onClick={() => { setAction('MANAGE_EMPLOYEE'); setSelectedData(workOrder) }}><UserPlus /> Manage Team</Button>
|
||||
</div>
|
||||
<AssignedPeople people={workOrder.project_assignment_work_order_detail} />
|
||||
</div>
|
||||
<AssignedPeople people={workOrder.project_assignment_work_order_detail} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</Card900>
|
||||
|
||||
{action === 'UPDATE_STATUS' ?
|
||||
<FormUpdateStatus data={selectedData} title={selectedData?.wo_name!} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
</Card900>
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ?
|
||||
<ManageEmployee data={selectedData!} title={selectedData?.wo_name!} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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 }>
|
||||
|
||||
@@ -41,21 +41,20 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] }
|
||||
<TableHead>WO Start</TableHead>
|
||||
<TableHead>WO End</TableHead>
|
||||
<TableHead>Last Status</TableHead>
|
||||
<TableHead>Status Remarks</TableHead>
|
||||
<TableHead className="w-[50px]"></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.map((assignment, idx) => {
|
||||
const isProject = assignment.project?.code
|
||||
|
||||
return (
|
||||
<TableRow key={idx} className="hover:bg-accent/30">
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`client-detail/${assignment.project?.client?.id}`} className="hover:underline text-blue-500 hover:text-his">
|
||||
{assignment.project?.client?.name}
|
||||
<Link href={`/task/client-detail/${assignment.client.id}`} className="hover:underline text-blue-500 hover:text-his">
|
||||
{assignment.client?.name}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="font-bold text-primary">{assignment.project?.client?.end_user_name}</TableCell>
|
||||
<TableCell className="font-bold text-primary">{assignment.client?.end_user?.name}</TableCell>
|
||||
<TableCell className="font-medium">{assignment.im_name}</TableCell>
|
||||
<TableCell>{assignment.im_code || ''}</TableCell>
|
||||
<TableCell className="max-w-[300px] truncate" title={assignment.im_description}>
|
||||
@@ -69,7 +68,7 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] }
|
||||
{assignment.im_end_date ? new Date(assignment.im_end_date).toLocaleDateString() : ''}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`client-detail/${assignment.project?.client?.id}/project-detail/${assignment.project?.id}`} className='text-blue-500 hover:text-his duration-300'>
|
||||
<Link href={`/task/client-detail/${assignment.client?.id}/project-detail/${assignment.project?.id}`} className='text-blue-500 hover:text-his duration-300'>
|
||||
{assignment.project?.name}
|
||||
</Link>
|
||||
</TableCell>
|
||||
@@ -95,6 +94,9 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] }
|
||||
<TableCell>
|
||||
<BadgeStatus status={assignment.project?.status || assignment.project_status.name} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{assignment.project_assignment_status_detail[0].status_remarks}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -104,11 +106,11 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] }
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`client-detail/${assignment.project?.client?.id}/${assignment.id}`}>View Assignment Details</Link>
|
||||
<Link href={`/task/client-detail/${assignment.client?.id}/${assignment.id}`}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
{assignment.project?.code ?
|
||||
{assignment.project?.name ?
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`client-detail/${assignment.project?.client?.id}/project-detail/${assignment.project?.id}`}>View Project Details</Link>
|
||||
<Link href={`/task/client-detail/${assignment.client?.id}/project-detail/${assignment.project?.id}`}>View Project Details</Link>
|
||||
</DropdownMenuItem>
|
||||
:
|
||||
null
|
||||
|
||||
@@ -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<Props> = ({ }) => {
|
||||
const FilterComponent: FC<Props> = ({ hideStatus, hideSort }) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
@@ -75,28 +78,32 @@ const FilterComponent: FC<Props> = ({ }) => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<MultiSelect
|
||||
className='w-full sm:w-72 dark:bg-zinc-900'
|
||||
placeholder='Select status'
|
||||
value={currentStatus ? currentStatus.split(',') : []}
|
||||
onChange={handleStatusChange}
|
||||
options={STATUS_LIST.map((item) => ({ label: item, value: item }))}
|
||||
maxCount={1}
|
||||
/>
|
||||
{!hideStatus ?
|
||||
<MultiSelect
|
||||
className='w-full sm:w-72 dark:bg-zinc-900'
|
||||
placeholder='Select status'
|
||||
value={currentStatus ? currentStatus.split(',') : []}
|
||||
onChange={handleStatusChange}
|
||||
options={STATUS_LIST.map((item) => ({ label: item, value: item }))}
|
||||
maxCount={1}
|
||||
/> : null
|
||||
}
|
||||
</div>
|
||||
|
||||
<Select value={currentSort} onValueChange={handleSortChange}>
|
||||
<SelectTrigger className="w-full md:w-max bg-white dark:bg-zinc-900">
|
||||
<SelectValue placeholder="Sort by" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="default">Default</SelectItem>
|
||||
<SelectItem value="latest">Latest</SelectItem>
|
||||
<SelectItem value="oldest">Oldest</SelectItem>
|
||||
<SelectItem value="participants_desc">Most Participants</SelectItem>
|
||||
<SelectItem value="participants_asc">Fewest Participants</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{!hideSort ?
|
||||
<Select value={currentSort} onValueChange={handleSortChange}>
|
||||
<SelectTrigger className="w-full md:w-max bg-white dark:bg-zinc-900">
|
||||
<SelectValue placeholder="Sort by" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="default">Default</SelectItem>
|
||||
<SelectItem value="latest">Latest</SelectItem>
|
||||
<SelectItem value="oldest">Oldest</SelectItem>
|
||||
<SelectItem value="participants_desc">Most Participants</SelectItem>
|
||||
<SelectItem value="participants_asc">Fewest Participants</SelectItem>
|
||||
</SelectContent>
|
||||
</Select> : null
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||
@@ -62,15 +52,7 @@ export default function HomeTask({ currentView, currentQuery }: ShellProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search clients, projects, or work orders..."
|
||||
className="pl-10"
|
||||
defaultValue={currentQuery}
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<FilterComponent hideStatus={currentView === 'grid'} />
|
||||
|
||||
{showForm && <FormClient onCancel={() => setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />}
|
||||
</>
|
||||
|
||||
@@ -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<Props> = ({ title, onCancel, onSuccess }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Employee to Assign <span className='text-red-600 font-bold'>*</span></FormLabel>
|
||||
<FormControl>
|
||||
<MultiSelectCustomSelection options={mappedUsers} value={field.value} onChange={field.onChange} placeholder='Select user to assign'
|
||||
<MultiSelectCustomSelection options={mappedUsers} value={field.value} onChange={field.onChange} placeholder='Select user to assign' maxCount={3}
|
||||
// --- CUSTOM DROPDOWN OPTIONS ---
|
||||
renderOption={(option, isSelected) => {
|
||||
const user = option.originalData as IUser;
|
||||
return (
|
||||
<div className="flex items-center justify-between w-full py-1">
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-full border border-border' alt={user.fullname} src={user.avatar} />
|
||||
<LazyImage className='w-10 h-10 rounded-full border border-border' alt={user.fullname} src={user.avatar ? `${process.env.BASE_URL_IMG}/${user.avatar}` : '/assets/no-avatar.jpg'} />
|
||||
<div className="flex flex-col">
|
||||
<span className={`text-sm ${isSelected ? 'font-bold text-primary' : ''}`}>
|
||||
{user.fullname}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6">
|
||||
@@ -49,7 +40,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
{view === 'grid' ?
|
||||
<ClientGrid clients={filteredClients} assignments={allAssignments} />
|
||||
:
|
||||
<AssignmentTable data={flattenedAssignments} />
|
||||
<AssignmentTable data={filterAssignments} />
|
||||
}
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(),
|
||||
},
|
||||
];
|
||||
];
|
||||
@@ -78,7 +78,7 @@ export function ConfirmDeleteWithInput({ endpoint, title, titleButton, descripti
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<div className="mt-2 mb-6">
|
||||
<div className="mt-4 mb-8">
|
||||
<FormField control={form.control} name='name'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
|
||||
Reference in New Issue
Block a user