react-query-v2 : react-query intergrated inside attendance and gallery module #270
| @ -10,7 +10,7 @@ import ProjectRepository from "../../repositories/ProjectRepository"; | ||||
| import Breadcrumb from "../../components/common/Breadcrumb"; | ||||
| import {useProjectDetails, useProjectInfra, useProjects} from "../../hooks/useProjects"; | ||||
| import {useHasUserPermission} from "../../hooks/useHasUserPermission"; | ||||
| import {MANAGE_PROJECT_INFRA} from "../../utils/constants"; | ||||
| import {APPROVE_TASK, ASSIGN_REPORT_TASK, MANAGE_PROJECT_INFRA} from "../../utils/constants"; | ||||
| import {useDispatch, useSelector} from "react-redux"; | ||||
| import {useProfile} from "../../hooks/useProfile"; | ||||
| import {refreshData, setProjectId} from "../../slices/localVariablesSlice"; | ||||
| @ -27,6 +27,8 @@ const InfraPlanning = () => | ||||
| 
 | ||||
|    | ||||
|   const ManageInfra = useHasUserPermission( MANAGE_PROJECT_INFRA ) | ||||
|     const ApprovedTaskRights = useHasUserPermission(APPROVE_TASK) | ||||
|     const ReportTaskRights = useHasUserPermission(ASSIGN_REPORT_TASK) | ||||
|   const reloadedData = useSelector( ( store ) => store.localVariables.reload ) | ||||
| 
 | ||||
