Replace FormUpdateStatus with timeline editor

Refactor status update UI: remove the old FormUpdateStatus component and introduce UpdateTimelineStatus (inline timeline editor with row-level editing, date pickers, and notes). Update imports/usages across client, assignment, project and work-order components to use the new component and adjust props (assignmentId/onClose). Also rename AddTeam usage to ManageTeam in the assignment detail. Add client description support: FormClient now includes a description field and textarea, and IClient type gains an optional description. Minor cleanup: remove stray comment in HomeTask/page.
This commit is contained in:
Ichsan Kurniawan
2026-04-26 23:26:48 +07:00
parent 461542cc1d
commit fa973a8722
10 changed files with 230 additions and 150 deletions
@@ -15,7 +15,7 @@ import { LazyImage } from '@/components/ui/lazy-image';
import { IProjectAssignment } from '../../../type.assignment';
import ManageEmployee from '../../../component/AddTeam';
import { useRouter } from 'next/navigation';
import FormUpdateStatus from '../../../component/FormUpdateStatus';
import FormUpdateStatus from '../../../component/UpdateTimelineStatus';
import BadgeStatus from '@/components/ui/badge-status';
import FilterComponent from '../../../component/FilterComponent';
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
@@ -13,11 +13,11 @@ import { useRouter } from 'next/navigation';
import { IClient } from '../../../types';
import { IProjectAssignment } from '../../../type.assignment';
import { useState } from 'react';
import FormUpdateStatus from '../../../component/FormUpdateStatus';
import FormUpdateStatus from '../../../component/UpdateTimelineStatus';
import BadgeStatus from '@/components/ui/badge-status';
import Link from 'next/link';
import ManageEmployee from '../../../component/AddTeam';
import AssignedPeople from '../project-detail/[project_id]/AssignedPeople';
import { ManageTeam } from '../../../component/ManageTeam';
interface Props {
client: IClient | undefined;
@@ -235,12 +235,12 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</motion.div>
{action === 'UPDATE_STATUS' ?
<FormUpdateStatus data={assignment} title={assignmentName} onCancel={handleClose} onSuccess={handleSuccess} />
<FormUpdateStatus assignmentId={1} onClose={handleClose} />
: null
}
{action === 'MANAGE_EMPLOYEE' ?
<ManageEmployee assignmentId={1} onCancel={handleClose} onSuccess={handleSuccess} />
<ManageTeam assignmentId={1} onClose={handleClose} />
: null
}
</>
@@ -10,7 +10,7 @@ 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 FormUpdateStatus from '@/app/(dashboard)/task/component/UpdateTimelineStatus';
import { IClient } from '@/app/(dashboard)/task/types';
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
import { IProject } from '@/app/(dashboard)/task/type.project';
@@ -9,7 +9,7 @@ import AssignedPeople from './AssignedPeople';
import BadgeStatus from '@/components/ui/badge-status';
import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment';
import { useRouter } from 'next/navigation';
import FormUpdateStatus from '@/app/(dashboard)/task/component/FormUpdateStatus';
import FormUpdateStatus from '@/app/(dashboard)/task/component/UpdateTimelineStatus';
import ManageEmployee from '@/app/(dashboard)/task/component/AddTeam';
interface WorkOrderCardProps {
@@ -19,10 +19,12 @@ import { LazyImage } from '@/components/ui/lazy-image';
import { Label } from '@/components/ui/label';
import { serverApiCall } from '@/lib/server-api';
import FormEndUser from './FormEndUser';
import { Textarea } from '@/components/ui/textarea';
const validationSchema = Yup.object().shape({
name: Yup.string().required(),
end_user_id: Yup.number().required(),
description: Yup.string().optional().default(''),
});
type FormDataType = Yup.InferType<typeof validationSchema>;
@@ -74,6 +76,7 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel }) => {
defaultValues: {
"name": data?.name || '',
"end_user_id": data?.end_user_id || undefined,
"description": data?.description || '',
},
});
@@ -194,6 +197,17 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel }) => {
</FormItem>
)}
/>
<FormField control={form.control} name='description'
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea {...field} placeholder='Describe a little about the client.' />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="flex flex-col gap-2">
<Label>Add Client Image</Label>
{/* Drop area */}
@@ -1,141 +0,0 @@
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 { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import * as Yup from 'yup'
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form";
import { yupResolver } from '@hookform/resolvers/yup';
import { useForm } from 'react-hook-form';
import { IProjectAssignment } from '../type.assignment';
import { DatePicker } from '@/components/ui/datepicker';
import { Loader2 } from 'lucide-react';
import { useFetchWithAxios } from '@/lib/axios/useFetch';
import { IStatus } from '../types';
import { Skeleton } from '@/components/ui/skeleton';
import { serverApiCall } from '@/lib/server-api';
import { toast } from 'sonner';
import dayjs from 'dayjs';
const validationSchema = Yup.object().shape({
project_status_id: Yup.string().required(),
date: Yup.date().required('Date is required'),
note: Yup.string().optional().default(''),
});
type FormDataType = Yup.InferType<typeof validationSchema>;
type Props = {
title: string
data?: IProjectAssignment
onCancel?: VoidFunction
onSuccess?: VoidFunction;
};
const FormUpdateStatus: FC<Props> = ({ title, data, onCancel, onSuccess }) => {
const [isLoading, setIsLoading] = useState(false)
const { data: statusList, isLoading: isLoadingStatus } = useFetchWithAxios('/project-assignment-status')
const form = useForm<FormDataType>({
resolver: yupResolver(validationSchema),
});
const onSubmit = async (payload: FormDataType) => {
setIsLoading(true);
const newPayload = {
"project_status_id": Number(payload.project_status_id),
"date": dayjs(payload.date).format('YYYY-MM-DD'),
"note": payload.note,
"remarks": payload.note
}
const res = await serverApiCall('PUT', `/project-assignment/status/${data?.id}`, newPayload)
setIsLoading(false)
if (res.success) {
toast.success('Client saved successfully')
onSuccess!()
} else {
toast.error(`Fail to save client`, { description: `(${res.code || '-'}) ${res.message}` })
}
}
return (
<>
<AlertDialog open={true} >
<AlertDialogContent className="max-w-md">
<AlertDialogHeader>
<AlertDialogTitle>Update Status</AlertDialogTitle>
<AlertDialogDescription>
Update the current status for <strong>{title}</strong>
</AlertDialogDescription>
</AlertDialogHeader>
{isLoadingStatus ?
<div className='space-y-2'>
<Skeleton className='h-10 w-full' />
<Skeleton className='h-10 w-full' />
<Skeleton className='h-10 w-full' />
<Skeleton className='h-10 w-full' />
<Skeleton className='h-10 w-full' />
</div>
:
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="grid gap-6 py-4">
<FormField control={form.control} name='project_status_id'
render={({ field }) => (
<FormItem>
<FormLabel>Status</FormLabel>
<Select onValueChange={field.onChange} defaultValue={String(field.value)}>
<FormControl>
<SelectTrigger className='w-full'>
<SelectValue placeholder="Select Status" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectGroup>
<SelectLabel>Status</SelectLabel>
{statusList.map((item: IStatus, key: number) =>
<SelectItem value={String(item.id)} key={key} className='capitalize'>{item.name}</SelectItem>
)}
</SelectGroup>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField control={form.control} name='date' render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Start Date</FormLabel>
<DatePicker date={field.value as Date} setDate={field.onChange} />
<FormMessage />
</FormItem>
)} />
<FormField control={form.control} name='note' render={({ field }) => (
<FormItem>
<FormLabel>Note / Remarks</FormLabel>
<FormControl>
<Textarea placeholder="Add a note about this status change..." className="min-h-25" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)} />
</div>
<AlertDialogFooter>
<AlertDialogCancel onClick={onCancel} disabled={isLoading}>Cancel</AlertDialogCancel>
<Button type='submit' disabled={isLoading}>{isLoading ? <Loader2 /> : null} Save Changes</Button>
</AlertDialogFooter>
</form>
</Form>
}
</AlertDialogContent>
</AlertDialog>
</>
);
}
export default FormUpdateStatus;
@@ -1,4 +1,3 @@
// app/clients/components/dashboard-shell.tsx
"use client"
import { useState } from 'react';
@@ -0,0 +1,208 @@
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';
const validationSchema = Yup.object().shape({
project_status_id: Yup.string().required(),
date: Yup.date().required('Date is required'),
note: Yup.string().optional().default(''),
});
type FormDataType = Yup.InferType<typeof validationSchema>;
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 form = useForm<FormDataType>({
resolver: yupResolver(validationSchema),
});
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.project_status_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">
<AlertDialogHeader>
<AlertDialogTitle>Update Status</AlertDialogTitle>
<AlertDialogDescription>
Update the timeline status for this assignment. You can also add a note or remark regarding this status change. This will help you keep track of the progress and any important information related to this assignment.
</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. 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-10" 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;
-1
View File
@@ -1,4 +1,3 @@
// app/clients/page.tsx
import { Suspense } from 'react';
import HomeTask from './component/HomeTask';
import ClientGrid from './component/ClientGrid';
+1
View File
@@ -10,6 +10,7 @@ export type IEndUser = {
export type IClient = {
id?: string;
name: string;
description?: string;
end_user_id?: number
photo?: string
code?: string