Merge branch 'pramod_Bug#99ProjectsDisplays' into Issues_April_4W

This commit is contained in:
Vikas Nale 2025-04-22 16:07:46 +05:30
commit 148058d1d2
3 changed files with 47 additions and 31 deletions

View File

@ -7,6 +7,7 @@ import { setProjectId } from "../slices/localVariablesSlice";
export const useProjects = () =>
{
const {profile} = useProfile()
const dispatch = useDispatch();
const [projects, setProjects] = useState([]);
const [loading, setLoading] = useState(false);
@ -48,9 +49,19 @@ export const useProjects = () =>
fetchData();
}, []);
useEffect(() => {
dispatch(setProjectId(projects[0]?.id));
}, [projects]);
useEffect( () =>
{
if (projects )
{
if ( profile?.projects && profile?.projects?.length > 0 )
{
dispatch(setProjectId(profile?.projects[0]))
} else
{
dispatch(setProjectId(1))
}
}
}, [profile]);
return { projects, loading, error, refetch: fetchData };
};

View File

@ -178,7 +178,9 @@ const EmployeeList = () => {
<>
<option value="">All Employees</option>
{Array.isArray(projects) &&
projects.map((item) => (
projects
.filter((item) => loginUser?.projects?.includes(String(item.id)))
.map((item) => (
<option key={item.id} value={item.id}>
{item.name}
</option>
@ -186,7 +188,7 @@ const EmployeeList = () => {
</>
)}
</select>
</label>
</label>
</div>
</div>
</div>

View File

@ -176,10 +176,13 @@ const ProjectList = () =>
{loading && <p className="text-center">Loading...</p>}
{currentItems &&
currentItems.map((item) => (
<ProjectCard projectData={item} key={item.id}></ProjectCard>
))}
{Array.isArray(currentItems) && loginUser?.projects && (
currentItems
.filter((item) => loginUser.projects.includes(String(item.id)))
.map((item) => (
<ProjectCard projectData={item} key={item.id} />
))
)}
</div>
{/* Pagination */}
{!loading && (