mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Add project detail UI and unified status badges
Introduce project detail screens and reusable status UI. Adds ProjectDetailComponent, WorkOrderCard, StatusTimeline, AssignedPeople, and a new BadgeStatus component with STATUS_BADGE_MAP and STATUS_LIST in badge.tsx to centralize status styling. Adds IProject type (type.project.ts) and project detail page routing. Update existing client/assignment views to use BadgeStatus, improve UI copy and link behavior (ExternalLink icon), handle nullable end dates in forms, include client_id in payload, and improve empty-state handling and descriptions. Misc: rename assignment page export, tweak form labels/placeholders, and small layout/UX refinements.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { Briefcase, Clock, Users, MoreVertical, Check, Calendar as CalendarIcon, LayoutGrid, Table as TableIcon } from 'lucide-react';
|
||||
import { Briefcase, Clock, Users, MoreVertical, Check, Calendar as CalendarIcon, LayoutGrid, Table as TableIcon, ExternalLink } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, Card900, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
@@ -18,6 +18,7 @@ import { IProjectAssignment } from '../../../type.assignment';
|
||||
import ManageEmployee from '../../../component/ManageEmployee';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import FormUpdateStatus from '../../../component/FormUpdateStatus';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
|
||||
interface Props {
|
||||
clientId: string;
|
||||
@@ -85,6 +86,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
const isProject = assignment.project.code
|
||||
|
||||
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
|
||||
@@ -93,26 +95,33 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
return (
|
||||
<motion.div key={assignment.id} initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }}>
|
||||
<Card900 key={assignment.id} className="group hover:border-primary/30 transition-all duration-300">
|
||||
<CardContent className="p-6">
|
||||
<CardContent className="py-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className={`w-12 h-12 rounded-xl flex items-center justify-center shrink-0 ${isProject ? 'bg-orange-500/10 text-orange-500' : 'bg-purple-500/10 text-purple-500'}`}>
|
||||
{isProject ? <Briefcase className="w-6 h-6" /> : <Clock className="w-6 h-6" />}
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-3 mb-1">
|
||||
<h3 className="font-bold text-xl">{assignment.project.name || assignment.im_name}</h3>
|
||||
<Badge variant={isProject ? 'default' : 'info'}>
|
||||
{assignmentType}
|
||||
</Badge>
|
||||
<Badge variant="outline" className={
|
||||
assignmentStatus === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
||||
assignmentStatus === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
||||
'text-orange-600 border-orange-200 bg-orange-50'
|
||||
}>
|
||||
{assignmentStatus}
|
||||
</Badge>
|
||||
</div>
|
||||
{isProject ?
|
||||
<Link href={`/task/client-detail/${clientId}/project-detail/${assignment.project.id}`}>
|
||||
<div className="flex items-center gap-3 mb-1">
|
||||
<div className='flex items-center gap-0 group-hover:gap-3 duration-300'>
|
||||
<h3 className="font-bold text-xl group-hover:underline duration-300 group-hover:text-his">{assignmentName}</h3>
|
||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover: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 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_code && (
|
||||
<p className="text-sm font-medium text-primary mb-1">
|
||||
@@ -158,7 +167,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
+{assignment.project_assignment_work_order_detail?.length - 3}
|
||||
</div>
|
||||
)}
|
||||
{!assignment.project_assignment_work_order_detail && <span>No employees assigned</span>}
|
||||
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && <span>No employees assigned</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -254,13 +263,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }:
|
||||
{assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : '-'}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="outline" className={
|
||||
assignment.status.name === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
||||
assignment.status.name === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
||||
'text-orange-600 border-orange-200 bg-orange-50'
|
||||
}>
|
||||
{assignment.status.name}
|
||||
</Badge>
|
||||
<BadgeStatus status={assignment.status.name} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
|
||||
@@ -17,7 +17,8 @@ export default async function ClientDetailPage({ params }: Props) {
|
||||
const { client_id } = await params;
|
||||
|
||||
const getClientById = fetchData(`/client/${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]);
|
||||
|
||||
|
||||
+10
-25
@@ -14,6 +14,7 @@ import { IClient } from '../../../types';
|
||||
import { IProjectAssignment } from '../../../type.assignment';
|
||||
import { useState } from 'react';
|
||||
import FormUpdateStatus from '../../../component/FormUpdateStatus';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
|
||||
interface Props {
|
||||
client: IClient | undefined;
|
||||
@@ -27,7 +28,6 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
const router = useRouter();
|
||||
|
||||
const isProject = assignment.project.code
|
||||
const title = isProject ? 'Project Detail' : 'Internal Memo Detail';
|
||||
|
||||
const assignmentType = isProject ? 'Project' : 'IM'
|
||||
const assignmentName = assignment.project.name || assignment.im_name
|
||||
@@ -58,17 +58,14 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
{/* Header */}
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6">
|
||||
<div className="space-y-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
<Button variant="ghost" size="sm" onClick={() => router.back()}
|
||||
className="p-0 h-auto hover:bg-transparent text-muted-foreground mb-2"
|
||||
onClick={() => router.back()}
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4 mr-1" />
|
||||
Back to {client?.name}
|
||||
</Button>
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-4xl font-bold tracking-tight">{title}</h1>
|
||||
<h1 className="text-4xl font-bold tracking-tight">Assignment Detail</h1>
|
||||
<Badge variant={isProject ? 'default' : 'info'} className="text-lg px-3 py-0">
|
||||
{assignmentType}
|
||||
</Badge>
|
||||
@@ -107,14 +104,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Current Status</Label>
|
||||
<div className="mt-1">
|
||||
<Badge variant="outline" className={cn(
|
||||
"px-3 py-1",
|
||||
assignmentStatus === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
||||
assignmentStatus === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
||||
'text-orange-600 border-orange-200 bg-orange-50'
|
||||
)}>
|
||||
{assignmentStatus}
|
||||
</Badge>
|
||||
<BadgeStatus status={assignmentStatus} className='px-3 py-1' />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
@@ -133,7 +123,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<Separator />
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Description</Label>
|
||||
<p className="mt-2 text-muted-foreground leading-relaxed">{assignmentDesc}</p>
|
||||
<p className="mt-2 text-muted-foreground leading-relaxed">{assignmentDesc ?? 'No description available for this assignment!'}</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
@@ -160,13 +150,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<div className="space-y-3 flex-1">
|
||||
<div className="flex items-center gap-3">
|
||||
<h3 className="text-xl font-bold">{assignment.wo_name}</h3>
|
||||
<Badge variant="outline" className={cn(
|
||||
assignment.status.name === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
||||
assignment.status.name === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
||||
'text-orange-600 border-orange-200 bg-orange-50'
|
||||
)}>
|
||||
{assignment.status.name || 'Active'}
|
||||
</Badge>
|
||||
<BadgeStatus status={assignment.project_status.name} />
|
||||
</div>
|
||||
<p className="text-muted-foreground text-sm">{assignment.wo_description}</p>
|
||||
<div className="flex flex-wrap gap-4 text-xs text-muted-foreground">
|
||||
@@ -189,9 +173,10 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
{/* WO Status History Mini-Timeline */}
|
||||
{assignment.project_assignment_status_detail && assignment.project_assignment_status_detail.length > 0 && (
|
||||
<div className="mt-6 pt-6 border-t">
|
||||
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">WO Status History</p>
|
||||
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">Team</p>
|
||||
<div className="space-y-4">
|
||||
{assignment.project_assignment_status_detail.map((history) => (
|
||||
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && <span className='text-muted-foreground'>No employees assigned</span>}
|
||||
{assignment.project_assignment_work_order_detail.map((history) => (
|
||||
<div key={history.id} className="flex gap-3 text-sm">
|
||||
<div className="w-2 h-2 rounded-full bg-primary mt-1.5 shrink-0" />
|
||||
<div>
|
||||
@@ -218,7 +203,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<Card900>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<History className="w-5 h-5 text-primary" /> {assignmentType} History
|
||||
<History className="w-5 h-5 text-primary" /> Assignment History
|
||||
</CardTitle>
|
||||
<CardDescription>Timeline of status changes</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
@@ -7,7 +7,7 @@ type Props = {
|
||||
params: Promise<{ client_id: string; assignment_id: string }>
|
||||
};
|
||||
|
||||
export default async function ProjectOrIMDetailPage({ params }: Props) {
|
||||
export default async function AssignmentDetailPage({ params }: Props) {
|
||||
const { client_id, assignment_id } = await params;
|
||||
|
||||
const getClientById = fetchData(`/client/${client_id}`)
|
||||
|
||||
+43
-14
@@ -41,7 +41,7 @@ export const assignmentSchema = yup.object({
|
||||
code: yup.string().required('Project code is required'),
|
||||
year: yup.string().required('Year is required'),
|
||||
startDate: yup.date().required('Start date is required'),
|
||||
endDate: yup.date().min(yup.ref('startDate'), 'End date cannot be before start date').required('End date is required'),
|
||||
endDate: yup.date().nullable().min(yup.ref('startDate'), 'End date cannot be before start date').default(null),
|
||||
description: yup.string().optional().nullable().default(''),
|
||||
|
||||
// Work Orders Step (Conditional based on 'type')
|
||||
@@ -51,7 +51,7 @@ export const assignmentSchema = yup.object({
|
||||
name: yup.string().required('Work order name is required'),
|
||||
code: yup.string().required('Work order code is required'),
|
||||
startDate: yup.date().required('Start date is required'),
|
||||
endDate: yup.date().required('End date is required'),
|
||||
endDate: yup.date().nullable().default(null),
|
||||
description: yup.string().optional().nullable().default(''),
|
||||
}),
|
||||
otherwise: (schema) => schema.nullable().notRequired()
|
||||
@@ -104,7 +104,6 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
|
||||
const currentStepIndex = steps.findIndex(s => s.id === step);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEdit) return
|
||||
|
||||
@@ -171,6 +170,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
setIsLoading(true);
|
||||
|
||||
const newPayload = {
|
||||
"client_id": clientId,
|
||||
"im_code": assignmentType === 'IM' ? payload.code : isEdit ? existAssignment?.im_code : "",
|
||||
"im_name": assignmentType === 'IM' ? payload.name : isEdit ? existAssignment?.im_name : "",
|
||||
"im_year": assignmentType === 'IM' ? Number(payload.year) : isEdit ? existAssignment?.im_year : 2026,
|
||||
@@ -191,7 +191,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
"wo_start_date": (payload.workOrder as any).startDate ? dayjs((payload.workOrder as any).startDate).format('YYYY-MM-DD') : '',
|
||||
"wo_end_date": (payload.workOrder as any).endDate ? dayjs((payload.workOrder as any).endDate).format('YYYY-MM-DD') : '',
|
||||
"wo_description": (payload.workOrder as any).description,
|
||||
"wo_warranty": isEdit ? existAssignment?.wo_warranty : '2026-04-16',
|
||||
"wo_warranty": isEdit ? existAssignment?.wo_warranty : '',
|
||||
|
||||
"note": isEdit ? existAssignment?.note : "",
|
||||
}
|
||||
@@ -224,7 +224,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold">Create Project Assignment</h1>
|
||||
<h1 className="text-3xl font-bold">{isEdit ? 'Update' : 'Create Project'} Assignment</h1>
|
||||
<p className="text-muted-foreground">For {client.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -321,11 +321,11 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Assignment Name</FormLabel>
|
||||
<FormLabel>{assignmentType === 'Project' ? "Project" : "Internal Memo"} Name</FormLabel>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1 relative">
|
||||
<FormControl>
|
||||
<Input placeholder={assignmentType === 'Project' ? "Project Name" : "IM Name"} {...field} />
|
||||
<Input placeholder="e.g Software Development Sem 1 PO 4200049718..." {...field} />
|
||||
</FormControl>
|
||||
{assignmentType === 'Project' && (
|
||||
<div className="absolute right-2 top-1/2 -translate-y-1/2">
|
||||
@@ -403,7 +403,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<FormField control={form.control} name="endDate" disabled={isExistProject} render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>End Date</FormLabel>
|
||||
<DatePicker date={field.value} setDate={field.onChange} />
|
||||
<DatePicker date={field.value as Date | undefined} setDate={field.onChange} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
@@ -492,7 +492,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Type</Label>
|
||||
<div className="mt-1">
|
||||
<Badge variant={formValues.type === 'Project' ? 'default' : 'secondary'}>{formValues.type}</Badge>
|
||||
<Badge variant={formValues.type === 'Project' ? 'default' : 'info'}>{formValues.type}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
@@ -504,6 +504,24 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<Label className="text-xs text-muted-foreground uppercase">Name</Label>
|
||||
<p className="text-xl font-bold mt-1">{formValues.name || 'Untitled Assignment'}</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Code</Label>
|
||||
<p className="font-medium mt-1">{formValues.code || 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Year</Label>
|
||||
<p className="font-medium mt-1">{formValues.year || 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Start Date</Label>
|
||||
<p className="font-medium mt-1">{formValues.startDate ? dayjs(formValues.startDate).format('MMMM DD, YYYY') : 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">End Date</Label>
|
||||
<p className="font-medium mt-1">{formValues.endDate ? dayjs(formValues.endDate).format('MMMM DD, YYYY') : 'N/A'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Description</Label>
|
||||
<p className="text-muted-foreground mt-1">{formValues.description || 'No description provided.'}</p>
|
||||
@@ -514,13 +532,24 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<Separator />
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase mb-3 block">Work Order</Label>
|
||||
<div className="flex items-center gap-3 p-2 bg-accent/30 rounded-md">
|
||||
<div className="w-6 h-6 rounded-full bg-primary/10 text-primary flex items-center justify-center text-[10px] font-bold">
|
||||
1
|
||||
<div className="flex flex-col gap-5 p-5 bg-accent/30 rounded-md text-xs">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase">Name</Label>
|
||||
<p className="text-sm font-bold mt-1">{(formValues.workOrder as any).name || 'Untitled Work Order'} ({(formValues.workOrder as any).code})</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase mb-0.5">Start Date</Label>
|
||||
<p>{(formValues.workOrder as any).startDate ? dayjs((formValues.workOrder as any).startDate).format('MMMM DD, YYYY') : 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase mb-0.5">End Date</Label>
|
||||
<p>{(formValues.workOrder as any).endDate ? dayjs((formValues.workOrder as any).endDate).format('MMMM DD, YYYY') : 'N/A'}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">{(formValues.workOrder as any).name}</p>
|
||||
<p className="text-xs text-muted-foreground">{(formValues.workOrder as any).description}</p>
|
||||
<Label className="text-xs text-muted-foreground uppercase mb-0.5">Description</Label>
|
||||
<p className="text-muted-foreground">{(formValues.workOrder as any).description || 'No description provided.'}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
import { Mail, Phone, Calendar } from 'lucide-react';
|
||||
|
||||
interface AssignedPeopleProps {
|
||||
people: any[];
|
||||
}
|
||||
|
||||
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) => {
|
||||
if (people.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-8 text-sm text-muted-foreground bg-muted/20 rounded-lg border border-dashed border-border">
|
||||
No people assigned yet
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const formatDate = (date: string) =>
|
||||
new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Stacked avatars */}
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex -space-x-3">
|
||||
{people.slice(0, 5).map((person, i) => (
|
||||
<div
|
||||
key={person.id}
|
||||
className={`w-10 h-10 rounded-full bg-linear-to-br ${avatarGradients[i % avatarGradients.length]} ring-2 ring-background flex items-center justify-center text-xs font-bold text-white shadow-md hover:scale-110 hover:z-10 transition-transform`}
|
||||
title={person.name}
|
||||
>
|
||||
{getInitials(person.name)}
|
||||
</div>
|
||||
))}
|
||||
{people.length > 5 && (
|
||||
<div className="w-10 h-10 rounded-full bg-muted ring-2 ring-background flex items-center justify-center text-xs font-bold text-muted-foreground shadow-md">
|
||||
+{people.length - 5}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
<p className="font-semibold text-foreground">{people.length} People</p>
|
||||
<p className="text-xs text-muted-foreground">assigned to this work order</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detailed list */}
|
||||
<div className="space-y-2">
|
||||
{people.map((person, i) => (
|
||||
<div
|
||||
key={person.id}
|
||||
className="group flex items-center gap-3 p-3 rounded-xl bg-card/40 border border-border/60 hover:border-primary/40 hover:bg-card/80 transition-all"
|
||||
>
|
||||
<div
|
||||
className={`w-11 h-11 shrink-0 rounded-full bg-linear-to-br ${avatarGradients[i % avatarGradients.length]} flex items-center justify-center text-sm font-bold text-white shadow-md`}
|
||||
>
|
||||
{getInitials(person.name)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start gap-2 flex-wrap">
|
||||
<p className="text-sm font-semibold text-foreground truncate min-w-0">{person.name}</p>
|
||||
<span className="text-[10px] font-medium uppercase tracking-wider px-2 py-0.5 rounded bg-primary/10 text-primary ring-1 ring-primary/20 whitespace-nowrap">
|
||||
{person.role}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 mt-1 text-xs text-muted-foreground sm:flex-wrap min-w-0">
|
||||
<span className="inline-flex items-center gap-1 min-w-0">
|
||||
<Mail className="w-3 h-3 shrink-0" />
|
||||
<span className="truncate">{person.email}</span>
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<Phone className="w-3 h-3 shrink-0" />
|
||||
<span className="font-mono">{person.phone}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="hidden sm:flex flex-col items-end shrink-0">
|
||||
<span className="text-[10px] uppercase tracking-wider text-muted-foreground">
|
||||
Assigned
|
||||
</span>
|
||||
<span className="text-xs font-medium text-foreground inline-flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3" />
|
||||
{formatDate(person.assigned_date)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssignedPeople;
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
"use client"
|
||||
|
||||
import { motion } from 'motion/react';
|
||||
import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle } 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';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import FormUpdateStatus from '@/app/(dashboard)/task/component/FormUpdateStatus';
|
||||
import { IClient } from '@/app/(dashboard)/task/types';
|
||||
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
|
||||
import { IProject } from '@/app/(dashboard)/task/type.project';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
|
||||
interface Props {
|
||||
client: IClient | undefined;
|
||||
project: IProject;
|
||||
}
|
||||
|
||||
export default function ProjectDetailComponent({ client, project }: Props) {
|
||||
const [action, setAction] = useState<'ASSIGNMENT' | 'WO' | undefined>()
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>()
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const handleClose = () => {
|
||||
setSelectedData(undefined)
|
||||
setAction(undefined)
|
||||
}
|
||||
|
||||
const handleSuccess = () => {
|
||||
router.refresh()
|
||||
handleClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
className="flex-1 space-y-8 p-6 sm:p-8 pt-6"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6">
|
||||
<div className="space-y-1">
|
||||
<Button variant="ghost" size="sm" onClick={() => router.back()}
|
||||
className="p-0 h-auto hover:bg-transparent text-muted-foreground mb-2"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4 mr-1" />
|
||||
Back to {client?.name}
|
||||
</Button>
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-4xl font-bold tracking-tight">Project Detail</h1>
|
||||
<Badge variant='default' className="text-lg px-3 py-0">Project</Badge>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 mt-2">
|
||||
<h2 className="text-xl font-medium text-muted-foreground">{project.name}</h2>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-muted-foreground">
|
||||
<p className="flex items-center gap-1">
|
||||
<Briefcase className="w-4 h-4" /> Code: {project.code || 'N/A'}
|
||||
</p>
|
||||
<Separator orientation="vertical" className="h-4" />
|
||||
<p className="flex items-center gap-1">
|
||||
<Calendar className="w-4 h-4" /> Year: {project.year || 'N/A'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-8 lg:grid-cols-3">
|
||||
{/* Left Column: Details & Work Orders */}
|
||||
<div className="lg:col-span-2 space-y-8">
|
||||
{/* Overview Card */}
|
||||
<Card900>
|
||||
<CardHeader>
|
||||
<CardTitle>Overview</CardTitle>
|
||||
</CardHeader>
|
||||
<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>
|
||||
<div className="mt-1">
|
||||
<BadgeStatus status={project.status} className='px-3 py-1' />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Start Date</Label>
|
||||
<p className="font-medium mt-1">{project.start_date ? new Date(project.start_date).toLocaleDateString() : 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">End Date</Label>
|
||||
<p className="font-medium mt-1">{project.end_date ? new Date(project.end_date).toLocaleDateString() : 'N/A'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Client</Label>
|
||||
<p className="font-medium mt-1">{client?.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Separator />
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Description</Label>
|
||||
<p className="mt-2 text-muted-foreground leading-relaxed">{project.description ?? 'No description available for this project!'}</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card900>
|
||||
|
||||
{/* Work Orders Section */}
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-2xl font-bold flex items-center gap-2">
|
||||
<CheckCircle2 className="w-6 h-6 text-primary" /> Work Orders ({project.project_assignment.length})
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
{!project.project_assignment || project.project_assignment.length === 0 ?
|
||||
<Card className="border-dashed bg-accent/10">
|
||||
<CardContent className="py-10 text-center text-muted-foreground">
|
||||
No work orders defined for this assignment.
|
||||
</CardContent>
|
||||
</Card>
|
||||
:
|
||||
project.project_assignment.map((assignment, key) =>
|
||||
<div className="grid gap-4" key={key}>
|
||||
<Card900 className="overflow-hidden border-l-4 border-l-primary">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex flex-col md:flex-row justify-between gap-6">
|
||||
<div className="space-y-3 flex-1">
|
||||
<div className="flex items-center gap-3">
|
||||
<h3 className="text-xl font-bold">{assignment.wo_name}</h3>
|
||||
<BadgeStatus status={assignment.project_status.name} />
|
||||
</div>
|
||||
<p className="text-muted-foreground text-sm">{assignment.wo_description ?? 'No description available for this project!'}</p>
|
||||
<div className="flex flex-wrap gap-4 text-xs text-muted-foreground">
|
||||
<span className="flex items-center gap-1">
|
||||
<AlertCircle className="w-3 h-3" /> Code: {assignment.wo_code || 'N/A'}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3" />
|
||||
{assignment.wo_start_date ? new Date(assignment.wo_start_date).toLocaleDateString() : 'N/A'} - {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start">
|
||||
<Button variant="outline" size="sm" onClick={() => { setSelectedData(assignment); setAction('WO') }} className='gap-2'>
|
||||
<History className="w-4 h-4" />
|
||||
Update WO Status
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* WO Status History Mini-Timeline */}
|
||||
{assignment.project_assignment_status_detail && assignment.project_assignment_status_detail.length > 0 && (
|
||||
<div className="mt-6 pt-6 border-t">
|
||||
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">WO Status History</p>
|
||||
<div className="space-y-4">
|
||||
{assignment.project_assignment_status_detail.map((history) => (
|
||||
<div key={history.id} className="flex gap-3 text-sm">
|
||||
<div className="w-2 h-2 rounded-full bg-primary mt-1.5 shrink-0" />
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-bold">{history.status}</span>
|
||||
<span className="text-muted-foreground text-xs">{new Date(history.date_status_changed).toLocaleDateString()}</span>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs mt-0.5">{history.status_remarks}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card900>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
|
||||
{action === 'ASSIGNMENT' ?
|
||||
<FormUpdateStatus data={selectedData} title={`${project.name} (Project)`} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
|
||||
{action === 'WO' ?
|
||||
<FormUpdateStatus data={selectedData} title={`${selectedData?.wo_name} (Work Order)`} onCancel={handleClose} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { ProjectAssignmentStatusDetail } from '@/app/(dashboard)/task/type.assignment';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { Clock } from 'lucide-react';
|
||||
|
||||
interface StatusTimelineProps {
|
||||
history: ProjectAssignmentStatusDetail[];
|
||||
}
|
||||
|
||||
const StatusTimeline = ({ history }: StatusTimelineProps) => {
|
||||
const formatDate = (date: string) => {
|
||||
const d = new Date(date);
|
||||
return {
|
||||
date: d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }),
|
||||
time: d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }),
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
{/* Vertical connector line */}
|
||||
<div className="absolute left-[15px] top-2 bottom-2 w-px bg-linear-to-b from-primary/40 via-border to-transparent" />
|
||||
|
||||
<div className="space-y-5">
|
||||
{history.map((item, i) => {
|
||||
const { date, time } = formatDate(item.date_status_changed);
|
||||
const isLatest = i === history.length - 1;
|
||||
|
||||
return (
|
||||
<div key={item.id} className="relative flex items-start gap-4 group">
|
||||
{/* Dot */}
|
||||
<div className="relative z-10 shrink-0">
|
||||
<div className={`w-8 h-8 rounded-full flex items-center justify-center bg-linear-to-br from-zinc-700 to-zinc-500 dark:from-zinc-400 dark:to-zinc-600 ring-4 ring-background shadow-lg ${isLatest ? 'animate-pulse-slow' : ''}`}>
|
||||
<div className="w-2 h-2 rounded-full bg-white" />
|
||||
</div>
|
||||
{isLatest && <div className={`absolute inset-0 rounded-full bg-linear-to-br from-his to-yellow-700 blur-md opacity-60 -z-10`} />}
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="flex-1 min-w-0 pb-1">
|
||||
<div className="flex flex-wrap items-center gap-2 mb-1">
|
||||
<BadgeStatus status={item.status} />
|
||||
{isLatest && <span className="text-[10px] font-bold uppercase tracking-wider text-primary">Current</span>}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mb-1.5">
|
||||
<Clock className="w-3 h-3" />
|
||||
<span>{date}</span>
|
||||
<span className="opacity-50">·</span>
|
||||
<span className="font-mono">{time}</span>
|
||||
</div>
|
||||
{item.status_remarks &&
|
||||
<p className="text-sm text-foreground/80 bg-muted/30 rounded-md px-3 py-2 border border-border/50">
|
||||
{item.status_remarks}
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatusTimeline;
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
import { useState } from 'react';
|
||||
import { ChevronDown, Calendar, FileText, History, Users, StickyNote } 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';
|
||||
|
||||
interface WorkOrderCardProps {
|
||||
workOrder: IProjectAssignment;
|
||||
index: number;
|
||||
defaultOpen?: boolean;
|
||||
}
|
||||
|
||||
const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) => {
|
||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
||||
|
||||
const formatDate = (date: string) =>
|
||||
new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
|
||||
|
||||
return (
|
||||
<Card900 className="overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm hover:shadow-xl transition-all">
|
||||
{/* 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-primary 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-xs 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 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="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>
|
||||
<p className="text-xs 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="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Status history */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<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-sm font-bold text-foreground">Status History</h4>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{workOrder.project_assignment_status_detail.length} status changes
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<StatusTimeline history={workOrder.project_assignment_status_detail} />
|
||||
</div>
|
||||
|
||||
{/* Assigned people */}
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<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-sm font-bold text-foreground">Assigned People</h4>
|
||||
<p className="text-xs text-muted-foreground">Team members on this work order</p>
|
||||
</div>
|
||||
</div>
|
||||
<AssignedPeople people={workOrder.project_assignment_work_order_detail} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</Card900>
|
||||
);
|
||||
};
|
||||
|
||||
export default WorkOrderCard;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import ProjectDetailComponent from './ProjectDetailComponent';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string; project_id: string }>
|
||||
};
|
||||
|
||||
export default async function ProjectDetailPage({ params }: Props) {
|
||||
const { client_id, project_id } = await params;
|
||||
|
||||
const getClientById = fetchData(`/client/${client_id}`)
|
||||
const getAssignmentByProjectId = fetchData(`/project/${project_id}`)
|
||||
|
||||
const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]);
|
||||
|
||||
// 3. Handle 404 Securely on the server
|
||||
if (!project) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
|
||||
<h2 className="text-2xl font-bold">Project not found</h2>
|
||||
<Link href={`/task/client-detail/${client_id}`}>
|
||||
<Button variant="outline">Back to Client</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 4. Pass the fetched data to the interactive Client Component
|
||||
return (
|
||||
<ProjectDetailComponent client={client} project={project} />
|
||||
);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ const FormUpdateStatus: FC<Props> = ({ title, data, onCancel, onSuccess }) => {
|
||||
<FormField control={form.control} name='status'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Kategori</FormLabel>
|
||||
<FormLabel>Status</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={String(field.value)}>
|
||||
<FormControl>
|
||||
<SelectTrigger className='w-full'>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { IProjectAssignment } from "./type.assignment"
|
||||
|
||||
export interface IProject {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
client: any
|
||||
start_date: string
|
||||
end_date: string
|
||||
description: string
|
||||
year: number
|
||||
status: any
|
||||
project_assignment: IProjectAssignment[]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Badge, STATUS_BADGE_MAP } from "@/components/ui/badge"
|
||||
|
||||
export default function BadgeStatus({ status, className }: { status: string, className?: string }) { // e.g. status = "UAT"
|
||||
return (
|
||||
<Badge variant={STATUS_BADGE_MAP[status?.toLowerCase()] || "default"} className={className}>
|
||||
{status?.toLowerCase()
|
||||
.split(' ')
|
||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ')}
|
||||
</Badge>
|
||||
)
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export const STATUS_LIST = [
|
||||
"Not Started", "On Progress", "On Going", "Halted", "Issue",
|
||||
"SIT", "UAT", "PTR", "BAST", "Warranty", "End Of Support",
|
||||
"Canceled", "Active"
|
||||
] as const;
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
@@ -21,6 +27,16 @@ const badgeVariants = cva(
|
||||
warn: "border-transparent bg-yellow-500 text-zinc-50 dark:bg-yellow-500 dark:text-yellow-50 hover:opacity-80",
|
||||
info: "border-transparent bg-cyan-500 text-zinc-50 dark:bg-cyan-500 dark:text-cyan-50 hover:opacity-80",
|
||||
violet: "border-transparent bg-violet-500 text-zinc-50 dark:bg-violet-500 dark:text-violet-50 hover:opacity-80",
|
||||
|
||||
// --- CUSTOM STATUS VARIANTS ---
|
||||
statusNotStarted: "border-transparent bg-slate-500 text-zinc-50 hover:opacity-80", // Gray
|
||||
statusActive: "border-transparent bg-teal-500 text-zinc-50 hover:opacity-80", // Blue
|
||||
statusWarning: "border-transparent bg-amber-500 text-zinc-50 hover:opacity-80", // Yellow/Orange
|
||||
statusDanger: "border-transparent bg-red-500 text-zinc-50 hover:opacity-80", // Red
|
||||
statusTesting: "border-transparent bg-indigo-500 text-zinc-50 hover:opacity-80", // Indigo/Purple
|
||||
statusSuccess: "border-transparent bg-emerald-500 text-zinc-50 hover:opacity-80", // Green
|
||||
statusMaintenance: "border-transparent bg-blue-500 text-zinc-50 hover:opacity-80", // Teal
|
||||
statusEnded: "border-transparent bg-stone-500 text-zinc-50 hover:opacity-80", // Dark Gray/Brown
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
@@ -29,6 +45,29 @@ const badgeVariants = cva(
|
||||
}
|
||||
)
|
||||
|
||||
export const STATUS_BADGE_MAP: Record<string, VariantProps<typeof badgeVariants>["variant"]> = {
|
||||
"not started": "statusNotStarted",
|
||||
|
||||
"on progress": "statusActive",
|
||||
"on going": "statusActive",
|
||||
"active": "statusActive",
|
||||
|
||||
"halted": "statusWarning",
|
||||
|
||||
"issue": "statusDanger",
|
||||
"canceled": "statusDanger",
|
||||
|
||||
"sit": "statusTesting",
|
||||
"uat": "statusTesting",
|
||||
"ptr": "statusTesting",
|
||||
|
||||
"bast": "statusSuccess", // Handover/Sign-off
|
||||
|
||||
"warranty": "statusMaintenance",
|
||||
|
||||
"end of support": "statusEnded",
|
||||
}
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
|
||||
Reference in New Issue
Block a user