mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Refactor team management & expand filters
Rename ManageEmployee to AddTeam and introduce a new ManageTeam component for listing/editing assignment team members. Update imports to use AddTeam and wire AddTeam into WorkOrder/Client pages. Enhance project assignment form payload to include end_user_id. Improve filtering by adding new props to FilterComponent/FilterModal (hideClient, hideEndUser, hideProjectDateFilter, hideWoDateFilter, hideImDateFilter, hideFilterModal) and implement client/end-user multi-selects and per-category date pickers. Adjust FilterModal layout widths and initial/clear/apply logic to set URL params for client/end_user. UX and API tweaks: switch user fetch to /user/active, change status endpoint to /project-assignment-status, replace multi-select with a Combobox in AddTeam, update textarea and popover sizing classes, and refine toast messages. Add ManageTeam modal with add/edit/delete flows and confirm-delete integration.
This commit is contained in:
@@ -13,7 +13,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import Link from 'next/link';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { IProjectAssignment } from '../../../type.assignment';
|
||||
import ManageEmployee from '../../../component/ManageEmployee';
|
||||
import ManageEmployee from '../../../component/AddTeam';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import FormUpdateStatus from '../../../component/FormUpdateStatus';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import { useState } from 'react';
|
||||
import FormUpdateStatus from '../../../component/FormUpdateStatus';
|
||||
import BadgeStatus from '@/components/ui/badge-status';
|
||||
import Link from 'next/link';
|
||||
import ManageEmployee from '../../../component/ManageEmployee';
|
||||
import ManageEmployee from '../../../component/AddTeam';
|
||||
import AssignedPeople from '../project-detail/[project_id]/AssignedPeople';
|
||||
|
||||
interface Props {
|
||||
|
||||
+4
-3
@@ -171,6 +171,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
|
||||
const newPayload = {
|
||||
"client_id": Number(clientId),
|
||||
"end_user_id": Number(client.end_user_id),
|
||||
"im_code": assignmentType === 'IM' ? payload.code : isEdit ? existAssignment?.im_code : "",
|
||||
"im_name": assignmentType === 'IM' ? payload.name : isEdit ? existAssignment?.im_name : "",
|
||||
"im_year": assignmentType === 'IM' ? Number(payload.year) : isEdit ? existAssignment?.im_year : 2026,
|
||||
@@ -337,7 +338,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<Search className="w-3 h-3 mr-1" /> Existing
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="p-0 w-[300px]" align="end">
|
||||
<PopoverContent className="p-0 w-75" align="end">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search existing projects..." />
|
||||
<CommandList>
|
||||
@@ -415,7 +416,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<FormItem>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea placeholder="Describe the scope..." className="min-h-[120px]" {...field} value={field.value || ''} />
|
||||
<Textarea placeholder="Describe the scope..." className="min-h-30" {...field} value={field.value || ''} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -468,7 +469,7 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is
|
||||
<FormField control={form.control} name={"workOrder.description" as any} render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>WO Description</FormLabel>
|
||||
<FormControl><Textarea placeholder="Briefly describe the task.." className="min-h-[120px]" {...field} value={field.value || ''} /></FormControl>
|
||||
<FormControl><Textarea placeholder="Briefly describe the task.." className="min-h-30" {...field} value={field.value || ''} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ 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 ManageEmployee from '@/app/(dashboard)/task/component/ManageEmployee';
|
||||
import ManageEmployee from '@/app/(dashboard)/task/component/AddTeam';
|
||||
|
||||
interface WorkOrderCardProps {
|
||||
workOrder: IProjectAssignment;
|
||||
|
||||
@@ -262,7 +262,7 @@ export default async function ProjectDetailPage({ params, searchParams }: Props)
|
||||
</div>
|
||||
|
||||
<div className='mb-5'>
|
||||
<FilterComponent hideCategory />
|
||||
<FilterComponent hideCategory hideProjectDateFilter hideImDateFilter />
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
{filterData() && filterData().length > 0 ? project.project_assignment.map((wo: any, i: number) =>
|
||||
|
||||
+25
-51
@@ -5,42 +5,37 @@ import {
|
||||
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
||||
} from "@/components/ui/alert-dialog"
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { CheckCircle, Loader2 } from 'lucide-react';
|
||||
import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
import { LazyImage } from '@/components/ui/lazy-image';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { IProjectAssignment } from '../type.assignment';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form";
|
||||
import * as Yup from 'yup'
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { serverApiCall } from '@/lib/server-api';
|
||||
import { toast } from 'sonner';
|
||||
import { DatePicker } from '@/components/ui/datepicker';
|
||||
import { MultiSelectCustomSelection } from '@/components/ui/multi-select-custom-ui';
|
||||
import dayjs from 'dayjs';
|
||||
import { Combobox } from '@/components/ui/combobox-custom-ui';
|
||||
|
||||
type Props = {
|
||||
data: IProjectAssignment
|
||||
title: string
|
||||
assignmentId: number;
|
||||
existingTeam?: number[];
|
||||
onCancel?: VoidFunction
|
||||
onSuccess?: VoidFunction;
|
||||
};
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
start_date: Yup.date().required('Start date is required'),
|
||||
end_date: Yup.date().nullable().min(Yup.ref('start_date'), 'End date cannot be before start date').default(null),
|
||||
users: Yup.array().of(Yup.number().required("Each item must be a number")).min(1, 'One user must be add').required()
|
||||
user: Yup.number().required('Please select at least one user'),
|
||||
});
|
||||
|
||||
type FormDataType = Yup.InferType<typeof validationSchema>;
|
||||
|
||||
|
||||
const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
const AddTeam: FC<Props> = ({ assignmentId, existingTeam, onCancel, onSuccess }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: userList, isLoading: isLoadingFetchUser } = useFetchWithAxios('/user')
|
||||
const { data: userList, isLoading: isLoadingFetchUser } = useFetchWithAxios('/user/active')
|
||||
|
||||
const form = useForm<FormDataType>({
|
||||
resolver: yupResolver(validationSchema),
|
||||
@@ -50,17 +45,13 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
const onSubmit = async (payload: FormDataType) => {
|
||||
setIsLoading(true);
|
||||
|
||||
const arrData = payload.users.map(item => (
|
||||
{
|
||||
"project_assignment_id": data.id,
|
||||
"user_id": item,
|
||||
"start_date": dayjs(payload.start_date).format('YYYY-MM-DD'),
|
||||
"end_date": dayjs(payload.end_date).format('YYYY-MM-DD')
|
||||
}
|
||||
))
|
||||
|
||||
const submitPayload = {
|
||||
data: arrData
|
||||
data: [{
|
||||
"project_assignment_id": assignmentId,
|
||||
"user_id": payload.user,
|
||||
"start_date": '',
|
||||
"end_date": ''
|
||||
}]
|
||||
}
|
||||
|
||||
console.log(submitPayload)
|
||||
@@ -68,10 +59,10 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
|
||||
setIsLoading(false)
|
||||
if (res.success) {
|
||||
toast.success('Client saved successfully')
|
||||
toast.success('New team added successfully')
|
||||
onSuccess!()
|
||||
} else {
|
||||
toast.error(`Fail to save client`, { description: `(${res.code || '-'}) ${res.message}` })
|
||||
toast.error(`Fail to save team`, { description: `(${res.code || '-'}) ${res.message}` })
|
||||
}
|
||||
};
|
||||
|
||||
@@ -81,7 +72,7 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
value: item.id,
|
||||
originalData: item
|
||||
})) || []
|
||||
}, [data])
|
||||
}, [userList])
|
||||
|
||||
|
||||
return (
|
||||
@@ -89,35 +80,33 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent className='max-h-[90vh] overflow-y-auto overflow-x-hidden'>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Manage Team</AlertDialogTitle>
|
||||
<AlertDialogTitle>Add Team</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Assign employees for <strong>{title}</strong>
|
||||
Assign new employees for project assignment.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<div className="grid gap-4 py-4 max-h-[400px] overflow-y-auto pr-2">
|
||||
<div className="grid gap-4 py-4 max-h-100 overflow-y-auto">
|
||||
{isLoadingFetchUser ?
|
||||
<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 grid-cols-1 gap-4 mb-6">
|
||||
<FormField control={form.control} name='users'
|
||||
<FormField control={form.control} name='user'
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Employee to Assign <span className='text-red-600 font-bold'>*</span></FormLabel>
|
||||
<FormControl>
|
||||
<MultiSelectCustomSelection options={mappedUsers} value={field.value} onChange={field.onChange} placeholder='Select user to assign' maxCount={3}
|
||||
<Combobox options={mappedUsers} value={field.value} onChange={field.onChange} placeholder='Select user to assign'
|
||||
// --- CUSTOM DROPDOWN OPTIONS ---
|
||||
renderOption={(option, isSelected) => {
|
||||
const user = option.originalData as IUser;
|
||||
return (
|
||||
<div className="flex items-center justify-between w-full py-1">
|
||||
<div className={`flex items-center justify-between w-full py-1 rounded-sm ${isSelected ? 'bg-zinc-800' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<LazyImage className='w-10 h-10 rounded-full border border-border' alt={user.fullname} src={user.avatar ? `${process.env.BASE_URL_IMG}/${user.avatar}` : '/assets/no-avatar.jpg'} />
|
||||
<div className="flex flex-col">
|
||||
@@ -125,11 +114,11 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
{user.fullname}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{user.role.name}
|
||||
{user.position?.name}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && <div className="h-4 w-4 bg-his rounded-full animate-pulse" />}
|
||||
{isSelected && <CheckCircle className="h-5 w-5 -translate-x-2" />}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
@@ -139,21 +128,6 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField control={form.control} name='start_date' render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Start Date</FormLabel>
|
||||
<DatePicker date={field.value} setDate={field.onChange} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
|
||||
<FormField control={form.control} name='end_date' render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>End Date</FormLabel>
|
||||
<DatePicker date={field.value as Date | undefined} setDate={field.onChange} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
</div>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={onCancel} disabled={isLoading} type='button'>Cancel</AlertDialogCancel>
|
||||
@@ -172,4 +146,4 @@ const ManageEmployee: FC<Props> = ({ data, title, onCancel, onSuccess }) => {
|
||||
);
|
||||
}
|
||||
|
||||
export default ManageEmployee;
|
||||
export default AddTeam;
|
||||
@@ -11,14 +11,19 @@ import useDebounce from '@/hooks/useDebounce';
|
||||
import { FilterModal } from './FilterModal';
|
||||
|
||||
type Props = {
|
||||
hideClient?: boolean
|
||||
hideEndUser?: boolean
|
||||
hideStatus?: boolean;
|
||||
hideAssignedTo?: boolean;
|
||||
hideDateFilters?: boolean;
|
||||
hideProjectDateFilter?: boolean;
|
||||
hideWoDateFilter?: boolean;
|
||||
hideImDateFilter?: boolean;
|
||||
hideCategory?: boolean;
|
||||
hideFilterModal?: boolean
|
||||
hideSort?: boolean
|
||||
};
|
||||
|
||||
const FilterComponent: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory, hideSort }) => {
|
||||
const FilterComponent: FC<Props> = ({ hideFilterModal, hideClient, hideEndUser, hideStatus, hideAssignedTo, hideProjectDateFilter, hideWoDateFilter, hideImDateFilter, hideCategory, hideSort }) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
@@ -67,7 +72,13 @@ const FilterComponent: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFilter
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FilterModal hideStatus={hideStatus} hideAssignedTo={hideAssignedTo} hideDateFilters={hideDateFilters} hideCategory={hideCategory} />
|
||||
{!hideFilterModal ?
|
||||
<FilterModal
|
||||
hideClient={hideClient} hideEndUser={hideEndUser}
|
||||
hideCategory={hideCategory} hideStatus={hideStatus} hideAssignedTo={hideAssignedTo}
|
||||
hideProjectDateFilter={hideProjectDateFilter} hideWoDateFilter={hideWoDateFilter} hideImDateFilter={hideImDateFilter} />
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
|
||||
{!hideSort ?
|
||||
|
||||
@@ -25,23 +25,32 @@ import { useFetchWithAxios } from '@/lib/axios/useFetch';
|
||||
|
||||
import { ProjectStatus } from '../type.assignment';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
import { IClient, IEndUser } from '../types';
|
||||
|
||||
interface Props {
|
||||
hideClient?: boolean
|
||||
hideEndUser?: boolean
|
||||
hideStatus?: boolean;
|
||||
hideAssignedTo?: boolean;
|
||||
hideDateFilters?: boolean;
|
||||
hideProjectDateFilter?: boolean;
|
||||
hideWoDateFilter?: boolean;
|
||||
hideImDateFilter?: boolean;
|
||||
hideCategory?: boolean;
|
||||
}
|
||||
|
||||
export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFilters, hideCategory }) => {
|
||||
export const FilterModal: FC<Props> = ({ hideClient = true, hideEndUser = true, hideStatus, hideAssignedTo, hideProjectDateFilter, hideWoDateFilter, hideImDateFilter, hideCategory }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const { data: statusList } = useFetchWithAxios('/project-status');
|
||||
const { data: userList } = useFetchWithAxios('/user');
|
||||
const { data: clientList } = useFetchWithAxios(!hideClient ? '/client' : null)
|
||||
const { data: endUserList } = useFetchWithAxios(!hideEndUser ? '/end-user' : null)
|
||||
const { data: statusList } = useFetchWithAxios(!hideStatus ? '/project-assignment-status' : null);
|
||||
const { data: userList } = useFetchWithAxios(!hideAssignedTo ? '/user' : null);
|
||||
|
||||
const [clientFilter, setClientFilter] = useState<any[]>([]);
|
||||
const [enduserFilter, setEnduserFilter] = useState<any[]>([]);
|
||||
const [category, setCategory] = useState<string | undefined>();
|
||||
const [statusFilter, setStatusFilter] = useState<any[]>([]);
|
||||
const [assignedToFilter, setAssignedToFilter] = useState<any[]>([]);
|
||||
@@ -52,10 +61,15 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
// Set initial filter if values exist in URL
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
const clientParam = searchParams?.get('client');
|
||||
setClientFilter(clientParam ? clientParam.split(',') : []);
|
||||
|
||||
const enduserParam = searchParams?.get('end_user');
|
||||
setEnduserFilter(enduserParam ? enduserParam.split(',') : []);
|
||||
|
||||
setCategory(searchParams?.get('category') || undefined);
|
||||
|
||||
const statusParam = searchParams?.get('status');
|
||||
console.log(statusParam)
|
||||
setStatusFilter(statusParam ? statusParam.split(',') : []);
|
||||
|
||||
const assignedToParam = searchParams?.get('users');
|
||||
@@ -81,6 +95,12 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
const handleApplyFilters = () => {
|
||||
const params = new URLSearchParams(searchParams?.toString());
|
||||
|
||||
if (clientFilter.length > 0) params.set('client', clientFilter.join(','));
|
||||
else params.delete('client');
|
||||
|
||||
if (endUserList.length > 0) params.set('end_user', endUserList.join(','));
|
||||
else params.delete('end_user');
|
||||
|
||||
// Single string values
|
||||
if (category) params.set('category', category);
|
||||
else params.delete('category');
|
||||
@@ -117,6 +137,8 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
|
||||
const handleClearFilters = () => {
|
||||
// Clear local state
|
||||
setClientFilter([]);
|
||||
setEnduserFilter([]);
|
||||
setCategory(undefined);
|
||||
setStatusFilter([]);
|
||||
setAssignedToFilter([]);
|
||||
@@ -141,13 +163,37 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
<Badge variant='secondary' className="ml-2">{activeFilterCount}</Badge>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align='start' forceMount className='w-full sm:w-[380px] px-0'>
|
||||
<PopoverContent align='start' forceMount className='w-full sm:w-95 px-0'>
|
||||
<CardHeader>
|
||||
<CardTitle>Filter</CardTitle>
|
||||
<CardDescription>Apply filters to customize the data shown.</CardDescription>
|
||||
</CardHeader>
|
||||
<ScrollArea className='h-80'>
|
||||
<CardContent className='grid gap-4 py-5'>
|
||||
{!hideClient ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Client</Label>
|
||||
<MultiSelect
|
||||
placeholder='Select client to filter'
|
||||
value={clientFilter}
|
||||
onChange={setClientFilter}
|
||||
options={clientList && clientList.length > 0 ? clientList.map((item: IClient) => ({ label: item.name, value: String(item.id) })) : []}
|
||||
maxCount={1}
|
||||
/>
|
||||
</div> : null
|
||||
}
|
||||
{!hideEndUser ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>End User</Label>
|
||||
<MultiSelect
|
||||
placeholder='Select end user to filter'
|
||||
value={enduserFilter}
|
||||
onChange={setEnduserFilter}
|
||||
options={endUserList && endUserList.length > 0 ? endUserList.map((item: IEndUser) => ({ label: item.name, value: String(item.id) })) : []}
|
||||
maxCount={1}
|
||||
/>
|
||||
</div> : null
|
||||
}
|
||||
{!hideCategory ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Assignment Category</Label>
|
||||
@@ -163,6 +209,27 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
</Select>
|
||||
</div> : null
|
||||
}
|
||||
{!hideProjectDateFilter && category === 'project' ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Project Date</Label>
|
||||
<DatePickerMultiMode date={projectDate} setDate={(d) => setProjectDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
{!hideWoDateFilter && category === 'wo' ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Work Order Date</Label>
|
||||
<DatePickerMultiMode date={woDate} setDate={(d) => setWoDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
{!hideImDateFilter && category === 'im' ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>IM Date</Label>
|
||||
<DatePickerMultiMode date={imDate} setDate={(d) => setImDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
{!hideStatus ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Status</Label>
|
||||
@@ -175,22 +242,6 @@ export const FilterModal: FC<Props> = ({ hideStatus, hideAssignedTo, hideDateFil
|
||||
/>
|
||||
</div> : null
|
||||
}
|
||||
{!hideDateFilters ?
|
||||
<>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Project Date</Label>
|
||||
<DatePickerMultiMode date={projectDate} setDate={(d) => setProjectDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Work Order Date</Label>
|
||||
<DatePickerMultiMode date={woDate} setDate={(d) => setWoDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>IM Date</Label>
|
||||
<DatePickerMultiMode date={imDate} setDate={(d) => setImDate(d as DateRange | undefined)} mode='range' />
|
||||
</div>
|
||||
</> : null
|
||||
}
|
||||
{!hideAssignedTo ?
|
||||
<div className='flex flex-col gap-2'>
|
||||
<Label>Assigned To</Label>
|
||||
|
||||
@@ -37,7 +37,7 @@ type Props = {
|
||||
const FormUpdateStatus: FC<Props> = ({ title, data, onCancel, onSuccess }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: statusList, isLoading: isLoadingStatus } = useFetchWithAxios('/project-status')
|
||||
const { data: statusList, isLoading: isLoadingStatus } = useFetchWithAxios('/project-assignment-status')
|
||||
const form = useForm<FormDataType>({
|
||||
resolver: yupResolver(validationSchema),
|
||||
});
|
||||
@@ -119,7 +119,7 @@ const FormUpdateStatus: FC<Props> = ({ title, data, onCancel, onSuccess }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Note / Remarks</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea placeholder="Add a note about this status change..." className="min-h-[100px]" {...field} />
|
||||
<Textarea placeholder="Add a note about this status change..." className="min-h-25" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -11,6 +11,7 @@ import FilterComponent from './FilterComponent';
|
||||
import {
|
||||
Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { ManageTeam } from './ManageTeam';
|
||||
|
||||
interface ShellProps {
|
||||
currentView: 'grid' | 'table';
|
||||
@@ -65,7 +66,9 @@ export default function HomeTask({ currentView }: ShellProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FilterComponent hideDateFilters={currentView === 'grid'} />
|
||||
<FilterComponent />
|
||||
|
||||
<ManageTeam onClose={() => console.log("dskjhdsjk")} />
|
||||
|
||||
{showForm && <FormClient onCancel={() => setShowForm(false)} onSuccess={() => { setShowForm(false); router.refresh() }} />}
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react";
|
||||
import {
|
||||
Edit2, Trash2, Save, X, Loader2, UserPlus
|
||||
} from "lucide-react";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow
|
||||
} from "@/components/ui/table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import {
|
||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue
|
||||
} from "@/components/ui/select";
|
||||
import { DatePicker } from "@/components/ui/datepicker";
|
||||
import BadgeStatus from "@/components/ui/badge-status";
|
||||
import {
|
||||
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
|
||||
} from "@/components/ui/alert-dialog"
|
||||
import AddTeam from "./AddTeam";
|
||||
import { useFetchWithAxios } from "@/lib/axios/useFetch";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { ConfirmDelete } from "@/components/modal/ConfirmDelete";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import { serverApiCall } from "@/lib/server-api";
|
||||
|
||||
|
||||
export type AssignmentStatus = "pending" | "in_progress" | "completed";
|
||||
|
||||
export interface ITableData {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar: string;
|
||||
position: string;
|
||||
start_date_assign: string;
|
||||
end_date_assign: string;
|
||||
status: AssignmentStatus;
|
||||
}
|
||||
|
||||
|
||||
export function ManageTeam({ assignmentId, onClose }: { assignmentId: number, onClose: VoidFunction }) {
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [draftData, setDraftData] = useState<Partial<ITableData>>({});
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [showAddTeamDialog, setShowAddTeamDialog] = useState(false);
|
||||
const [deletedId, setDeletedId] = useState<string | null>(null);
|
||||
|
||||
const { data: existUserAssign, isLoading, mutate } = useFetchWithAxios(`/project-assignment/assign-user/${assignmentId}`)
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const handleEdit = (row: ITableData) => {
|
||||
setEditingId(row.id);
|
||||
|
||||
setDraftData({
|
||||
start_date_assign: row.start_date_assign,
|
||||
end_date_assign: row.end_date_assign,
|
||||
status: row.status,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
|
||||
const submitPayload = {
|
||||
"project_assignment_id": assignmentId,
|
||||
"status": draftData.status,
|
||||
"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() : '',
|
||||
}
|
||||
|
||||
console.log(submitPayload)
|
||||
const res = await serverApiCall('PUT', `/project-assignment/assign-user/${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: keyof ITableData, value: string) => {
|
||||
setDraftData((prev) => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setEditingId(null);
|
||||
setDraftData({});
|
||||
setShowAddTeamDialog(false);
|
||||
setDeletedId(null)
|
||||
};
|
||||
|
||||
|
||||
const handleSuccess = () => {
|
||||
handleCancel()
|
||||
mutate()
|
||||
router.refresh()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<AlertDialog open={true} >
|
||||
<AlertDialogContent className="min-w-full md:min-w-max">
|
||||
<div className="flex flex-col sm:flex-row justify-between gap-3">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Manage Team</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Add team members and manage who is working on each project assignment.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<Button size='sm' variant='outline' onClick={() => setShowAddTeamDialog(true)}><UserPlus /> Add Team</Button>
|
||||
</div>
|
||||
<div className="rounded-md border bg-card overflow-x-auto my-3">
|
||||
<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 ?
|
||||
<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>
|
||||
:
|
||||
existUserAssign.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
|
||||
<Button variant='outline' className="w-max" onClick={() => setShowAddTeamDialog(true)}><UserPlus /> Add Team</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
:
|
||||
existUserAssign.map((row: ITableData) => {
|
||||
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={row.avatar} alt={row.name} />
|
||||
<AvatarFallback>{row.name.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.name}</span>
|
||||
<Badge variant="secondary" className="ml-auto">{row.position}</Badge>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground mt-1">{row.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
</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 ?
|
||||
<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="pending">Active</SelectItem>
|
||||
<SelectItem value="in_progress">In Active</SelectItem>
|
||||
<SelectItem value="completed">Completed</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
:
|
||||
<BadgeStatus status={row.status} />
|
||||
}
|
||||
</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>
|
||||
<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>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={onClose} disabled={isSaving}>Close</AlertDialogCancel>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{showAddTeamDialog ?
|
||||
<AddTeam assignmentId={assignmentId} existingTeam={existUserAssign} onCancel={() => setShowAddTeamDialog(false)} onSuccess={handleSuccess} />
|
||||
: null
|
||||
}
|
||||
|
||||
{deletedId ?
|
||||
<ConfirmDelete description="This action cannot be undone. This will permanently delete this user from this assignment." endpoint={`/project-assignment/assign-user/delete/${deletedId}`}
|
||||
onCancel={handleCancel} onSuccess={handleSuccess}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user