mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
Add admin status updates and modal polish
Adds a dedicated administration-status workflow across client, assignment, and project views, including a new UpdateAdministrationStatus modal and action entries in assignment menus. It also improves modal layout consistency, prioritizes project-assignment status badges in list/grid views, and expands badge variants for administration and technical lifecycle states.
This commit is contained in:
@@ -11,6 +11,7 @@ import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import FilterComponent from '../../../component/FilterComponent';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus';
|
||||
import { ManageTeam } from '../../../component/ManageTeam';
|
||||
import AssignmentGrid from '../../../component/project-assignment/AssignmentGrid';
|
||||
import AssignmentList from '../../../component/project-assignment/AssignmentList';
|
||||
@@ -26,7 +27,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
const urlLayout = searchParams?.get('layout') as 'grid' | 'list' | null;
|
||||
|
||||
const [viewMode] = useState<'grid' | 'list'>(urlLayout || 'list');
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'DELETE' | undefined>();
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | 'DELETE' | undefined>();
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>();
|
||||
|
||||
const activeLayout = urlLayout || viewMode;
|
||||
@@ -75,6 +76,10 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
setSelectedData(a);
|
||||
setAction('MANAGE_EMPLOYEE');
|
||||
}}
|
||||
onUpdateAdministrationStatus={(a) => {
|
||||
setSelectedData(a);
|
||||
setAction('UPDATE_ADMIN_STATUS');
|
||||
}}
|
||||
onUpdateStatus={(a) => {
|
||||
setSelectedData(a);
|
||||
setAction('UPDATE_STATUS');
|
||||
@@ -92,6 +97,10 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
setSelectedData(a);
|
||||
setAction('MANAGE_EMPLOYEE');
|
||||
}}
|
||||
onUpdateAdministrationStatus={(a) => {
|
||||
setSelectedData(a);
|
||||
setAction('UPDATE_ADMIN_STATUS');
|
||||
}}
|
||||
onUpdateStatus={(a) => {
|
||||
setSelectedData(a);
|
||||
setAction('UPDATE_STATUS');
|
||||
@@ -112,6 +121,18 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{action === 'UPDATE_ADMIN_STATUS' && selectedData ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={selectedData.id}
|
||||
assignment={selectedData}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{action === 'UPDATE_STATUS' && selectedData ? (
|
||||
<UpdateTechnicalStatus assignmentId={selectedData.id} onClose={handleClose} />
|
||||
) : null}
|
||||
|
||||
+34
-9
@@ -12,9 +12,10 @@
|
||||
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
ArrowLeft, Briefcase, Calendar, ChevronDown, Clock, ExternalLink, FileText,
|
||||
ArrowLeft, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText,
|
||||
FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -26,6 +27,7 @@ import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../.
|
||||
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
|
||||
import { ManageTeam } from '../../../component/ManageTeam';
|
||||
import UpdateTechnicalStatus from '../../../component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '../../../component/UpdateAdministrationStatus';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
interface Props {
|
||||
@@ -56,7 +58,8 @@ function formatSpan(start?: string | null, end?: string | null) {
|
||||
}
|
||||
|
||||
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>();
|
||||
const router = useRouter();
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>();
|
||||
const [showAllTeam, setShowAllTeam] = useState(false);
|
||||
const [teamView, setTeamView] = useState<'grid' | 'list'>('list');
|
||||
|
||||
@@ -142,13 +145,23 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={() => setAction('UPDATE_STATUS')}
|
||||
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
<div className="flex flex-col sm:flex-row gap-2.5 w-full md:w-auto">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
|
||||
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
|
||||
>
|
||||
<ClipboardCheck className="h-4 w-4 text-his" />
|
||||
Update Administration Status
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => setAction('UPDATE_STATUS')}
|
||||
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
|
||||
@@ -410,6 +423,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{action === 'UPDATE_ADMIN_STATUS' ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={assignment.id}
|
||||
assignment={assignment}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{action === 'UPDATE_STATUS' ? (
|
||||
<UpdateTechnicalStatus assignmentId={assignment.id} onClose={handleClose} />
|
||||
) : null}
|
||||
|
||||
+37
-13
@@ -5,6 +5,7 @@ import { motion, AnimatePresence, useReducedMotion } from 'motion/react';
|
||||
import {
|
||||
Calendar,
|
||||
ChevronDown,
|
||||
ClipboardCheck,
|
||||
History,
|
||||
IterationCcw,
|
||||
StickyNote,
|
||||
@@ -18,6 +19,7 @@ import AssignedPeople from './AssignedPeople';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
|
||||
import UpdateTimelineStatus from '@/app/(dashboard)/task/component/UpdateTechnicalStatus';
|
||||
import UpdateAdministrationStatus from '@/app/(dashboard)/task/component/UpdateAdministrationStatus';
|
||||
import { ManageTeam } from '@/app/(dashboard)/task/component/ManageTeam';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
||||
@@ -31,7 +33,7 @@ interface WorkOrderCardProps {
|
||||
|
||||
export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) {
|
||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>();
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>();
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>();
|
||||
const reduce = useReducedMotion();
|
||||
|
||||
@@ -231,18 +233,32 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
|
||||
title="Assignment Timeline"
|
||||
badgeText={`${statusList.length} stages`}
|
||||
action={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_STATUS');
|
||||
}}
|
||||
>
|
||||
<IterationCcw className="h-3.5 w-3.5 text-his" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_ADMIN_STATUS');
|
||||
}}
|
||||
>
|
||||
<ClipboardCheck className="h-3.5 w-3.5 text-his" />
|
||||
Update Admin Status
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_STATUS');
|
||||
}}
|
||||
>
|
||||
<IterationCcw className="h-3.5 w-3.5 text-his" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -293,6 +309,14 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
|
||||
</article>
|
||||
|
||||
{/* Modals */}
|
||||
{action === 'UPDATE_ADMIN_STATUS' && selectedData ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={selectedData.id}
|
||||
assignment={selectedData}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{action === 'UPDATE_STATUS' && selectedData ? (
|
||||
<UpdateTimelineStatus assignmentId={selectedData.id} onClose={handleClose} />
|
||||
) : null}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import {
|
||||
Edit2, Trash2, Save, X, Loader2, UserPlus
|
||||
Edit2, Trash2, Save, X, Loader2, UserPlus,
|
||||
UserGroup
|
||||
} from "lucide-react";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow
|
||||
@@ -114,182 +115,193 @@ export function ManageTeam({ assignmentId, onClose, startDate, endDate }: { assi
|
||||
return (
|
||||
<>
|
||||
<Dialog open={true} onOpenChange={(open) => { if (!open) onClose(); }}>
|
||||
<DialogContent className="min-w-full md:min-w-max max-h-[90vh] overflow-y-auto py-7">
|
||||
<div className="flex flex-col sm:flex-row justify-between gap-3 pr-6">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Manage Team</DialogTitle>
|
||||
<DialogDescription>
|
||||
Add team members and manage who is working on each project assignment.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Button size='sm' variant='outline' onClick={() => setShowAddTeamDialog(true)}><UserPlus className="h-4 w-4" /> Add Team</Button>
|
||||
<DialogContent className="min-w-full md:min-w-max p-0">
|
||||
<div className="border-b border-border/70 bg-muted/40 px-6 py-5">
|
||||
<div className="flex flex-col sm:flex-row justify-between gap-3 pr-6">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<UserGroup className="h-5 w-5 text-his" />
|
||||
Manage Team
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Add team members and manage who is working on each project assignment.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Button size='sm' variant='outline' onClick={() => setShowAddTeamDialog(true)}><UserPlus className="h-4 w-4" /> Add Team</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-md border bg-card overflow-x-auto my-5">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-75">Name</TableHead>
|
||||
<TableHead>Start Date</TableHead>
|
||||
<TableHead>End Date</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead className="text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{isLoading ?
|
||||
|
||||
<div className="px-6 py-5 max-h-[70vh] overflow-y-auto">
|
||||
<div className="rounded-md border bg-card overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="w-full space-y-3">
|
||||
<Skeleton className='h-10 w-full' />
|
||||
<Skeleton className='h-10 w-full' />
|
||||
<Skeleton className='h-10 w-full' />
|
||||
</TableCell>
|
||||
<TableHead className="w-75">Name</TableHead>
|
||||
<TableHead>Start Date</TableHead>
|
||||
<TableHead>End Date</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead className="text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
:
|
||||
existUserAssign.length === 0 ?
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{isLoading ?
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="w-full py-6">
|
||||
<div className="text-center text-muted-foreground flex flex-col items-center justify-center gap-4">
|
||||
No team members have been added yet.<br />Create a team to get started with project assignments
|
||||
<Button variant='outline' className="w-max" onClick={() => setShowAddTeamDialog(true)}><UserPlus /> Add Team</Button>
|
||||
</div>
|
||||
<TableCell colSpan={5} className="w-full space-y-3">
|
||||
<Skeleton className='h-10 w-full' />
|
||||
<Skeleton className='h-10 w-full' />
|
||||
<Skeleton className='h-10 w-full' />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
:
|
||||
existUserAssign.map((row: IProjectAssignmentAssignUserDetail) => {
|
||||
const isEditing = editingId === row.id;
|
||||
const isOtherRowEditing = editingId !== null && editingId !== row.id;
|
||||
existUserAssign.length === 0 ?
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="w-full py-6">
|
||||
<div className="text-center text-muted-foreground flex flex-col items-center justify-center gap-4">
|
||||
No team members have been added yet.<br />Create a team to get started with project assignments
|
||||
<Button variant='outline' className="w-max" onClick={() => setShowAddTeamDialog(true)}><UserPlus /> Add Team</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
:
|
||||
existUserAssign.map((row: IProjectAssignmentAssignUserDetail) => {
|
||||
const isEditing = editingId === row.id;
|
||||
const isOtherRowEditing = editingId !== null && editingId !== row.id;
|
||||
|
||||
return (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar className="h-9 w-9">
|
||||
<AvatarImage src={`${process.env.BASE_URL_IMG}/${row.user.avatar}`} alt={row.user.fullname} />
|
||||
<AvatarFallback>{row.user.fullname?.charAt(0)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex flex-col">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="font-medium text-sm leading-none">{row.user.fullname}</span>
|
||||
<Badge variant="secondary" className="ml-auto">{row.user.position?.name}</Badge>
|
||||
return (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar className="h-9 w-9">
|
||||
<AvatarImage src={`${process.env.BASE_URL_IMG}/${row.user.avatar}`} alt={row.user.fullname} />
|
||||
<AvatarFallback>{row.user.fullname?.charAt(0)}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex flex-col">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="font-medium text-sm leading-none">{row.user.fullname}</span>
|
||||
<Badge variant="secondary" className="ml-auto">{row.user.position?.name}</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground mt-1">{row.user.email}</span>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground mt-1">{row.user.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.start_date as Date | undefined} setDate={(date) => handleDraftChange("start_date", date as any)}
|
||||
disabledDate={(date: Date) => {
|
||||
// const assStartDate = startDate
|
||||
// const assEndDate = endDate
|
||||
|
||||
// return assStartDate ? (date <= new Date(assStartDate) || date > new Date(assEndDate)) : false;
|
||||
if (!startDate || !endDate) return false;
|
||||
|
||||
// 1. Normalize all dates to midnight (00:00:00) to strip out time differences
|
||||
const targetDate = new Date(date).setHours(0, 0, 0, 0);
|
||||
const minDate = new Date(startDate).setHours(0, 0, 0, 0);
|
||||
const maxDate = new Date(endDate).setHours(0, 0, 0, 0);
|
||||
|
||||
// 2. Disable if strictly BEFORE (<) the start date, or strictly AFTER (>) the end date
|
||||
return targetDate < minDate || targetDate > maxDate;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<span className="text-sm">{row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.end_date as Date | undefined} setDate={(date) => handleDraftChange("end_date", date as any)}
|
||||
disabledDate={(date: Date) => {
|
||||
// 1. Normalize the calendar date we are currently checking
|
||||
const targetDate = new Date(date).setHours(0, 0, 0, 0);
|
||||
|
||||
const assStartDate = startDate;
|
||||
const assEndDate = endDate;
|
||||
const userStartDate = draftData.start_date;
|
||||
|
||||
// 2. Check against the User's selected Start Date (if it exists)
|
||||
if (userStartDate) {
|
||||
const minUserDate = new Date(userStartDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate < minUserDate) return true; // Disable if before user's start date
|
||||
}
|
||||
|
||||
// 3. Check against the overall Assignment Start boundary (if it exists)
|
||||
if (assStartDate) {
|
||||
const minAssDate = new Date(assStartDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate < minAssDate) return true; // Disable if before assignment start limit
|
||||
}
|
||||
|
||||
// 4. Check against the overall Assignment End boundary (if it exists)
|
||||
if (assEndDate) {
|
||||
const maxAssDate = new Date(assEndDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate > maxAssDate) return true; // Disable if AFTER assignment end limit
|
||||
}
|
||||
|
||||
// If it passes all existing checks, it is a valid date!
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<span className="text-sm">{row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<Select value={draftData.status} onValueChange={(value) => handleDraftChange("status", value)}>
|
||||
<SelectTrigger className="h-8 w-32.5 dark:bg-zinc-950">
|
||||
<SelectValue placeholder="Select status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ACTIVE">Active</SelectItem>
|
||||
<SelectItem value="INACTIVE">In Active</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
:
|
||||
<Badge variant={row.status === "ACTIVE" ? 'statusActive' : "destructive"} className='inline-block lowercase first-letter:uppercase' >{row.status}</Badge>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-0.5">
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<>
|
||||
<Button variant="outline" className="h-10 w-10 text-green-600 hover:text-green-700 hover:bg-green-100" onClick={handleSave} disabled={isSaving}>
|
||||
{isSaving ? <Loader2 className=" animate-spin" /> : <Save className="" />}
|
||||
</Button>
|
||||
<Button variant="outline" className="h-10 w-10" onClick={handleCancel} disabled={isSaving}>
|
||||
<X className="" />
|
||||
</Button>
|
||||
</>
|
||||
<DatePicker date={draftData.start_date as Date | undefined} setDate={(date) => handleDraftChange("start_date", date as any)}
|
||||
disabledDate={(date: Date) => {
|
||||
// const assStartDate = startDate
|
||||
// const assEndDate = endDate
|
||||
|
||||
// return assStartDate ? (date <= new Date(assStartDate) || date > new Date(assEndDate)) : false;
|
||||
if (!startDate || !endDate) return false;
|
||||
|
||||
// 1. Normalize all dates to midnight (00:00:00) to strip out time differences
|
||||
const targetDate = new Date(date).setHours(0, 0, 0, 0);
|
||||
const minDate = new Date(startDate).setHours(0, 0, 0, 0);
|
||||
const maxDate = new Date(endDate).setHours(0, 0, 0, 0);
|
||||
|
||||
// 2. Disable if strictly BEFORE (<) the start date, or strictly AFTER (>) the end date
|
||||
return targetDate < minDate || targetDate > maxDate;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
!isOtherRowEditing && (
|
||||
<span className="text-sm">{row.start_date ? dayjs(row.start_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<DatePicker date={draftData.end_date as Date | undefined} setDate={(date) => handleDraftChange("end_date", date as any)}
|
||||
disabledDate={(date: Date) => {
|
||||
// 1. Normalize the calendar date we are currently checking
|
||||
const targetDate = new Date(date).setHours(0, 0, 0, 0);
|
||||
|
||||
const assStartDate = startDate;
|
||||
const assEndDate = endDate;
|
||||
const userStartDate = draftData.start_date;
|
||||
|
||||
// 2. Check against the User's selected Start Date (if it exists)
|
||||
if (userStartDate) {
|
||||
const minUserDate = new Date(userStartDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate < minUserDate) return true; // Disable if before user's start date
|
||||
}
|
||||
|
||||
// 3. Check against the overall Assignment Start boundary (if it exists)
|
||||
if (assStartDate) {
|
||||
const minAssDate = new Date(assStartDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate < minAssDate) return true; // Disable if before assignment start limit
|
||||
}
|
||||
|
||||
// 4. Check against the overall Assignment End boundary (if it exists)
|
||||
if (assEndDate) {
|
||||
const maxAssDate = new Date(assEndDate).setHours(0, 0, 0, 0);
|
||||
if (targetDate > maxAssDate) return true; // Disable if AFTER assignment end limit
|
||||
}
|
||||
|
||||
// If it passes all existing checks, it is a valid date!
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<span className="text-sm">{row.end_date ? dayjs(row.end_date).format('DD MMM YYYY') : ''}</span>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{isEditing ?
|
||||
<Select value={draftData.status} onValueChange={(value) => handleDraftChange("status", value)}>
|
||||
<SelectTrigger className="h-8 w-32.5 dark:bg-zinc-950">
|
||||
<SelectValue placeholder="Select status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ACTIVE">Active</SelectItem>
|
||||
<SelectItem value="INACTIVE">In Active</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
:
|
||||
<Badge variant={row.status === "ACTIVE" ? 'statusActive' : "destructive"} className='inline-block lowercase first-letter:uppercase' >{row.status}</Badge>
|
||||
}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-0.5">
|
||||
{isEditing ?
|
||||
<>
|
||||
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEdit(row)}>
|
||||
<Edit2 className="size-3.5" />
|
||||
<Button variant="outline" className="h-10 w-10 text-green-600 hover:text-green-700 hover:bg-green-100" onClick={handleSave} disabled={isSaving}>
|
||||
{isSaving ? <Loader2 className=" animate-spin" /> : <Save className="" />}
|
||||
</Button>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeletedId(row.id)}>
|
||||
<Trash2 className="size-3.5" />
|
||||
<Button variant="outline" className="h-10 w-10" onClick={handleCancel} disabled={isSaving}>
|
||||
<X className="" />
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
}
|
||||
</TableBody>
|
||||
</Table>
|
||||
:
|
||||
!isOtherRowEditing && (
|
||||
<>
|
||||
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEdit(row)}>
|
||||
<Edit2 className="size-3.5" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeletedId(row.id)}>
|
||||
<Trash2 className="size-3.5" />
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pb-5 px-6">
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onClose} disabled={isSaving}>Close</Button>
|
||||
</DialogFooter>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onClose} disabled={isSaving}>Close</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo, useTransition } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { IProjectAssignment } from '../type.assignment';
|
||||
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
import { serverApiCall } from '@/lib/server-api';
|
||||
import { toast } from 'sonner';
|
||||
import {
|
||||
Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import { ClipboardCheck, Loader2 } from 'lucide-react';
|
||||
|
||||
export interface IMasterStatus {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
remark?: string | null;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
|
||||
interface UpdateAdministrationStatusProps {
|
||||
assignmentId?: number;
|
||||
assignment?: IProjectAssignment;
|
||||
onClose: () => void;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export default function UpdateAdministrationStatus({
|
||||
assignmentId: propAssignmentId,
|
||||
assignment,
|
||||
onClose,
|
||||
onSuccess,
|
||||
}: UpdateAdministrationStatusProps) {
|
||||
const router = useRouter();
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const effectiveId = propAssignmentId ?? assignment?.id;
|
||||
const assignmentName = assignment?.wo_name || assignment?.im_name || assignment?.project?.name || (effectiveId ? `Assignment #${effectiveId}` : 'Project Assignment');
|
||||
const assignmentCode = assignment?.wo_code || assignment?.im_code || assignment?.project?.code;
|
||||
|
||||
const { data: fetchedStatuses, isLoading: isLoadingStatuses } = useFetchWithAxios('/project-assignment-status?type=master');
|
||||
|
||||
const statusList: IMasterStatus[] = Array.isArray(fetchedStatuses) && fetchedStatuses.length > 0 ? fetchedStatuses : [];
|
||||
|
||||
const initialStatusId = useMemo(() => {
|
||||
if (assignment?.project_assignment_status?.id) {
|
||||
return String(assignment.project_assignment_status.id);
|
||||
}
|
||||
|
||||
if ((assignment as any)?.project_assignment_status_id) {
|
||||
return String((assignment as any).project_assignment_status_id);
|
||||
}
|
||||
|
||||
const currentName = assignment?.project_assignment_status?.name || (assignment as any)?.status?.name || (assignment as any)?.status;
|
||||
|
||||
if (currentName && statusList.length > 0) {
|
||||
const findStatus = statusList.find((s) => s.name?.toLowerCase().trim() === String(currentName).toLowerCase().trim());
|
||||
if (findStatus) return String(findStatus.id);
|
||||
}
|
||||
|
||||
if (statusList.length > 0 && statusList[0]?.id) {
|
||||
return String(statusList[0].id);
|
||||
}
|
||||
|
||||
return '';
|
||||
}, [assignment, statusList]);
|
||||
|
||||
const [selectedStatusId, setSelectedStatusId] = useState<string>(initialStatusId);
|
||||
const [description, setDescription] = useState<string>(assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '');
|
||||
|
||||
useEffect(() => {
|
||||
if (initialStatusId) {
|
||||
setSelectedStatusId(initialStatusId);
|
||||
}
|
||||
}, [initialStatusId]);
|
||||
|
||||
useEffect(() => {
|
||||
const initialRemark = assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '';
|
||||
setDescription(initialRemark);
|
||||
}, [assignment]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!effectiveId) {
|
||||
toast.error('Invalid assignment identifier');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedStatusId) {
|
||||
toast.error('Please select an administrative status');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const payload = {
|
||||
project_assignment_status_id: Number(selectedStatusId),
|
||||
remark: description.trim(),
|
||||
description: description.trim(),
|
||||
note: description.trim(),
|
||||
};
|
||||
|
||||
const res = await serverApiCall('PUT', `/project-assignment/status/${effectiveId}`, payload);
|
||||
|
||||
if (res.success) {
|
||||
toast.success('Administration status updated successfully');
|
||||
startTransition(() => {
|
||||
router.refresh();
|
||||
});
|
||||
onSuccess?.();
|
||||
onClose();
|
||||
} else {
|
||||
toast.error('Failed to update administration status', {
|
||||
description: res.message || 'An unexpected error occurred.',
|
||||
});
|
||||
}
|
||||
} catch (err: any) {
|
||||
toast.error('An error occurred while saving status', {
|
||||
description: err?.message || 'Please try again later.',
|
||||
});
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const isBusy = isSubmitting || isPending;
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(open) => !open && !isBusy && onClose()}>
|
||||
<DialogContent className="sm:max-w-120 p-0 overflow-hidden">
|
||||
{/* Modal Header */}
|
||||
<div className="border-b border-border/70 bg-muted/40 px-6 py-5">
|
||||
<DialogHeader className="space-y-1.5 text-left">
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<ClipboardCheck className="h-5 w-5 text-his" />
|
||||
Update Administration Status
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground">
|
||||
Update the overarching lifecycle stage and audit notes for{' '}
|
||||
<span className="font-semibold text-foreground">
|
||||
{assignmentName}
|
||||
</span>
|
||||
{assignmentCode &&
|
||||
<span className="ml-1 font-mono text-muted-foreground">
|
||||
(# {assignmentCode})
|
||||
</span>
|
||||
}
|
||||
.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
</div>
|
||||
|
||||
{/* Form Body */}
|
||||
<form onSubmit={handleSubmit} className="space-y-5 px-6 pb-5 pt-2">
|
||||
{/* Current Status Reference Card */}
|
||||
{assignment?.project_assignment_status?.name && (
|
||||
<div className="flex items-center justify-between rounded-lg border border-border/60 bg-muted/30 px-3.5 py-2.5 text-xs">
|
||||
<span className="text-muted-foreground font-medium">Current Status</span>
|
||||
<BadgeStatus status={assignment.project_assignment_status.name} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status Select Field */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label htmlFor="admin-status-select" className="text-xs font-semibold">
|
||||
New Administration Status <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
{isLoadingStatuses && (
|
||||
<span className="text-[11px] text-muted-foreground flex items-center gap-1">
|
||||
<Loader2 className="size-3 animate-spin" /> Loading options...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Select
|
||||
value={selectedStatusId}
|
||||
onValueChange={setSelectedStatusId}
|
||||
disabled={isBusy}
|
||||
>
|
||||
<SelectTrigger
|
||||
id="admin-status-select"
|
||||
className="w-full h-10 text-sm"
|
||||
>
|
||||
<SelectValue placeholder="Select administrative status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{statusList.map((status) => (
|
||||
<SelectItem
|
||||
key={status.id}
|
||||
value={String(status.id)}
|
||||
className="py-2 cursor-pointer"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-4 w-full">
|
||||
<span className="font-medium text-foreground">{status.name}</span>
|
||||
<BadgeStatus status={status.name} />
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Description / Notes Field */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label htmlFor="admin-status-description" className="text-xs font-semibold">
|
||||
Notes / Description
|
||||
</Label>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
{description.length} / 500
|
||||
</span>
|
||||
</div>
|
||||
<Textarea
|
||||
id="admin-status-description"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value.slice(0, 500))}
|
||||
placeholder="Add reason for status change, audit remarks, or handover notes..."
|
||||
className="min-h-26.25 text-sm leading-relaxed"
|
||||
disabled={isBusy}
|
||||
/>
|
||||
<p className="text-[11px] text-muted-foreground leading-normal">
|
||||
This description will be recorded as audit trail notes for this assignment.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Modal Footer */}
|
||||
<DialogFooter className="gap-2 sm:gap-2 pt-2 border-t border-border/60">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
disabled={isBusy}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isBusy || !selectedStatusId}
|
||||
className="w-full sm:w-auto bg-his text-white hover:bg-his/90 gap-1.5 shadow-sm font-medium"
|
||||
>
|
||||
{isBusy ? (
|
||||
<>
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
Updating...
|
||||
</>
|
||||
) : (
|
||||
'Save Status'
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -452,131 +452,135 @@ const UpdateTechnicalStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
||||
if (!open && onClose) onClose();
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-4xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader className="pr-6">
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<History className="h-5 w-5 text-his" />
|
||||
Update Technical Status
|
||||
</DialogTitle>
|
||||
<DialogDescription className="w-full sm:max-w-140">
|
||||
Manage timeline schedules and deliverable notes for each technical status. Multiple date intervals can be added to a single status.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="rounded-md border bg-card overflow-x-auto my-3">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-44">Status</TableHead>
|
||||
<TableHead className="min-w-80">Schedules & Notes</TableHead>
|
||||
<TableHead className="w-24 text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{isLoadingTimeline ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} className="w-full space-y-3 p-4">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : statusItems.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} className="w-full h-32 text-center text-muted-foreground">
|
||||
No technical statuses found.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
statusItems.map((item) => {
|
||||
const hasDates = item.dates.length > 0;
|
||||
|
||||
return (
|
||||
<TableRow key={item.technicalId}>
|
||||
{/* Status Column - Badge only */}
|
||||
<TableCell className="align-top py-3.5">
|
||||
<BadgeStatus status={item.statusName} />
|
||||
</TableCell>
|
||||
|
||||
{/* Schedules & Notes Column */}
|
||||
<TableCell className="align-top py-3">
|
||||
<div className="space-y-2">
|
||||
{hasDates ? (
|
||||
<div className="space-y-1.5">
|
||||
{item.dates.map((dateEntry, idx) => {
|
||||
const start = dateEntry.start_date ? dayjs(dateEntry.start_date) : null;
|
||||
const end = dateEntry.end_date ? dayjs(dateEntry.end_date) : null;
|
||||
const spanDays = start && end ? end.diff(start, 'day') + 1 : null;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-2 rounded-md bg-muted/30 border border-border/60 hover:bg-muted/40 transition-colors"
|
||||
>
|
||||
<div className="flex items-center gap-2 font-mono text-xs text-foreground min-w-0">
|
||||
<Calendar className="size-3.5 text-his shrink-0" />
|
||||
<span className="font-medium">
|
||||
{start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'}
|
||||
</span>
|
||||
{spanDays !== null && (
|
||||
<span className="font-sans text-[11px] text-muted-foreground">
|
||||
({spanDays} {spanDays === 1 ? 'day' : 'days'})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0 self-end sm:self-center">
|
||||
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEditExistingDate(item, idx)}>
|
||||
<Edit2 className="size-3.5" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeleteTarget({ item, index: idx, dateEntry })}>
|
||||
<Trash2 className="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground/70 italic py-1 block">
|
||||
No dates scheduled
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Description / Notes Display */}
|
||||
{item.description ? (
|
||||
<div className="rounded-md border border-border/40 bg-muted/20 px-2.5 py-1.5 text-xs text-muted-foreground leading-relaxed wrap-break-word italic">
|
||||
"{item.description}"
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* Action Column - Always Add button with HIS accent */}
|
||||
<TableCell className="align-top py-3 text-right">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-8 gap-1.5 text-xs border-border hover:bg-muted text-foreground"
|
||||
onClick={() => handleAddNewDate(item)}
|
||||
>
|
||||
<Plus className="size-3.5 text-his" />
|
||||
Add
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<DialogContent className="sm:max-w-4xl p-0">
|
||||
<div className="border-b border-border/70 bg-muted/40 px-6 py-5">
|
||||
<DialogHeader className="space-y-1.5 text-left">
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<History className="h-5 w-5 text-his" />
|
||||
Update Technical Status
|
||||
</DialogTitle>
|
||||
<DialogDescription className="w-full sm:max-w-140">
|
||||
Manage timeline schedules and deliverable notes for each technical status. Multiple date intervals can be added to a single status.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Close
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
<div className="px-6 py-5 max-h-[65vh] overflow-y-auto">
|
||||
<div className="rounded-md border bg-card overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-44">Status</TableHead>
|
||||
<TableHead className="min-w-80">Schedules & Notes</TableHead>
|
||||
<TableHead className="w-24 text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{isLoadingTimeline ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} className="w-full space-y-3 p-4">
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : statusItems.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={3} className="w-full h-32 text-center text-muted-foreground">
|
||||
No technical statuses found.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
statusItems.map((item) => {
|
||||
const hasDates = item.dates.length > 0;
|
||||
|
||||
return (
|
||||
<TableRow key={item.technicalId}>
|
||||
{/* Status Column - Badge only */}
|
||||
<TableCell className="align-top py-3.5">
|
||||
<BadgeStatus status={item.statusName} />
|
||||
</TableCell>
|
||||
|
||||
{/* Schedules & Notes Column */}
|
||||
<TableCell className="align-top py-3">
|
||||
<div className="space-y-2">
|
||||
{hasDates ? (
|
||||
<div className="space-y-1.5">
|
||||
{item.dates.map((dateEntry, idx) => {
|
||||
const start = dateEntry.start_date ? dayjs(dateEntry.start_date) : null;
|
||||
const end = dateEntry.end_date ? dayjs(dateEntry.end_date) : null;
|
||||
const spanDays = start && end ? end.diff(start, 'day') + 1 : null;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-2 rounded-md bg-muted/30 border border-border/60 hover:bg-muted/40 transition-colors"
|
||||
>
|
||||
<div className="flex items-center gap-2 font-mono text-xs text-foreground min-w-0">
|
||||
<Calendar className="size-3.5 text-his shrink-0" />
|
||||
<span className="font-medium">
|
||||
{start ? start.format('DD MMM YYYY') : 'TBD'} – {end ? end.format('DD MMM YYYY') : 'Present'}
|
||||
</span>
|
||||
{spanDays !== null && (
|
||||
<span className="font-sans text-[11px] text-muted-foreground">
|
||||
({spanDays} {spanDays === 1 ? 'day' : 'days'})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0 self-end sm:self-center">
|
||||
<Button variant="outline" className="h-8 w-8 text-teal-600 hover:text-teal-700 hover:bg-teal-100" onClick={() => handleEditExistingDate(item, idx)}>
|
||||
<Edit2 className="size-3.5" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100" onClick={() => setDeleteTarget({ item, index: idx, dateEntry })}>
|
||||
<Trash2 className="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground/70 italic py-1 block">
|
||||
No dates scheduled
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Description / Notes Display */}
|
||||
{item.description ? (
|
||||
<div className="rounded-md border border-border/40 bg-muted/20 px-2.5 py-1.5 text-xs text-muted-foreground leading-relaxed wrap-break-word italic">
|
||||
"{item.description}"
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* Action Column - Always Add button with HIS accent */}
|
||||
<TableCell className="align-top py-3 text-right">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-8 gap-1.5 text-xs border-border hover:bg-muted text-foreground"
|
||||
onClick={() => handleAddNewDate(item)}
|
||||
>
|
||||
<Plus className="size-3.5 text-his" />
|
||||
Add
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pb-5 px-6">
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ interface AssignmentGridProps {
|
||||
clientId?: string;
|
||||
onManageTeam?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
|
||||
onDelete?: (assignment: IProjectAssignment) => void;
|
||||
}
|
||||
|
||||
@@ -31,6 +32,7 @@ export default function AssignmentGrid({
|
||||
clientId,
|
||||
onManageTeam,
|
||||
onUpdateStatus,
|
||||
onUpdateAdministrationStatus,
|
||||
onDelete,
|
||||
}: AssignmentGridProps) {
|
||||
return (
|
||||
@@ -43,7 +45,7 @@ export default function AssignmentGrid({
|
||||
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
|
||||
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
|
||||
const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description;
|
||||
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name;
|
||||
const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status;
|
||||
|
||||
const illustrationSrc = isProject
|
||||
? '/assets/illustrations/work_order.jpg'
|
||||
@@ -144,6 +146,11 @@ export default function AssignmentGrid({
|
||||
Manage Team
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateAdministrationStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
|
||||
Update Administration Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
||||
Update Technical Status
|
||||
|
||||
@@ -32,6 +32,7 @@ interface AssignmentListProps {
|
||||
clientId?: string;
|
||||
onManageTeam?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
|
||||
onDelete?: (assignment: IProjectAssignment) => void;
|
||||
}
|
||||
|
||||
@@ -40,6 +41,7 @@ export default function AssignmentList({
|
||||
clientId,
|
||||
onManageTeam,
|
||||
onUpdateStatus,
|
||||
onUpdateAdministrationStatus,
|
||||
onDelete,
|
||||
}: AssignmentListProps) {
|
||||
return (
|
||||
@@ -51,11 +53,9 @@ export default function AssignmentList({
|
||||
const assignmentCode = assignment.wo_code || assignment.im_code || assignment.project?.code;
|
||||
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
|
||||
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
|
||||
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name;
|
||||
const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status;
|
||||
|
||||
const illustrationSrc = isProject
|
||||
? '/assets/illustrations/work_order.jpg'
|
||||
: '/assets/illustrations/internal_memo.jpg';
|
||||
const illustrationSrc = isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
|
||||
|
||||
const effectiveClientId = clientId || assignment.client?.id;
|
||||
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
|
||||
@@ -257,6 +257,11 @@ export default function AssignmentList({
|
||||
Manage Team
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateAdministrationStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
|
||||
Update Administration Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
||||
Update Technical Status
|
||||
|
||||
@@ -54,6 +54,8 @@ export interface Project {
|
||||
export interface ProjectStatus {
|
||||
id: string
|
||||
name: string
|
||||
remark?: string
|
||||
description?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user