diff --git a/src/components/Project/AssignRole.jsx b/src/components/Project/AssignRole.jsx index 46de8044..9f2a8e19 100644 --- a/src/components/Project/AssignRole.jsx +++ b/src/components/Project/AssignRole.jsx @@ -17,6 +17,16 @@ const schema = z.object({ .array(z.number()) .min(1, { message: "At least one employee must be selected" }), description: z.string().min(1, { message: "description required" }), + plannedTask: z.preprocess( + (val) => parseInt(val, 10), + z + .number({ + required_error: "Planned task is required", + invalid_type_error: "Planned task must be a number", + }) + .int() + .positive({ message: "Planned task must be a positive number" }) + ), }); const AssignRoleModel = ({ assignData, onClose }) => { @@ -45,6 +55,7 @@ const AssignRoleModel = ({ assignData, onClose }) => { defaultValues: { selectedEmployees: [], description: "", + plannedTask: "", }, resolver: (data) => { const validation = schema.safeParse(data); @@ -53,20 +64,16 @@ const AssignRoleModel = ({ assignData, onClose }) => { }, }); - const handleRoleChange = ( event ) => - { - reset() - setSelectedEmployees( [] ) + const handleRoleChange = (event) => { + reset(); + setSelectedEmployees([]); setSelectedRole(event.target.value); }; const filteredEmployees = selectedRole === "all" ? employees - : employees.filter((emp) => - String(emp.jobRoleId || "") === selectedRole - ); - + : employees.filter((emp) => String(emp.jobRoleId || "") === selectedRole); const handleEmployeeSelection = (employeeId, field) => { setSelectedEmployees((prevSelected) => { @@ -92,17 +99,18 @@ const AssignRoleModel = ({ assignData, onClose }) => { const onSubmit = async (data) => { const formattedData = { taskTeam: data.selectedEmployees, - plannedTask: parseInt(plannedTask, 10), + plannedTask: data.plannedTask, description: data.description, assignmentDate: new Date().toISOString(), workItemId: assignData?.workItem?.workItem.id, }; try { let response = await TasksRepository.assignTask(formattedData); - showToast( "Task Successfully Assigend", "success" ); - setSelectedEmployees([]) + showToast("Task Successfully Assigend", "success"); + setSelectedEmployees([]); + reset(); - onClose(); + onClose(); } catch (error) { showToast("something wrong", "error"); } @@ -113,7 +121,7 @@ const AssignRoleModel = ({ assignData, onClose }) => { }, [dispatch]); return ( -
- {[ - assignData?.building?.name, - assignData?.floor?.floorName, - assignData?.workArea?.areaName, - assignData?.workItem?.workItem?.activityMaster?.activityName, - ] - .filter(Boolean) - .map((item, index, array) => ( - - {item} - {index < array.length - 1 && ( - - )} - - ))} -
++ {[ + assignData?.building?.name, + assignData?.floor?.floorName, + assignData?.workArea?.areaName, + assignData?.workItem?.workItem?.activityMaster?.activityName, + ] + .filter(Boolean) + .map((item, index, array) => ( + + {item} + {index < array.length - 1 && ( + + )} + + ))} +
-