diff --git a/src/components/Project/AssignRole.jsx b/src/components/Project/AssignRole.jsx index 1b7bfcb0..be557dd4 100644 --- a/src/components/Project/AssignRole.jsx +++ b/src/components/Project/AssignRole.jsx @@ -34,18 +34,24 @@ const AssignRoleModel = ({ assignData, onClose }) => { const [selectedRole, setSelectedRole] = useState("all"); const [selectedEmployees, setSelectedEmployees] = useState([]); - -const { handleSubmit, control, setValue, watch, formState: { errors },reset } = useForm({ - defaultValues: { - selectedEmployees: [], - description:"" - }, - resolver: (data) => { - const validation = schema.safeParse(data); - if (validation.success) return { values: data, errors: {} }; - return { values: {}, errors: validation.error.formErrors.fieldErrors }; - }, -}); + const { + handleSubmit, + control, + setValue, + watch, + formState: { errors }, + reset, + } = useForm({ + defaultValues: { + selectedEmployees: [], + description: "", + }, + resolver: (data) => { + const validation = schema.safeParse(data); + if (validation.success) return { values: data, errors: {} }; + return { values: {}, errors: validation.error.formErrors.fieldErrors }; + }, + }); const handleRoleChange = (event) => { setSelectedRole(event.plannedTask.value); @@ -78,62 +84,51 @@ const { handleSubmit, control, setValue, watch, formState: { errors },reset } = }); }; + const onSubmit = async (data) => { + const formattedData = { + taskTeam: data.selectedEmployees, + plannedTask: parseInt(plannedTask, 10), + 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([]) + reset(); + closeModal() -const onSubmit = async(data) => { - const formattedData = { - taskTeam: data.selectedEmployees, - plannedTask: parseInt( plannedTask, 10 ), - description: data.description, - assignmentDate: new Date().toISOString(), - workItemId:assignData?.workItem?.workItem.id + } catch (error) { + showToast("something wrong", "error"); + } }; - try - { - let response = await TasksRepository.assignTask( formattedData ); - showToast( "Task Successfully Assigend", "success" ) - reset() - onClose() - } catch ( error ) - { - showToast("something wrong","error") - - } - -}; -useEffect(()=>{ - dispatch(changeMaster("Job Role")) - return ()=> setSelectedRole("all") -},[dispatch]) - + useEffect(() => { + dispatch(changeMaster("Job Role")); + return () => setSelectedRole("all"); + }, [dispatch]); return ( <>
-
-
+
+

{[ assignData?.building?.name, assignData?.floor?.floorName, assignData?.workArea?.areaName, assignData?.workItem?.workItem?.activityMaster?.activityName, - ].map((item, index, array) => ( -

-
- {item} - - {/* Arrow between items */} + ] + .filter(Boolean) + .map((item, index, array) => ( + + {item} {index < array.length - 1 && ( -
- -
+ )} -
-
- ))} -
+ + ))} +

@@ -166,7 +161,10 @@ useEffect(()=>{
Employee
- {selectedRole !== "" && ( + +
+
+ {selectedRole !== "" && (
@@ -178,7 +176,7 @@ useEffect(()=>{ return (
@@ -200,10 +198,19 @@ useEffect(()=>{ )} />
-
+

{emp.firstName} {emp.lastName} -

- +

+ {loading && (

{

)} - +
+
+ {selectedEmployees.length > 0 && (
@@ -233,7 +242,7 @@ useEffect(()=>{ return ( {emp.firstName} {emp.lastName}

{

)} +
+
+ +
@@ -273,7 +286,7 @@ useEffect(()=>{ setPlannedTask(e.target.value)} id="defaultFormControlInput" @@ -298,7 +311,7 @@ useEffect(()=>{ {...field} className="form-control" id="exampleFormControlTextarea1" - rows="3" + rows="2" /> )} /> diff --git a/src/components/Project/Infrastructure/WorkItem.jsx b/src/components/Project/Infrastructure/WorkItem.jsx index 956991da..ae279024 100644 --- a/src/components/Project/Infrastructure/WorkItem.jsx +++ b/src/components/Project/Infrastructure/WorkItem.jsx @@ -159,8 +159,14 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => { {" "} - Delete + Delete + {!projectId && ( + {" "} + Assign + )}
diff --git a/src/components/common/GlobalModel.jsx b/src/components/common/GlobalModel.jsx index d12aeb34..04d24d5a 100644 --- a/src/components/common/GlobalModel.jsx +++ b/src/components/common/GlobalModel.jsx @@ -45,7 +45,7 @@ const GlobalModel = ({ return (
-
+
-
+
{/* Close button inside the modal header */}
-
+
{children} {/* Render children here, which can be the ReportTask component */}