Files
hats-app/app/(dashboard)/task/component/FormUpdateStatus.tsx
T
Ichsan Kurniawan 78f48d783f Add client & assignment detail UI; update dev env
Introduce client and assignment detail pages and client-side components for the Task dashboard. Adds interactive ClientDetailComponent, AssignmentDetailComponent, page entries (server + dummy variants), project-assignment form, various UI components (AssignmentTable, ClientGrid, ManageEmployee, FormUpdateStatus, ConfirmDelete, LazyImage helper), types and a dummy data hook. Update app/(dashboard)/task/page.tsx to use the new components. Update .env.development to point to dev API endpoints, bump NEXT_PUBLIC_APP_VERSION to v1.2.0 and add NEXT_PUBLIC_S3_IMAGE_URL.
2026-04-16 22:38:26 +07:00

108 lines
5.4 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, STATUS_LIST } from '../type.assignment';
import { DatePicker } from '@/components/ui/datepicker';
import { Loader2 } from 'lucide-react';
const validationSchema = Yup.object().shape({
status: 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 form = useForm<FormDataType>({
resolver: yupResolver(validationSchema),
});
const onSubmit = async (payload: FormDataType) => {
setIsLoading(true);
}
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>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="grid gap-6 py-4">
<FormField control={form.control} name='status'
render={({ field }) => (
<FormItem>
<FormLabel>Kategori</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>
{STATUS_LIST.map((item, key: number) =>
<SelectItem value={item} key={key}>{item}</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-[100px]" {...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;