diff --git a/src/components/Activities/AttendcesLogs.jsx b/src/components/Activities/AttendcesLogs.jsx index b57a9c75..1ac58c72 100644 --- a/src/components/Activities/AttendcesLogs.jsx +++ b/src/components/Activities/AttendcesLogs.jsx @@ -112,7 +112,7 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => { const { currentPage, totalPages, currentItems: paginatedAttendances, paginate, resetPage } = usePagination( processedData, - 10 + 20 ); // Reset to the first page whenever processedData changes (due to switch on/off) @@ -127,7 +127,7 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => { id="DataTables_Table_0_length" >
- +
{ acc.push( - {moment(currentDate).format("YYYY-MM-DD")} + {moment(currentDate).format("DD-MM-YYYY")} ); diff --git a/src/components/Activities/ReportTask.jsx b/src/components/Activities/ReportTask.jsx index 58d8ccd5..1b1f0188 100644 --- a/src/components/Activities/ReportTask.jsx +++ b/src/components/Activities/ReportTask.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState,useEffect } from "react"; import { formatDate } from "../../utils/dateUtils"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -13,15 +13,23 @@ export const ReportTask = ({ report, closeModal, refetch }) => { report?.workItem?.plannedWork - report?.workItem?.completedWork; const schema = z.object({ - completedTask: z - .number() - .min(0, "Completed Work must be greater than 0") - .max(maxPending, { - message: `Completed task cannot exceed total pending tasks: ${maxPending}`, - }) - .optional(), - comment: z.string().min(1, "Comment cannot be empty"), - }); + completedTask: z + .preprocess( + (val) => (val === "" || val === null || Number.isNaN(val) ? undefined : Number(val)), + z + .number({ + required_error: "Completed Work must be a number", + invalid_type_error: "Completed Work must be a number", + }) + .min(1, "Completed Work must be greater than 0") + .max(maxPending, { + message: `Completed task cannot exceed total pending tasks: ${maxPending}`, + }) + ), + comment: z.string().min(1, "Comment cannot be empty"), +}); + + const { register, handleSubmit, @@ -32,6 +40,14 @@ export const ReportTask = ({ report, closeModal, refetch }) => { defaultValues: { completedTask: 0, comment: "" }, }); + +useEffect(() => { + if (report) { + reset({ completedTask: 0, comment: "" }); // optional: customize default if needed + } +}, [report, reset]); + + const onSubmit = async (data) => { try { setloading(true); @@ -56,6 +72,7 @@ export const ReportTask = ({ report, closeModal, refetch }) => { }; const handleClose = () => { closeModal(); + reset(); }; return ( diff --git a/src/components/Activities/ReportTaskComments.jsx b/src/components/Activities/ReportTaskComments.jsx index efe62d0a..9db42b3a 100644 --- a/src/components/Activities/ReportTaskComments.jsx +++ b/src/components/Activities/ReportTaskComments.jsx @@ -13,35 +13,52 @@ const schema = z.object({ comment: z.string().min(1, "Comment cannot be empty"), }); +/** + * ReportTaskComments component for displaying and adding comments to a task. + * It also shows a summary of the activity and task details. + * + * @param {object} props - The component props. + * @param {object} props.commentsData - Data related to the task and its comments, including the description. + * @param {function} props.closeModal - Callback function to close the modal. + */ + const ReportTaskComments = ({ commentsData, closeModal }) => { const [loading, setloading] = useState(false); const [comments, setComment] = useState([]); - const [bgClass, setBgClass] = useState(""); const { register, handleSubmit, formState: { errors }, - reset, + reset, // Destructure reset from useForm } = useForm({ resolver: zodResolver(schema), }); const containerRef = useRef(null); - const firstRender = useRef(true); - + const firstRender = useRef(true); useEffect(() => { - setComment(commentsData?.comments); + const taskList = getCachedData("taskList"); + if (taskList && taskList.data && commentsData?.id) { + const currentTask = taskList.data.find(task => task.id === commentsData.id); + if (currentTask && currentTask.comments) { + setComment(currentTask.comments); + } else { + setComment(commentsData?.comments || []); + } + } else { + setComment(commentsData?.comments || []); + } + firstRender.current = true; }, [commentsData]); - // Scroll logic: scroll to bottom when new comments are added useEffect(() => { if (!firstRender.current && containerRef.current) { containerRef.current.scrollTop = containerRef.current.scrollHeight; } else { - firstRender.current = false; // Mark the first render as complete + firstRender.current = false; } - }, [comments]); // Run this when comments array is updated + }, [comments]); const onSubmit = async (data) => { let sendComment = { @@ -52,28 +69,34 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { try { setloading(true); const resp = await TasksRepository.taskComments(sendComment); + setComment((prevItems) => [...prevItems, resp.data]); + const taskList = getCachedData("taskList"); - const updatedTaskList = taskList.data.map((task) => { - if (task.id === resp.data.taskAllocationId) { - const existingComments = Array.isArray(task.comments) - ? task.comments - : []; - return { - ...task, - comments: [...existingComments, resp.data], - }; - } - return task; - }); - cacheData("taskList", { - data: updatedTaskList, - projectId: taskList.projectId, - }); - reset(); + + if (taskList && taskList.data) { + const updatedTaskList = taskList.data.map((task) => { + if (task.id === resp.data.taskAllocationId) { + const existingComments = Array.isArray(task.comments) + ? task.comments + : []; + return { + ...task, + comments: [...existingComments, resp.data], + }; + } + return task; + }); + + cacheData("taskList", { + data: updatedTaskList, + projectId: taskList.projectId, + }); + } + + reset(); setloading(false); showToast("Successfully Sent", "success"); - // closeModal(); } catch (error) { setloading(false); showToast(error.response.data?.message || "Something went wrong", "error"); @@ -93,16 +116,20 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { onClick={closeModal} aria-label="Close" > -

Activity Summary

+
+ Activity Summary +
+

- {comments && comments[0]?.comment} + {commentsData?.workItem?.workArea?.floor?.building?.description}

+

Assigned By : - {commentsData?.assignedBy.firstName + + {commentsData?.assignedBy?.firstName + " " + - commentsData?.assignedBy.lastName} + commentsData?.assignedBy?.lastName} {" "}

@@ -126,7 +153,7 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { Completed Work : {commentsData?.completedTask}

-

Team:

+

Team :

{commentsData?.teamMembers?.map((member, idx) => ( @@ -147,7 +174,6 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { {...register("comment")} className="form-control" id="exampleFormControlTextarea1" - rows="1" placeholder="Enter comment" /> {errors.comment && ( @@ -162,7 +188,7 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { > Close -
@@ -170,23 +196,21 @@ const ReportTaskComments = ({ commentsData, closeModal }) => {
    {comments && comments ?.slice() - .reverse() + .reverse() .map((data, idx) => { const fullName = `${data?.employee?.firstName} ${data?.employee?.lastName}`; - const bgClass = getBgClassFromHash(fullName); return (
  • {
    -
    -

    {fullName}

    -

    +

    +

    {fullName}

    +

    {moment.utc(data?.commentDate).local().fromNow()}

    diff --git a/src/components/Directory/CardViewDirectory.jsx b/src/components/Directory/CardViewDirectory.jsx index 33fcad6f..519d1b7f 100644 --- a/src/components/Directory/CardViewDirectory.jsx +++ b/src/components/Directory/CardViewDirectory.jsx @@ -79,10 +79,10 @@ const CardViewDirectory = ({ )} {!IsActive && ( { diff --git a/src/components/Directory/ListViewDirectory.jsx b/src/components/Directory/ListViewDirectory.jsx index d227d99d..e2e3d18e 100644 --- a/src/components/Directory/ListViewDirectory.jsx +++ b/src/components/Directory/ListViewDirectory.jsx @@ -110,8 +110,9 @@ const ListViewDirectory = ({ )} {!IsActive && ( { @@ -125,4 +126,4 @@ const ListViewDirectory = ({ ); }; -export default ListViewDirectory; +export default ListViewDirectory; \ No newline at end of file diff --git a/src/components/Directory/ManageBucket.jsx b/src/components/Directory/ManageBucket.jsx index 86ba6dfe..ef8b5e54 100644 --- a/src/components/Directory/ManageBucket.jsx +++ b/src/components/Directory/ManageBucket.jsx @@ -296,7 +296,7 @@ const ManageBucket = () => {loading && ( - + {" "}
    Loading... @@ -306,7 +306,7 @@ const ManageBucket = () => )} {!loading && buckets.length == 0 && ( - +
    Bucket Not Available.
    @@ -315,7 +315,7 @@ const ManageBucket = () => )} {!loading && sortedBucktesList.length == 0 && ( - +
    No Matching Bucket Found.
    diff --git a/src/components/Directory/NoteCardDirectory.jsx b/src/components/Directory/NoteCardDirectory.jsx index 2b5c0868..7b996e94 100644 --- a/src/components/Directory/NoteCardDirectory.jsx +++ b/src/components/Directory/NoteCardDirectory.jsx @@ -156,15 +156,16 @@ const NoteCardDirectory = ({refetchProfile,refetchNotes, noteItem, contactId, se )} ) : isActivProcess ? ( - < i className='bx bx-refresh text-primary bx-spin' >
    + < i className='bx bx-loader-alt bx-spin text-primary' >
    ) : ( handleDeleteNote(!noteItem.isActive)} title="Restore" > )} -
    +
    +
    diff --git a/src/components/Project/AssignRole.jsx b/src/components/Project/AssignRole.jsx index a639abc8..65badfb7 100644 --- a/src/components/Project/AssignRole.jsx +++ b/src/components/Project/AssignRole.jsx @@ -273,13 +273,6 @@ const AssignRoleModel = ({ assignData, onClose }) => {
- {employeeLoading &&
Loading employees...
} - {!employeeLoading && - filteredEmployees?.length === 0 && - employees && ( -
No employees found for the selected role.
- )} -
{selectedRole !== "" && ( diff --git a/src/components/Project/ManageProjectInfo.jsx b/src/components/Project/ManageProjectInfo.jsx index 41d2cb24..a03077f9 100644 --- a/src/components/Project/ManageProjectInfo.jsx +++ b/src/components/Project/ManageProjectInfo.jsx @@ -102,13 +102,21 @@ const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => { const onSubmitForm = (updatedProject) => { setLoading(true); handleSubmitForm( updatedProject, setLoading,reset ); - - + }; + const handleCancel = () => { + reset({ + id: project?.id || "", + name: project?.name || "", + contactPerson: project?.contactPerson || "", + projectAddress: project?.projectAddress || "", + startDate: formatDate(project?.startDate) || currentDate, + endDate: formatDate(project?.endDate) || currentDate, + projectStatusId: String(project?.projectStatusId || "00000000-0000-0000-0000-000000000000"), + }); + onClose(); }; - - return (
{
@@ -280,7 +288,7 @@ const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
@@ -188,7 +190,7 @@ const DailyTask = () => { )} {!task_loading && TaskList.length === 0 && ( - +

No Reports Found

@@ -199,7 +201,7 @@ const DailyTask = () => { - {date} + {moment(date).format("DD-MM-YYYY")} {TaskLists.filter((task) => @@ -246,7 +248,7 @@ const DailyTask = () => { task.workItem.completedWork} {task.completedTask} - {formatDate(task.assignmentDate)} + {moment(task.assignmentDate).format("DD-MM-YYYY")}
{ ${task.teamMembers .map( (member) => ` -
-
- - ${ - member?.firstName?.charAt( - 0 - ) || "" - }${ +
+
+ + ${ + member?.firstName?.charAt( + 0 + ) || "" + }${ member?.lastName?.charAt(0) || "" } - -
- ${member.firstName} ${ + +
+ ${member.firstName} ${ member.lastName } -
- ` +
+ ` ) .join("")}
@@ -362,4 +364,4 @@ const DailyTask = () => { ); }; -export default DailyTask; +export default DailyTask; \ No newline at end of file diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx index a9ceab49..ad3e1052 100644 --- a/src/pages/Directory/Directory.jsx +++ b/src/pages/Directory/Directory.jsx @@ -21,8 +21,9 @@ import ManageBucket from "../../components/Directory/ManageBucket"; import {useFab} from "../../Context/FabContext"; import {DireProvider, useDir} from "../../Context/DireContext"; -const Directory = () => +const Directory = ({IsPage=true,prefernceContacts}) => { + const[projectPrefernce,setPerfence] = useState(null) const[IsActive,setIsActive] = useState(true) const [isOpenModal, setIsOpenModal] = useState(false); const [isOpenModalNote, setIsOpenModalNote] = useState(false); @@ -44,7 +45,7 @@ const Directory = () => const { dirActions, setDirActions } = useDir(); - const { contacts, loading , refetch} = useDirectory(IsActive); + const { contacts, loading , refetch} = useDirectory(IsActive,projectPrefernce); const { contactCategory, loading: contactCategoryLoading } = useContactCategory(); const {buckets} = useBuckets(); @@ -72,7 +73,7 @@ const Directory = () => // cacheData("Contacts", {data:updatedContacts,isActive:IsActive}); // setContactList(updatedContacts); - refetch() + refetch(IsActive,prefernceContacts) } catch (error) { const msg = error.response?.data?.message || @@ -216,35 +217,43 @@ const handleDeleteContact = async (overrideId = null) => { }; - useEffect(() => { - setActions([ - { - label: "New Contact", - icon: "bx bx-plus-circle", - color: "warning", - onClick: () => setIsOpenModal(true), - }, - { - label: "Manage Bucket", - icon: "fa-solid fa-bucket fs-5 ", - color: "primary", - onClick: () => setOpenBucketModal(true), - }, - - ]); + useEffect(() => { + const actions = []; - return () => setActions([]); // Clean up - }, []); + if (IsPage) { + actions.push({ + label: "Manage Bucket", + icon: "fa-solid fa-bucket fs-5", + color:"primary", + onClick: () => setOpenBucketModal(true), + }); + } + actions.push({ + label: "New Contact", + icon: "bx bx-plus-circle", + color: "warning", + onClick: () => setIsOpenModal(true), + } ); + + + setActions(actions); + + return () => setActions([]); +}, [IsPage]); + useEffect( () => + { + setPerfence(prefernceContacts) +},[prefernceContacts]) return (
- + >)} {isOpenModal && (
-
+
-
+