mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 11:36:28 +00:00
dcb74c0f2b
Introduce a reusable HoverCard component (components/ui/hover-card.tsx) and integrate it into the client grid to show a status summary with badges. Import the cn helper and BadgeStatus in ClientGrid, add a status pill trigger with animated indicator, and switch displayed client reference from end_user_name to client.name. In ManageTeam, include id in draftData, replace BadgeStatus rendering with a Badge variant and adjust the edit button colors to teal; the same teal edit-button color change was applied to UpdateTimelineStatus. Remove an unnecessary comment line in the task page. These changes improve status visibility and unify UI affordances.
203 lines
10 KiB
TypeScript
203 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 { Textarea } from '@/components/ui/textarea';
|
|
import * as Yup from 'yup'
|
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
import { useForm } from 'react-hook-form';
|
|
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('Team updated successfully')
|
|
handleSuccess!()
|
|
} else {
|
|
toast.error(`Fail to save team`, { 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.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; |