|    | ||||
| @ -44,7 +46,7 @@ const InfraPlanning = () => | ||||
|     <div className="col-md-12 col-lg-12 col-xl-12 order-0 mb-4"> | ||||
|     <div className="card"> | ||||
|       <div className="card-body" style={{ padding: "0.5rem" }}> | ||||
|           {ManageInfra ? ( | ||||
|           {(ApprovedTaskRights || ReportTaskRights) ? ( | ||||
|             <div className="align-items-center"> | ||||
|             <div className="row "> | ||||
|               {isLoading && ( <p>Loading...</p> )} | ||||
|  | ||||
| @ -29,7 +29,8 @@ const Header = () => { | ||||
|   const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); | ||||
| 
 | ||||
|     const isDirectoryPath = /^\/directory$/.test(location.pathname); | ||||
|     const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname); | ||||
|     const isProjectPath = /^\/projects$/.test(location.pathname); | ||||
|     const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ; | ||||
|   const getRole = (roles, joRoleId) => { | ||||
|     if (!Array.isArray(roles)) return "User"; | ||||
|     let role = roles.find((role) => role.id === joRoleId); | ||||
| @ -159,6 +160,15 @@ const Header = () => { | ||||
|     }; | ||||
|   }, [handler, newProjectHandler]); | ||||
| 
 | ||||
|   const handleProjectChange =(project)=>{ | ||||
|     if(isProjectPath){ | ||||
|      dispatch(setProjectId(project)) | ||||
|      navigate("/projects/details") | ||||
|     } else{ | ||||
|       dispatch(setProjectId(project)) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   return ( | ||||
|     <nav | ||||
|       className="layout-navbar container-fluid mb-3 navbar navbar-expand-xl navbar-detached align-items-center bg-navbar-theme" | ||||
| @ -212,7 +222,7 @@ const Header = () => { | ||||
|                       <li key={project?.id}> | ||||
|                         <button | ||||
|                           className="dropdown-item" | ||||
|                           onClick={() => dispatch(setProjectId(project?.id))} | ||||
|                           onClick={()=>handleProjectChange(project?.id)} | ||||
|                         > | ||||
|                           {project?.name} | ||||
|                           {project?.shortName && ( | ||||
|  | ||||
| @ -15,8 +15,7 @@ import { useCreateTask } from "../../hooks/useTasks"; | ||||
| 
 | ||||
| const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|   const maxPlanned = | ||||
|     assignData?.workItem?.plannedWork - | ||||
|     assignData?.workItem?.completedWork; | ||||
|     assignData?.workItem?.plannedWork - assignData?.workItem?.completedWork; | ||||
|   const schema = z.object({ | ||||
|     selectedEmployees: z | ||||
|       .array(z.string()) | ||||
| @ -79,10 +78,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|     employees, | ||||
|     loading: employeeLoading, | ||||
|     recallEmployeeData, | ||||
|   } = useEmployeesAllOrByProjectId(selectedProject, false); | ||||
|   } = useEmployeesAllOrByProjectId(false, selectedProject, false); | ||||
|   const dispatch = useDispatch(); | ||||
|   const { loading } = useMaster(); | ||||
|   const {data:jobRoleData} = useMaster(); | ||||
|   const { data: jobRoleData } = useMaster(); | ||||
| 
 | ||||
|   const [selectedRole, setSelectedRole] = useState("all"); | ||||
|   const [displayedSelection, setDisplayedSelection] = useState(""); | ||||
| @ -137,11 +136,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|           (emp) => String(emp.jobRoleId || "") === selectedRole | ||||
|         ); | ||||
| 
 | ||||
| 
 | ||||
|   const onSubmit = (data) => { | ||||
|     const selectedEmployeeIds = data.selectedEmployees; | ||||
| 
 | ||||
|     const taskTeamWithDetails = selectedEmployeeIds?.map((empId) => empId)?.filter(Boolean); | ||||
|     const taskTeamWithDetails = selectedEmployeeIds | ||||
|       ?.map((empId) => empId) | ||||
|       ?.filter(Boolean); | ||||
|     const formattedData = { | ||||
|       taskTeam: taskTeamWithDetails, | ||||
|       plannedTask: data.plannedTask, | ||||
| @ -149,7 +149,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|       assignmentDate: new Date().toISOString(), | ||||
|       workItemId: assignData?.workItem.id, | ||||
|     }; | ||||
|     assignTask({payload:formattedData,workAreaId:assignData?.workArea?.id}); | ||||
|     assignTask({ | ||||
|       payload: formattedData, | ||||
|       workAreaId: assignData?.workArea?.id, | ||||
|     }); | ||||
|   }; | ||||
| 
 | ||||
|   const closedModel = () => { | ||||
| @ -234,12 +237,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|                 <div className="col-12 h-sm-25 overflow-auto mt-2"> | ||||
|                   {selectedRole !== "" && ( | ||||
|                     <div className="row"> | ||||
|                       {loading ? ( // Assuming 'loading' here refers to master data loading | ||||
|                       {employeeLoading ? ( | ||||
|                         <div className="col-12"> | ||||
|                           <p className="text-center">Loading roles...</p> | ||||
|                           <p className="text-center">Loading employees...</p> | ||||
|                         </div> | ||||
|                       ) : filteredEmployees?.length > 0 ? ( | ||||
|                         filteredEmployees?.map((emp) => { | ||||
|                         filteredEmployees.map((emp) => { | ||||
|                           const jobRole = jobRoleData?.find( | ||||
|                             (role) => role?.id === emp?.jobRoleId | ||||
|                           ); | ||||
| @ -348,7 +351,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => { | ||||
|               {!loading && errors.selectedEmployees && ( | ||||
|                 <div className="danger-text mt-1"> | ||||
|                   <p>{errors.selectedEmployees.message}</p>{" "} | ||||
|                  | ||||
|                 </div> | ||||
|               )} | ||||
| 
 | ||||
|  | ||||
| @ -125,7 +125,7 @@ const WorkArea = ({ workArea, floor, forBuilding }) => { | ||||
|                   {isLoading  || ProjectTaskList === undefined  ? ( | ||||
|                     <div className="text-center py-2 text-muted">Loading activities...</div> | ||||
|                   ) :  ProjectTaskList?.length ===  0 ? ( | ||||
|                     <div className="text-center py-2 text-muted">Loading activities...</div> | ||||
|                     <div className="text-center py-2 text-muted">No activities available for this work area.</div> | ||||
|                   ):ProjectTaskList?.length > 0 ? ( | ||||
|                     <table className="table table-sm mx-1"> | ||||
|                       <thead> | ||||
| @ -144,7 +144,7 @@ const WorkArea = ({ workArea, floor, forBuilding }) => { | ||||
|                             Today's Planned | ||||
|                           </th> | ||||
|                           <th className="infra-activity-table-header">Progress</th> | ||||
|                           {(ManageInfra ||  ManageAndAssignTak) && ( | ||||
|                           {(ManageInfra || ManageAndAssignTak) && ( | ||||
|                             <th className="infra-activity-table-header text-end"> | ||||
|                               <span className="px-2">Actions</span> | ||||
|                             </th> | ||||
|  | ||||
| @ -22,16 +22,20 @@ const ProjectList = () => { | ||||
|   const { profile: loginUser } = useProfile(); | ||||
|   const [listView, setListView] = useState(false); | ||||
|   const [showModal, setShowModal] = useState(false); | ||||
|   const selectedProject = useSelector((store)=>store.localVariables.projectId) | ||||
|   const dispatch = useDispatch() | ||||
|   const selectedProject = useSelector( | ||||
|     (store) => store.localVariables.projectId | ||||
|   ); | ||||
|   const dispatch = useDispatch(); | ||||
| 
 | ||||
|   const { projects, loading, error, refetch } = useProjects(); | ||||
|   const [projectList, setProjectList] = useState([]); | ||||
| 
 | ||||
|   const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); | ||||
|   const [HasManageProject, setHasManageProject] = useState(HasManageProjectPermission); | ||||
|   const [HasManageProject, setHasManageProject] = useState( | ||||
|     HasManageProjectPermission | ||||
|   ); | ||||
| 
 | ||||
|   const { mutate: createProject,isPending } = useCreateProject({ | ||||
|   const { mutate: createProject, isPending } = useCreateProject({ | ||||
|     onSuccessCallback: () => { | ||||
|       setShowModal(false); | ||||
|     }, | ||||
| @ -48,7 +52,9 @@ const ProjectList = () => { | ||||
| 
 | ||||
|   const handleShow = () => setShowModal(true); | ||||
|   const handleClose = () => setShowModal(false); | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     dispatch(setProjectId(null)); | ||||
|   }, []); | ||||
|   const sortingProject = (projects) => { | ||||
|     if (!loading && Array.isArray(projects)) { | ||||
|       const grouped = {}; | ||||
| @ -74,10 +80,6 @@ const ProjectList = () => { | ||||
|   }; | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|    if(selectedProject == null){ | ||||
|        dispatch(setProjectId(projects[0]?.id)); | ||||
|    } | ||||
| 
 | ||||
|     if (!loading && projects) { | ||||
|       sortingProject(projects); | ||||
|     } | ||||
| @ -114,12 +116,10 @@ const ProjectList = () => { | ||||
| 
 | ||||
|   const totalPages = Math.ceil(filteredProjects.length / ITEMS_PER_PAGE); | ||||
| 
 | ||||
|   const { | ||||
|     currentItems, | ||||
|     currentPage, | ||||
|     paginate, | ||||
|     setCurrentPage, | ||||
|   } = usePagination(filteredProjects, ITEMS_PER_PAGE); | ||||
|   const { currentItems, currentPage, paginate, setCurrentPage } = usePagination( | ||||
|     filteredProjects, | ||||
|     ITEMS_PER_PAGE | ||||
|   ); | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     const tooltipTriggerList = Array.from( | ||||
| @ -130,17 +130,16 @@ const ProjectList = () => { | ||||
| 
 | ||||
|   return ( | ||||
|     <> | ||||
|      | ||||
|       {showModal && ( | ||||
|          <GlobalModel isOpen={showModal} closeModal={handleClose}> | ||||
|          <ManageProjectInfo | ||||
|           project={null} | ||||
|           handleSubmitForm={handleSubmitForm} | ||||
|           onClose={handleClose} | ||||
|           isPending={isPending} | ||||
|         /> | ||||
|       </GlobalModel> | ||||
|      )} | ||||
|         <GlobalModel isOpen={showModal} closeModal={handleClose}> | ||||
|           <ManageProjectInfo | ||||
|             project={null} | ||||
|             handleSubmitForm={handleSubmitForm} | ||||
|             onClose={handleClose} | ||||
|             isPending={isPending} | ||||
|           /> | ||||
|         </GlobalModel> | ||||
|       )} | ||||
| 
 | ||||
|       <div className="container-fluid"> | ||||
|         <Breadcrumb | ||||
| @ -211,7 +210,7 @@ const ProjectList = () => { | ||||
|                       }, | ||||
|                       { | ||||
|                         id: "cdad86aa-8a56-4ff4-b633-9c629057dfef", | ||||
|                         label:"In Progress" | ||||
|                         label: "In Progress", | ||||
|                       }, | ||||
|                       { | ||||
|                         id: "603e994b-a27f-4e5d-a251-f3d69b0498ba", | ||||
| @ -269,11 +268,14 @@ const ProjectList = () => { | ||||
|         {listView ? ( | ||||
|           <div className="card cursor-pointer"> | ||||
|             <div className="card-body p-2"> | ||||
|               <div className="table-responsive text-nowrap py-2 " style={{minHeight:"400px"}}> | ||||
|               <div | ||||
|                 className="table-responsive text-nowrap py-2 " | ||||
|                 style={{ minHeight: "400px" }} | ||||
|               > | ||||
|                 <table className="table m-3"> | ||||
|                   <thead> | ||||
|                     <tr> | ||||
|                       <th className="text-start" colSpan={5} > | ||||
|                       <th className="text-start" colSpan={5}> | ||||
|                         Project Name | ||||
|                       </th> | ||||
|                       <th className="mx-2 text-start">Contact Person</th> | ||||
| @ -298,8 +300,8 @@ const ProjectList = () => { | ||||
|                               }, | ||||
|                               { | ||||
|                                 id: "cdad86aa-8a56-4ff4-b633-9c629057dfef", | ||||
|                                 label:"In Progress" | ||||
|                                }, | ||||
|                                 label: "In Progress", | ||||
|                               }, | ||||
|                               { | ||||
|                                 id: "603e994b-a27f-4e5d-a251-f3d69b0498ba", | ||||
|                                 label: "On Hold", | ||||
| @ -342,7 +344,11 @@ const ProjectList = () => { | ||||
|                   <tbody className="table-border-bottom-0 overflow-auto "> | ||||
|                     {currentItems.length === 0 ? ( | ||||
|                       <tr className="text-center"> | ||||
|                         <td colSpan="12" rowSpan='12'style={{height:"200px"}} > | ||||
|                         <td | ||||
|                           colSpan="12" | ||||
|                           rowSpan="12" | ||||
|                           style={{ height: "200px" }} | ||||
|                         > | ||||
|                           No projects found | ||||
|                         </td> | ||||
|                       </tr> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user