mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 16:46:29 +00:00
109 lines
5.4 KiB
TypeScript
109 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 } from '../type.assignment';
|
|
import { DatePicker } from '@/components/ui/datepicker';
|
|
import { Loader2 } from 'lucide-react';
|
|
import { STATUS_LIST } from '../data';
|
|
|
|
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>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>
|
|
{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; |