diff --git a/src/components/Project/AssignTask.jsx b/src/components/Project/AssignTask.jsx index abe44a41..8c906c13 100644 --- a/src/components/Project/AssignTask.jsx +++ b/src/components/Project/AssignTask.jsx @@ -21,19 +21,18 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { const schema = z.object({ selectedEmployees: z .array(z.string()) - .min(1, { message: "At least one employee must be selected" }), + .min(1, { message: "At least one employee must be selected" }), description: z.string().min(1, { message: "Description is required" }), plannedTask: z.preprocess( - (val) => parseInt(val, 10), + (val) => parseInt(val, 10), z .number({ required_error: "Planned task is required", invalid_type_error: "Target for Today must be a number", }) - .int() - .positive({ message: "Planned task must be a positive number" }) + .int() + .positive({ message: "Planned task must be a positive number" }) .max(maxPlanned, { - message: `Planned task cannot exceed ${maxPlanned}`, }) ), @@ -42,6 +41,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { const [isHelpVisibleTarget, setIsHelpVisibleTarget] = useState(false); const helpPopupRefTarget = useRef(null); const [isHelpVisible, setIsHelpVisible] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); // Refs for Bootstrap Popovers const infoRef = useRef(null); @@ -151,7 +151,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { // Form submission handler const onSubmit = async (data) => { const selectedEmployeeIds = data.selectedEmployees; - + setIsSubmitting(true); // Prepare taskTeam data (only IDs are needed for the backend based on previous context) const taskTeamWithDetails = selectedEmployeeIds .map((empId) => { @@ -169,11 +169,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { }; try { - // Call API to assign task - // Close the modal + await TasksRepository.assignTask(formattedData); + setIsSubmitting(false); + closedModel(); } catch (error) { - console.error("Error assigning task:", error); - showToast("Something went wrong. Please try again.", "error"); + setIsSubmitting(false); + showToast("Something went wrong. Please try again.", "error"); } }; @@ -183,393 +184,387 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { onClose(); }; return ( - -
Assign Task
-
-
- Work Location :
- {[
- assignData?.building?.name,
- assignData?.floor?.floorName,
- assignData?.workArea?.areaName,
- assignData?.workItem?.workItem?.activityMaster
- ?.activityName,
- ]
- .filter(Boolean) // Filter out any undefined/null values
- .map((item, index, array) => (
-
- {item}
- {index < array.length - 1 && (
-
- )}
-
- ))}
+ Assign Task
+
+ Work Location :
+ {[
+ assignData?.building?.name,
+ assignData?.floor?.floorName,
+ assignData?.workArea?.areaName,
+ assignData?.workItem?.workItem?.activityMaster?.activityName,
+ ]
+ .filter(Boolean) // Filter out any undefined/null values
+ .map((item, index, array) => (
+
+ {item}
+ {index < array.length - 1 && (
+
+ )}
-