mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 11:06:29 +00:00
7b1541c567
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.
141 lines
7.0 KiB
TypeScript
141 lines
7.0 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 { 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; |