mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 10:06:28 +00:00
7892eda589
Refactor Assignment detail view and related team components to improve layout, UX and behaviour. Key changes:
- Added a backup of the previous AssignmentDetailComponent as AssignmentDetailComponent.old.tsx.
- Reworked AssignmentDetailComponent.tsx: simplified assignment fields, added LazyImage, formatDate helper, visual redesign (MetaTile, PartyCard), improved project context card and conditional badges/UI for IM vs Project, and minor status-list rendering tweaks.
- AssignedPeople.tsx: made team list collapsible with motion animations, added toggle button, defaultOpen prop, and preserved stacked avatars UI.
- page.tsx: adjusted project assignment fetch to use /project/{id} (commented previous query-based call).
- AddTeam.tsx: updated existingTeam type and filter logic to exclude already-assigned users when mapping candidates.
- ManageTeam.tsx: removed an unused import.
- UpdateTimelineStatus.tsx: removed some form libs, updated success/error toast messages and sort timeline rows before rendering.
- globals.css: added --type-memo and --type-wo CSS variables and minor variable tweaks.
These changes aim to improve clarity, consistency and interactivity of the assignment and team management UI.
199 lines
10 KiB
TypeScript
199 lines
10 KiB
TypeScript
import { useState, type FC } from 'react';
|
|
import {
|
|
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
|
} from "@/components/ui/alert-dialog"
|
|
import { Button } from '@/components/ui/button';
|
|
import { DatePicker } from '@/components/ui/datepicker';
|
|
import { Edit2, Loader2, Save, X } from 'lucide-react';
|
|
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
|
import { serverApiCall } from '@/lib/server-api';
|
|
import { toast } from 'sonner';
|
|
import { useRouter } from 'next/navigation';
|
|
import {
|
|
Table, TableBody, TableCell, TableHead, TableHeader, TableRow
|
|
} from "@/components/ui/table";
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import dayjs from 'dayjs';
|
|
|
|
export interface IProjectAssignmentTimeline {
|
|
id: number
|
|
end_date: any
|
|
start_date: any
|
|
project_assignment_status: ProjectAssignmentStatus
|
|
}
|
|
|
|
export interface ProjectAssignmentStatus {
|
|
id: number
|
|
name: string
|
|
remark: any
|
|
}
|
|
|
|
|
|
type Props = {
|
|
assignmentId: string | number
|
|
onClose?: VoidFunction
|
|
};
|
|
|
|
const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
|
const [editingId, setEditingId] = useState<number | null>(null);
|
|
const [draftData, setDraftData] = useState<any>({});
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
|
|
const { data: existTimeline, isLoading: isLoadingTimeline, mutate } = useFetchWithAxios(`project-assignment/status-detail/${assignmentId}`)
|
|
|
|
const router = useRouter()
|
|
|
|
const handleEdit = (row: IProjectAssignmentTimeline) => {
|
|
setEditingId(row.id);
|
|
|
|
setDraftData({
|
|
detailId: Number(row.id),
|
|
masterId: Number(row.project_assignment_status.id),
|
|
start_date_assign: row.start_date,
|
|
end_date_assign: row.end_date,
|
|
});
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
setIsSaving(true);
|
|
|
|
const submitPayload = {
|
|
"project_assignment_status_detail_id": Number(draftData.detailId),
|
|
"project_assignment_status_id": Number(draftData.masterId),
|
|
"start_date": draftData.start_date_assign ? new Date(draftData.start_date_assign).toISOString() : '',
|
|
"end_date": draftData.end_date_assign ? new Date(draftData.end_date_assign).toISOString() : '',
|
|
"note": draftData.note,
|
|
"remarks": draftData.note
|
|
}
|
|
|
|
console.log(submitPayload)
|
|
const res = await serverApiCall('PUT', `/project-assignment/status/${assignmentId}`, submitPayload)
|
|
|
|
setIsSaving(false);
|
|
if (res.success) {
|
|
toast.success('Status updated successfully')
|
|
handleSuccess!()
|
|
} else {
|
|
toast.error(`Fail to save status`, { description: `(${res.code || '-'}) ${res.message}` })
|
|
}
|
|
};
|
|
|
|
const handleDraftChange = (field: any, value: string) => {
|
|
setDraftData((prev: any) => ({ ...prev, [field]: value }));
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
setEditingId(null);
|
|
setDraftData({});
|
|
};
|
|
|
|
|
|
const handleSuccess = () => {
|
|
handleCancel()
|
|
mutate()
|
|
router.refresh()
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<AlertDialog open={true} >
|
|
<AlertDialogContent className="min-w-full md:min-w-max max-h-[90vh] overflow-y-auto">
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Update Status</AlertDialogTitle>
|
|
<AlertDialogDescription className='w-full sm:max-w-140'>
|
|
Update the timeline status for this assignment. You can also add a note or remark regarding this status change. This will help to keep track of the progress.
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<div className="rounded-md border bg-card overflow-x-auto my-3">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Status</TableHead>
|
|
<TableHead>Start Date</TableHead>
|
|
<TableHead>End Date</TableHead>
|
|
<TableHead className="text-right">Action</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{isLoadingTimeline ?
|
|
<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>
|
|
</TableRow>
|
|
:
|
|
existTimeline.length === 0 ?
|
|
<TableRow>
|
|
<TableCell colSpan={5} className="w-full h-32">
|
|
<div className="text-center text-muted-foreground flex flex-col items-center justify-center gap-2">
|
|
No team members have been added yet.<br />Create a team to get started with project assignments
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
:
|
|
existTimeline.sort((a: any, b: any) => a.id - b.id).map((row: IProjectAssignmentTimeline) => {
|
|
const isEditing = editingId === row.id;
|
|
const isOtherRowEditing = editingId !== null && editingId !== row.id;
|
|
|
|
return (
|
|
<TableRow key={row.id}>
|
|
<TableCell>
|
|
<BadgeStatus status={row.project_assignment_status.name} />
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{isEditing ?
|
|
<DatePicker date={draftData.start_date_assign as Date | undefined} setDate={(date) => handleDraftChange("start_date_assign", date as any)} />
|
|
:
|
|
<span className="text-sm">{row.start_date ? dayjs(row.start_date).format('MMM DD, YYYY') : null}</span>
|
|
}
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{isEditing ?
|
|
<DatePicker date={draftData.end_date_assign as Date | undefined} setDate={(date) => handleDraftChange("end_date_assign", date as any)} />
|
|
:
|
|
<span className="text-sm">{row.end_date ? dayjs(row.end_date).format('MMM DD, YYYY') : null}</span>
|
|
}
|
|
</TableCell>
|
|
|
|
<TableCell className="text-right">
|
|
<div className="flex justify-end gap-0.5">
|
|
{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>
|
|
</>
|
|
:
|
|
!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>
|
|
|
|
}
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
);
|
|
})
|
|
}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel onClick={onClose} disabled={isSaving}>Close</AlertDialogCancel>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default UpdateTimelineStatus; |