Compare commits

..

No commits in common. "1caeeb890d2f566ee809fac48be7ece68552810b" and "d4fed679121e1fe95e0c6bf01e26e035b2be8a98" have entirely different histories.

3 changed files with 31 additions and 47 deletions

View File

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

View File

@ -163,32 +163,30 @@ const EmployeeList = () => {
className="dataTables_length text-start" className="dataTables_length text-start"
id="DataTables_Table_0_length" id="DataTables_Table_0_length"
> >
<label> <label>
<select <select
id="project-select" id="project-select"
onChange={(e) => setSelectedProject(e.target.value)} onChange={(e) => setSelectedProject(e.target.value)}
name="DataTables_Table_0_length" name="DataTables_Table_0_length"
aria-controls="DataTables_Table_0" aria-controls="DataTables_Table_0"
className="form-select form-select-sm" className="form-select form-select-sm"
value={selectedProject || ""} value={selectedProject || ""}
> >
{projectLoading ? ( {projectLoading ? (
<option value="Loading">Loading...</option> <option value="Loading">Loading...</option>
) : ( ) : (
<> <>
<option value="">All Employees</option> <option value="">All Employees</option>
{Array.isArray(projects) && {Array.isArray(projects) &&
projects projects.map((item) => (
.filter((item) => loginUser?.projects?.includes(String(item.id))) <option key={item.id} value={item.id}>
.map((item) => ( {item.name}
<option key={item.id} value={item.id}> </option>
{item.name} ))}
</option> </>
))} )}
</> </select>
)} </label>
</select>
</label>
</div> </div>
</div> </div>
</div> </div>

View File

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