mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 11:16:28 +00:00
d61e424012
Consolidate and improve client/task UI and related forms: - Replace/rename modal components: use ManageTeam and UpdateTimelineStatus consistently (replace previous ManageEmployee/FormUpdateStatus imports/usages). - ClientDetail: update grid layout, add End User column in table view, guard status with optional chaining, adjust avatar size, and minor label tweaks. - Project/Assignment forms: add end_user_id to assignment schema and form, fetch end-users, integrate ComboboxCustomUI and lazy image rendering for end-user selection, allow creating end-user inline, and fix autofill mappings for project selection. Improve loading handling and payload construction for create/update flows. - Project assignments page: switch to fetching project list endpoint and pass correct project type to form. - WorkOrderCard & AssignmentDetail: optional chaining for status, use correct selected IDs for modals, and ensure ManageTeam receives real assignment id. - ManageTeam: update data shape (field renames: fullname, position, start_date, end_date, status strings), change PUT endpoint for updating assignment user, improve empty-state copy and avatar/fallback handling, adjust status select values. - UpdateTimelineStatus: remove unused form, adjust payload mapping, make dialog scrollable, tweak layout and textarea sizing. - AssignmentTable & ClientDetail table: adjust column widths, truncation classes, and use assignment.end_user where appropriate. - Small UX/cleanup: hide category filter on HomeTask, comment out end_user in FormClient, minor spacing/formatting cleanups, and a temporary console.log in page.tsx. These changes improve UI consistency, add explicit end-user handling across forms, harden status access with optional chaining, and align API usages and data shapes for team/status operations.
197 lines
10 KiB
TypeScript
197 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';
|
|
|
|
|
|
type Props = {
|
|
assignmentId: string | number
|
|
onClose?: VoidFunction
|
|
};
|
|
|
|
const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
|
|
const [editingId, setEditingId] = useState<string | 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: any) => {
|
|
setEditingId(row.id);
|
|
|
|
setDraftData({
|
|
start_date_assign: row.start_date_assign,
|
|
end_date_assign: row.end_date_assign,
|
|
"note": draftData.note,
|
|
"remarks": draftData.note
|
|
});
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
setIsSaving(true);
|
|
|
|
const submitPayload = {
|
|
"project_status_id": Number(draftData.id),
|
|
"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/${draftData.id}`, 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>Note/Remarks</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: any) => {
|
|
const isEditing = editingId === row.id;
|
|
const isOtherRowEditing = editingId !== null && editingId !== row.id;
|
|
|
|
return (
|
|
<TableRow key={row.id}>
|
|
<TableCell>
|
|
<BadgeStatus status={row.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_assign}</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_assign}</span>
|
|
}
|
|
</TableCell>
|
|
|
|
<TableCell>
|
|
{isEditing ?
|
|
<Textarea placeholder="Add a note about this status change..." className="min-h-20 w-60" value={draftData.note} onChange={(e) => handleDraftChange("note", e.target.value)} />
|
|
:
|
|
<span className="text-sm">{row.note}</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-blue-600 hover:text-blue-700 hover:bg-blue-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; |