mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Add FilterModal and DatePickerMultiMode; UI fixes
Introduce a FilterModal component and a DatePickerMultiMode UI component; refactor FilterComponent to use the modal and expose new hide* props for finer control. Update HomeTask to use a Select for view switching and remove unused props. Improve client and assignment UIs: ClientGrid empty state, client card actions, AssignmentTable empty state, and various text/label adjustments. Fix PieChart null-safety with optional chaining and remove a stray console.log in ClientDetailComponent. Update assignment field mappings to prefer wo_* values where appropriate and pass hideCategory to project detail page. Also update .env.development API/IMG URLs.
This commit is contained in:
+1
-3
@@ -2,10 +2,8 @@ BASE_PATH = ""
|
||||
NEXT_PUBLIC_APP_URL="http://localhost:1209"
|
||||
|
||||
# BASE_URL_API = https://api-hats.hisnutech.my.id/api/v1
|
||||
# BASE_URL_IMG = https://api-hats.hisnutech.my.id/
|
||||
|
||||
BASE_URL_API = https://api-hats-dev.hisnutech.my.id/api/v1
|
||||
BASE_URL_IMG = https://api-hats-dev.hisnutech.my.id/
|
||||
BASE_URL_IMG = https://api-hats.hisnutech.my.id/
|
||||
|
||||
NEXTAUTH_URL = http://localhost:1209
|
||||
# NEXTAUTH_URL = http://localhost:7090/super-apps/api/auth
|
||||
|
||||
@@ -39,11 +39,11 @@ const PieChart: FC<Props> = ({ data }) => {
|
||||
}
|
||||
|
||||
if (selectedDataPoints.length > 0) {
|
||||
chart.toggleDataPointSelection(selectedDataPoints[0])
|
||||
chart?.toggleDataPointSelection(selectedDataPoints[0])
|
||||
}
|
||||
},
|
||||
mounted: (chart) => {
|
||||
chart.windowResizeHandler();
|
||||
chart?.windowResizeHandler();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -43,7 +43,6 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
handleClose()
|
||||
}
|
||||
|
||||
console.log(assignmentLists)
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
||||
@@ -73,8 +72,8 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<h3 className="text-xl font-semibold">No Project Assignments</h3>
|
||||
<p className="text-muted-foreground max-w-xs mx-auto mt-2">
|
||||
This client doesn't have any projects or internal memos yet. Create one to get started.
|
||||
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
||||
This client doesn't have any projects or internal memos yet. Try to change the filter or create one to get started.
|
||||
</p>
|
||||
</div>
|
||||
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
|
||||
@@ -87,13 +86,13 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
/* --- GRID VIEW --- */
|
||||
<div className="grid gap-4">
|
||||
{assignmentLists.map((assignment) => {
|
||||
const isProject = assignment.project?.code
|
||||
const isProject = assignment.wo_name
|
||||
|
||||
const assignmentType = isProject ? 'Project' : 'IM'
|
||||
const assignmentName = assignment.project?.name || assignment.im_name
|
||||
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 assignmentName = assignment.wo_name || assignment.im_name
|
||||
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date
|
||||
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date
|
||||
const assignmentDesc = assignment.wo_description || assignment.im_description
|
||||
const assignmentStatus = assignment.project?.status || assignment.project_status.name
|
||||
|
||||
return (
|
||||
@@ -107,29 +106,23 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
{isProject ? <Briefcase className="w-6 h-6" /> : <Clock className="w-6 h-6" />}
|
||||
</div>
|
||||
<div>
|
||||
{isProject ?
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-3 mb-1">
|
||||
<h3 className="font-bold text-xl">{assignmentName}</h3>
|
||||
{!isProject ? <Badge variant={'info'}>{assignmentType}</Badge> : null}
|
||||
<BadgeStatus status={assignmentStatus} />
|
||||
</div>
|
||||
|
||||
{assignment.wo_name &&
|
||||
<Link href={`${clientId}/project-detail/${assignment.project?.id}`} onClick={(e) => e.stopPropagation()}>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-3 mb-1 group/in">
|
||||
<div className='flex items-center gap-0 group-hover/in:gap-3 duration-300'>
|
||||
<h3 className="font-bold text-xl group-hover/in:underline duration-300 group-hover/in:text-his">{assignmentName}</h3>
|
||||
<p className="text-sm font-medium text-primary mb-1 group-hover/in:underline group-hover/in:text-his duration-300">Project Name: {assignment.project?.name}</p>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover/in:opacity-100 transition-opacity cursor-pointer">
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Badge variant={'default'}>{assignmentType}</Badge>
|
||||
<BadgeStatus status={assignmentStatus} />
|
||||
</div>
|
||||
</Link>
|
||||
:
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-3 mb-1">
|
||||
<h3 className="font-bold text-xl">{assignmentName}</h3>
|
||||
<Badge variant={'info'}>{assignmentType}</Badge>
|
||||
<BadgeStatus status={assignmentStatus} />
|
||||
</div>
|
||||
}
|
||||
|
||||
{assignment.wo_name &&
|
||||
<p className="text-sm font-medium text-primary mb-1">WO: {assignment.wo_name}</p>
|
||||
}
|
||||
|
||||
<p className="text-muted-foreground line-clamp-2 text-sm mb-4">{assignmentDesc}</p>
|
||||
|
||||
+4
-4
@@ -36,9 +36,9 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
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 assignmentStartDate = assignment.wo_start_date || assignment.im_start_date
|
||||
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date
|
||||
const assignmentDesc = assignment.wo_description || assignment.im_description
|
||||
const assignmentStatus = assignment.project?.status || assignment.project_status.name
|
||||
|
||||
const handleClose = () => {
|
||||
@@ -110,7 +110,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-6">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Current Status</Label>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Project Assignment Status</Label>
|
||||
<div className="mt-1">
|
||||
<BadgeStatus status={assignmentStatus} className='px-3 py-1' />
|
||||
</div>
|
||||
|
||||
@@ -262,7 +262,7 @@ export default async function ProjectDetailPage({ params, searchParams }: Props)
|
||||
</div>
|
||||
|
||||
<div className='mb-5'>
|
||||
<FilterComponent />
|
||||
<FilterComponent hideCategory />
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
{filterData() && filterData().length > 0 ? project.project_assignment.map((wo: any, i: number) =>
|
||||
|
||||
@@ -14,7 +14,12 @@ export default function AssignmentTable({ data }: { data: IProjectAssignment[] }
|
||||
if (data.length === 0) {
|
||||
return <Card className="py-12 text-center border-2 border-dashed rounded-xl">
|
||||
<BookOpenCheck className="w-12 h-12 mx-auto text-muted-foreground opacity-20" />
|
||||
<h3 className="text-lg font-medium">No project assignment found</h3>
|
||||
<div className="text-center">
|
||||
<h3 className="text-xl font-semibold">No Project Assignment Found</h3>
|
||||
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
||||
Try to change the filter or create one to get started.
|
||||
</p>
|
||||
</div>
|
||||
</Card>
|
||||
}
|
||||
|
||||
|
||||
@@ -29,144 +29,152 @@ export default function ClientGrid({ clients }: { clients: IClient[] }) {
|
||||
setShowSelectedData(undefined)
|
||||
}
|
||||
|
||||
if (clients.length === 0) {
|
||||
return (
|
||||
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
||||
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
||||
<h3 className="text-lg font-medium">No client found</h3>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{clients.map((client, i) => {
|
||||
const imCount = 0
|
||||
const projectCount = client.total_project;
|
||||
const woCount = client.total_work_order
|
||||
const userCount = client.total_user_assigned
|
||||
{clients.length === 0 ?
|
||||
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
||||
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
||||
<div className="text-center">
|
||||
<h3 className="text-xl font-semibold">No Client Found</h3>
|
||||
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
||||
Try to change the filter or create one to get started.
|
||||
</p>
|
||||
<Button variant="outline" className="mt-4" onClick={() => { setAction('EDIT'); setShowSelectedData(undefined) }}>Create New Client</Button>
|
||||
</div>
|
||||
</div> : null
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
key={client.id}
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ delay: i * 0.05 }}
|
||||
className="h-full"
|
||||
>
|
||||
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
||||
<CardContent className="p-0 flex flex-col h-full">
|
||||
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
alt={client.name}
|
||||
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
||||
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
||||
<div className="text-white">
|
||||
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
||||
<p className="text-xs opacity-80">{client.end_user_name}</p>
|
||||
{clients.length > 0 ?
|
||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{clients.map((client, i) => {
|
||||
const imCount = 0
|
||||
const projectCount = client.total_project;
|
||||
const woCount = client.total_work_order
|
||||
const userCount = client.total_user_assigned
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
key={client.id}
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ delay: i * 0.05 }}
|
||||
className="h-full"
|
||||
>
|
||||
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
||||
<CardContent className="p-0 flex flex-col h-full">
|
||||
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
||||
<LazyImage
|
||||
src={client.photo!}
|
||||
alt={client.name}
|
||||
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
||||
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
||||
<div className="text-white">
|
||||
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
||||
<p className="text-xs opacity-80">{client.end_user_name}</p>
|
||||
</div>
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
||||
<div className="space-y-2">
|
||||
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
||||
<div className="space-y-2">
|
||||
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
Currently managing a portfolio of <span className="font-bold text-foreground">{projectCount} projects</span> and <span className="font-bold text-foreground">{imCount} internal memos</span>.
|
||||
A dedicated team of <span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling <span className="font-bold text-foreground">{woCount} work orders</span> to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
||||
</p> */}
|
||||
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
{projectCount === 0 && imCount === 0 && woCount === 0 ?
|
||||
"No active projects, internal memos, or work orders recorded for this client yet."
|
||||
:
|
||||
<>
|
||||
{(projectCount! > 0 || imCount > 0) && (
|
||||
<>
|
||||
Currently managing a portfolio of{" "}
|
||||
{projectCount! > 0 &&
|
||||
<span className="font-bold text-foreground">{projectCount} project{projectCount! > 1 ? 's' : ''}</span>
|
||||
}
|
||||
{projectCount! > 0 && imCount > 0 && " and "}
|
||||
{imCount > 0 &&
|
||||
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
||||
}
|
||||
.{" "}
|
||||
</>
|
||||
)}
|
||||
{woCount! > 0 && (
|
||||
<>
|
||||
A dedicated team of{" "}
|
||||
<span className="font-bold text-foreground">{userCount} experts</span> is handling{" "}
|
||||
<span className="font-bold text-foreground">{woCount} work order{woCount! > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.end_user_name}</span>.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
||||
{projectCount === 0 && imCount === 0 && woCount === 0 ?
|
||||
"No active projects, internal memos, or work orders recorded for this client yet."
|
||||
:
|
||||
<>
|
||||
{(projectCount! > 0 || imCount > 0) && (
|
||||
<>
|
||||
Currently managing a portfolio of{" "}
|
||||
{projectCount! > 0 &&
|
||||
<span className="font-bold text-foreground">{projectCount} project{projectCount! > 1 ? 's' : ''}</span>
|
||||
}
|
||||
{projectCount! > 0 && imCount > 0 && " and "}
|
||||
{imCount > 0 &&
|
||||
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
||||
}
|
||||
.{" "}
|
||||
</>
|
||||
)}
|
||||
{woCount! > 0 && (
|
||||
<>
|
||||
A dedicated team of{" "}
|
||||
<span className="font-bold text-foreground">{userCount} experts</span> is handling{" "}
|
||||
<span className="font-bold text-foreground">{woCount} work order{woCount! > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.end_user_name}</span>.
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
||||
<div className="flex -space-x-2 overflow-hidden">
|
||||
{client.users?.slice(0, 5).map((user, key) => {
|
||||
return (
|
||||
<div key={key}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<LazyImage src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user?.avatar}` : '/assets/no-avatar.jpg'} alt={user?.fullname!} className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-xs font-bold">{user?.name}</p>
|
||||
<p className="text-[10px] opacity-80">{user?.position?.name}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
||||
<div className="flex -space-x-2 overflow-hidden">
|
||||
{client.users?.slice(0, 5).map((user, key) => {
|
||||
return (
|
||||
<div key={key}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<LazyImage src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user?.avatar}` : '/assets/no-avatar.jpg'} alt={user?.fullname!} className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-xs font-bold">{user?.name}</p>
|
||||
<p className="text-[10px] opacity-80">{user?.position?.name}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{client.users?.length! > 5 &&
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
||||
+{client.users?.length! - 5}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{client.users?.length! > 5 &&
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
||||
+{client.users?.length! - 5}
|
||||
</div>
|
||||
}
|
||||
{client.users?.length === 0 &&
|
||||
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
||||
}
|
||||
}
|
||||
{client.users?.length === 0 &&
|
||||
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 self-end">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<MoreHorizontal className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('EDIT') }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 self-end">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<MoreHorizontal className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('EDIT') }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</div> : null
|
||||
}
|
||||
|
||||
{action === 'EDIT' && <FormClient data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/client/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }}
|
||||
title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove client ${selectedData?.name} from our servers.`}
|
||||
titleButton={`I understand the consequences, delete this client`}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { MultiSelect } from '@/components/ui/multi-select'; // Assuming this is a custom component
|
||||
import { Search } from 'lucide-react';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { type FC, useEffect, useState } from 'react';
|
||||
@@ -9,20 +8,22 @@ import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import useDebounce from '@/hooks/useDebounce';
|
||||
import { STATUS_LIST } from '../data';
|
||||
import { FilterModal } from './FilterModal';
|
||||
|
||||
type Props = {
|
||||
hideStatus?: boolean
|
||||
hideStatus?: boolean;
|
||||
hideAssignedTo?: boolean;
|
||||
hideDateFilters?: boolean;
|
||||
hideCategory?: boolean;
|
||||
hideSort?: boolean
|
||||
};
|
||||
|
||||
const FilterComponent: FC<Props> = ({ hideStatus, hideSort }) => {
|
||||
const FilterComponent: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory, hideSort }) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const currentQuery = searchParams?.get('q') || '';
|
||||
const currentStatus = searchParams?.get('status');
|
||||
const currentSort = searchParams?.get('sort') || '';
|
||||
|
||||
const [searchText, setSearchText] = useState(currentQuery);
|
||||
@@ -41,18 +42,6 @@ const FilterComponent: FC<Props> = ({ hideStatus, hideSort }) => {
|
||||
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
}, [debouncedSearchText, pathname, router]); // Remove searchParams from dependency array to prevent infinite loops
|
||||
|
||||
const handleStatusChange = (val: any[]) => {
|
||||
const params = new URLSearchParams(searchParams!);
|
||||
|
||||
if (val && val.length > 0) {
|
||||
params.set('status', val.join(','));
|
||||
} else {
|
||||
params.delete('status');
|
||||
}
|
||||
|
||||
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
};
|
||||
|
||||
const handleSortChange = (val: string) => {
|
||||
const params = new URLSearchParams(searchParams!);
|
||||
|
||||
@@ -78,16 +67,7 @@ const FilterComponent: FC<Props> = ({ hideStatus, hideSort }) => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!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
|
||||
}
|
||||
<FilterModal hideStatus={hideStatus} hideAssignedTo={hideAssignedTo} hideDateFilters={hideDateFilters} hideCategory={hideCategory} />
|
||||
</div>
|
||||
|
||||
{!hideSort ?
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect, type FC } from 'react';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { format, parseISO } from 'date-fns';
|
||||
import { ListFilter } from 'lucide-react';
|
||||
import type { DateRange } from 'react-day-picker';
|
||||
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import {
|
||||
CardContent, CardDescription, CardFooter, CardHeader, CardTitle,
|
||||
} from "@/components/ui/card"
|
||||
import {
|
||||
Popover, PopoverContent, PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { DatePickerMultiMode } from '@/components/ui/datepicker-multi-mode';
|
||||
import { MultiSelect } from '@/components/ui/multi-select';
|
||||
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
|
||||
import { ProjectStatus } from '../type.assignment';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
|
||||
interface Props {
|
||||
hideStatus?: boolean;
|
||||
hideAssignedTo?: boolean;
|
||||
hideDateFilters?: boolean;
|
||||
hideCategory?: boolean;
|
||||
}
|
||||
|
||||
export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const { data: statusList } = useFetchWithAxios('/project-status');
|
||||
const { data: userList } = useFetchWithAxios('/user');
|
||||
|
||||
const [category, setCategory] = useState<string | undefined>();
|
||||
const [statusFilter, setStatusFilter] = useState<any[]>([]);
|
||||
const [assignedToFilter, setAssignedToFilter] = useState<any[]>([]);
|
||||
const [projectDate, setProjectDate] = useState<DateRange | undefined>();
|
||||
const [woDate, setWoDate] = useState<DateRange | undefined>();
|
||||
const [imDate, setImDate] = useState<DateRange | undefined>();
|
||||
|
||||
// Set initial filter if values exist in URL
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setCategory(searchParams?.get('category') || undefined);
|
||||
|
||||
const statusParam = searchParams?.get('status');
|
||||
console.log(statusParam)
|
||||
setStatusFilter(statusParam ? statusParam.split(',') : []);
|
||||
|
||||
const assignedToParam = searchParams?.get('users');
|
||||
setAssignedToFilter(assignedToParam ? assignedToParam.split(',') : []);
|
||||
|
||||
const parseDateRange = (prefix: string): DateRange | undefined => {
|
||||
const fromStr = searchParams?.get(`${prefix}_from`);
|
||||
const toStr = searchParams?.get(`${prefix}_to`);
|
||||
if (!fromStr) return undefined;
|
||||
return {
|
||||
from: parseISO(fromStr),
|
||||
to: toStr ? parseISO(toStr) : undefined
|
||||
};
|
||||
};
|
||||
|
||||
setProjectDate(parseDateRange('project_date'));
|
||||
setWoDate(parseDateRange('wo_date'));
|
||||
setImDate(parseDateRange('im_date'));
|
||||
}
|
||||
}, [open, searchParams]);
|
||||
|
||||
|
||||
const handleApplyFilters = () => {
|
||||
const params = new URLSearchParams(searchParams?.toString());
|
||||
|
||||
// Single string values
|
||||
if (category) params.set('category', category);
|
||||
else params.delete('category');
|
||||
|
||||
if (statusFilter.length > 0) params.set('status', statusFilter.join(','));
|
||||
else params.delete('status');
|
||||
|
||||
if (assignedToFilter.length > 0) params.set('users', assignedToFilter.join(','));
|
||||
else params.delete('users');
|
||||
|
||||
|
||||
// Helper to format DateRange into URL params
|
||||
const applyDateRangeToParams = (range: DateRange | undefined, prefix: string) => {
|
||||
if (range?.from) {
|
||||
params.set(`${prefix}_from`, format(range.from, 'yyyy-MM-dd'));
|
||||
if (range.to) {
|
||||
params.set(`${prefix}_to`, format(range.to, 'yyyy-MM-dd'));
|
||||
} else {
|
||||
params.delete(`${prefix}_to`);
|
||||
}
|
||||
} else {
|
||||
params.delete(`${prefix}_from`);
|
||||
params.delete(`${prefix}_to`);
|
||||
}
|
||||
};
|
||||
|
||||
applyDateRangeToParams(projectDate, 'project_date');
|
||||
applyDateRangeToParams(woDate, 'wo_date');
|
||||
applyDateRangeToParams(imDate, 'im_date');
|
||||
|
||||
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleClearFilters = () => {
|
||||
// Clear local state
|
||||
setCategory(undefined);
|
||||
setStatusFilter([]);
|
||||
setAssignedToFilter([]);
|
||||
setProjectDate(undefined);
|
||||
setWoDate(undefined);
|
||||
setImDate(undefined);
|
||||
|
||||
// Clear URL (or you can clear specific keys if you want to keep pagination params)
|
||||
router.replace(pathname!, { scroll: false });
|
||||
};
|
||||
|
||||
// Calculate active filter count for the badge
|
||||
const activeFilterCount = Array.from(searchParams!.keys()).filter(key =>
|
||||
['category', 'status', 'users', 'project_date_from', 'wo_date_from', 'im_date_from'].includes(key)
|
||||
).length;
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline" className='dark:bg-zinc-900'>
|
||||
<ListFilter className='mr-1' /> Filter
|
||||
<Badge variant='secondary' className="ml-2">{activeFilterCount}</Badge>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align='start' forceMount className='w-full sm:w-[380px] px-0'>
|
||||
<CardHeader>
|
||||
<CardTitle>Filter</CardTitle>
|
||||
<CardDescription>Apply filters to customize the data shown.</CardDescription>
|
||||
</CardHeader>
|
||||
<ScrollArea className='h-80'>
|
||||
<CardContent className='grid gap-4 py-5'>
|
||||
{!hideCategory ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Assignment Category</Label>
|
||||
<Select value={category} onValueChange={setCategory}>
|
||||
<SelectTrigger className='w-full'>
|
||||
<SelectValue placeholder="Select category" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="project">Project</SelectItem>
|
||||
<SelectItem value="im">Internal Memo (IM)</SelectItem>
|
||||
<SelectItem value="wo">Work Order (WO)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div> : null
|
||||
}
|
||||
{!hideStatus ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Status</Label>
|
||||
<MultiSelect
|
||||
placeholder='Select status'
|
||||
value={statusFilter}
|
||||
onChange={setStatusFilter}
|
||||
options={statusList && statusList.length > 0 ? statusList.map((item: ProjectStatus) => ({ label: item.name, value: String(item.id) })) : []}
|
||||
maxCount={1}
|
||||
/>
|
||||
</div> : null
|
||||
}
|
||||
{!hideDateFilters ?
|
||||
<>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Project Date</Label>
|
||||
<DatePickerMultiMode date={projectDate} setDate={(d) => setProjectDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Work Order Date</Label>
|
||||
<DatePickerMultiMode date={woDate} setDate={(d) => setWoDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>IM Date</Label>
|
||||
<DatePickerMultiMode date={imDate} setDate={(d) => setImDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
</> : null
|
||||
}
|
||||
{!hideAssignedTo ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Assigned To</Label>
|
||||
<MultiSelect
|
||||
placeholder='Select user to filter'
|
||||
value={assignedToFilter}
|
||||
onChange={setAssignedToFilter}
|
||||
options={userList && userList.length > 0 ? userList.map((item: IUser) => ({ label: item.name, value: String(item.id) })) : []}
|
||||
maxCount={1}
|
||||
/>
|
||||
</div> : null
|
||||
}
|
||||
</CardContent>
|
||||
</ScrollArea>
|
||||
<CardFooter className='flex justify-end gap-2'>
|
||||
<Button variant='outline' onClick={handleClearFilters}>
|
||||
Reset
|
||||
</Button>
|
||||
<Button onClick={handleApplyFilters}>
|
||||
Apply
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -3,19 +3,20 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
|
||||
import { Plus, Search, LayoutGrid, List } from 'lucide-react';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
// import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import FormClient from './FormClient';
|
||||
import FilterComponent from './FilterComponent';
|
||||
import {
|
||||
Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
|
||||
interface ShellProps {
|
||||
currentView: 'grid' | 'table';
|
||||
currentQuery: string;
|
||||
}
|
||||
|
||||
export default function HomeTask({ currentView, currentQuery }: ShellProps) {
|
||||
export default function HomeTask({ currentView }: ShellProps) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
@@ -40,19 +41,31 @@ export default function HomeTask({ currentView, currentQuery }: ShellProps) {
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Tabs value={currentView} onValueChange={handleTabChange} className="w-auto">
|
||||
{/* <Tabs value={currentView} onValueChange={handleTabChange} className="w-auto">
|
||||
<TabsList>
|
||||
<TabsTrigger value="grid" className="gap-2"><LayoutGrid className="w-4 h-4" /> Clients</TabsTrigger>
|
||||
<TabsTrigger value="table" className="gap-2"><List className="w-4 h-4" /> Assignments</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</Tabs> */}
|
||||
<Select value={currentView} onValueChange={handleTabChange}>
|
||||
<SelectTrigger className="w-full md:w-max bg-white dark:bg-zinc-900">
|
||||
<SelectValue placeholder="Show by" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectLabel>Show by</SelectLabel>
|
||||
<SelectItem value="grid">Clients</SelectItem>
|
||||
<SelectItem value="table">Project Assignment</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button className="gap-2" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4" /> Add Client
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FilterComponent hideStatus={currentView === 'grid'} />
|
||||
<FilterComponent hideDateFilters={currentView === 'grid'} />
|
||||
|
||||
{showForm && <FormClient onCancel={() => setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />}
|
||||
</>
|
||||
|
||||
@@ -32,7 +32,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6">
|
||||
|
||||
{/* The Shell manages the Search Input, Tabs, and "Add Client" Modal */}
|
||||
<HomeTask currentView={view} currentQuery={query} />
|
||||
<HomeTask currentView={view} />
|
||||
|
||||
{/* Render the correct view based on the URL */}
|
||||
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react";
|
||||
import { CalendarIcon } from "@radix-ui/react-icons";
|
||||
import { format } from "date-fns";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import type { Matcher, DateRange } from "react-day-picker";
|
||||
|
||||
// 1. Base props shared across all modes
|
||||
type BaseProps = {
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
disabledDate?: Matcher | Matcher[] | undefined;
|
||||
captionLayout?: "label" | "dropdown" | "dropdown-months" | "dropdown-years";
|
||||
formatDate?: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
// 2. Strict typings for each specific mode to avoid `any`
|
||||
export type DatePickerSingleProps = BaseProps & {
|
||||
mode?: "single";
|
||||
date: Date | undefined;
|
||||
setDate: (date: Date | undefined) => void;
|
||||
};
|
||||
|
||||
export type DatePickerMultipleProps = BaseProps & {
|
||||
mode: "multiple";
|
||||
date: Date[] | undefined;
|
||||
setDate: (date: Date[] | undefined) => void;
|
||||
};
|
||||
|
||||
export type DatePickerRangeProps = BaseProps & {
|
||||
mode: "range";
|
||||
date: DateRange | undefined;
|
||||
setDate: (date: DateRange | undefined) => void;
|
||||
};
|
||||
|
||||
export type DatePickerProps =
|
||||
| DatePickerSingleProps
|
||||
| DatePickerMultipleProps
|
||||
| DatePickerRangeProps;
|
||||
|
||||
export function DatePickerMultiMode(props: DatePickerProps) {
|
||||
const {
|
||||
placeholder,
|
||||
disabled,
|
||||
disabledDate,
|
||||
captionLayout,
|
||||
formatDate = "PPP",
|
||||
className
|
||||
} = props;
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
// Dynamic text rendering based on the active mode
|
||||
const renderTriggerText = () => {
|
||||
if (!props.date) return <span>{placeholder || "Pick a date"}</span>;
|
||||
|
||||
if (props.mode === "single" || !props.mode) {
|
||||
return format(props.date as Date, formatDate);
|
||||
}
|
||||
|
||||
if (props.mode === "multiple") {
|
||||
const dates = props.date as Date[];
|
||||
if (dates.length === 0) return <span>{placeholder || "Pick a date"}</span>;
|
||||
if (dates.length === 1) return format(dates[0], formatDate);
|
||||
if (dates.length <= 2) return dates.map(d => format(d, formatDate)).join(", ");
|
||||
return <span>{dates.length} dates selected</span>;
|
||||
}
|
||||
|
||||
if (props.mode === "range") {
|
||||
const rangeDate = props.date as DateRange;
|
||||
if (rangeDate.from) {
|
||||
if (rangeDate.to) {
|
||||
return (
|
||||
<>
|
||||
{format(rangeDate.from, formatDate)} - {format(rangeDate.to, formatDate)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return format(rangeDate.from, formatDate);
|
||||
}
|
||||
}
|
||||
|
||||
return <span>{placeholder || "Pick a date"}</span>;
|
||||
};
|
||||
|
||||
// Conditional Calendar rendering to appease react-day-picker strict types
|
||||
const renderCalendar = () => {
|
||||
const commonProps = {
|
||||
captionLayout: captionLayout || "dropdown",
|
||||
disabled: disabledDate,
|
||||
initialFocus: true,
|
||||
endMonth: new Date(2050, 11),
|
||||
};
|
||||
|
||||
if (props.mode === "multiple") {
|
||||
return (
|
||||
<Calendar
|
||||
{...commonProps}
|
||||
mode="multiple"
|
||||
selected={props.date}
|
||||
onSelect={props.setDate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (props.mode === "range") {
|
||||
return (
|
||||
<Calendar
|
||||
{...commonProps}
|
||||
mode="range"
|
||||
selected={props.date}
|
||||
onSelect={props.setDate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// Default to single
|
||||
return (
|
||||
<Calendar
|
||||
{...commonProps}
|
||||
mode="single"
|
||||
selected={props.date}
|
||||
defaultMonth={props.date}
|
||||
onSelect={(selectedDate) => {
|
||||
props.setDate(selectedDate);
|
||||
setOpen(false); // Only close automatically on single select mode
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant={"outline"} disabled={disabled}
|
||||
className={cn("w-full justify-start text-left font-normal", !props.date && "text-muted-foreground", className)}>
|
||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||
{renderTriggerText()}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
{renderCalendar()}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user