Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peterson impl feature finish my team filter or tasks tab #2078

Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1db74db
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 10, 2024
037f982
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 18, 2024
64c7cca
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 19, 2024
0f421d6
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 20, 2024
3fdad23
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
14583a3
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
a6c9036
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
6984e1f
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
78ea025
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
af41e69
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
b902fcb
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
256acf7
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
d6b0bc6
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
445051c
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
da40515
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 21, 2024
e789817
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Mar 21, 2024
c52d74a
Update Leaderboard.jsx
peterson337 Mar 21, 2024
81f8cb7
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Mar 23, 2024
215438a
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Mar 25, 2024
56d5462
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Apr 1, 2024
5331bfe
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 2, 2024
6c45bb4
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 2, 2024
9e7931e
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 3, 2024
1ea971e
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 5, 2024
a92a2e0
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 8, 2024
97d70c1
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 16, 2024
45ccbe0
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Apr 16, 2024
8f50704
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 17, 2024
ab40428
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 17, 2024
f325711
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Apr 17, 2024
a4ce81e
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Apr 28, 2024
341e5f1
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 May 10, 2024
a525b52
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 May 10, 2024
78aab84
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 May 21, 2024
42a6ff5
Update Leaderboard.jsx
peterson337 May 22, 2024
1abb075
Update Leaderboard.jsx
peterson337 May 22, 2024
6580313
Update Leaderboard.jsx
peterson337 May 23, 2024
8a6af61
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 May 25, 2024
6d70d20
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Jun 6, 2024
fe081f9
Update TeamMemberTasks.jsx
peterson337 Jun 6, 2024
ebff810
Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab
peterson337 Jun 7, 2024
f30e5ea
Merge branch 'development' into Peterson_impl_feature_Finish_My_Team_…
peterson337 Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Badge/__tests__/NewBadges.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('NewBadges component', () => {
mockBadges.forEach(async (badge, index) => {
fireEvent.mouseEnter(badgeImages[index]);
await waitFor(() => {
expect(screen.getByText(badge.badge.badgeName)).toBeInTheDocument();
expect(screen.getByText(badge.badge.description)).toBeInTheDocument();
expect(screen.getByText(badge.badge.badge.badgeName)).toBeInTheDocument();
expect(screen.getByText(badge.badge.badge.description)).toBeInTheDocument();
});
});
});
Expand Down
167 changes: 161 additions & 6 deletions src/components/LeaderBoard/Leaderboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ import { useEffect, useState, useRef } from 'react';
import './Leaderboard.css';
import { isEqual } from 'lodash';
import { Link } from 'react-router-dom';
import { Table, Progress, Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
import {
Table,
Progress,
Modal,
ModalBody,
ModalFooter,
ModalHeader,
Button,
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
Spinner,
} from 'reactstrap';
import Alert from 'reactstrap/lib/Alert';
import {
hasLeaderboardPermissions,
Expand All @@ -15,10 +28,13 @@ import MouseoverTextTotalTimeEditButton from 'components/mouseoverText/Mouseover
import { toast } from 'react-toastify';
import EditableInfoModal from 'components/UserProfile/EditableModal/EditableInfoModal';
import moment from 'moment-timezone';
import { boxStyle } from 'styles';
import axios from 'axios';
import { getUserProfile } from 'actions/userProfile';
import { useDispatch } from 'react-redux';
import { boxStyleDark } from 'styles';
import '../Header/DarkMode.css';
import { ENDPOINTS } from '../../utils/URL';

function useDeepEffect(effectFunc, deps) {
const isFirst = useRef(true);
Expand Down Expand Up @@ -65,6 +81,79 @@ function LeaderBoard({
getMouseoverText();
setMouseoverTextValue(totalTimeMouseoverText);
}, [totalTimeMouseoverText]);
const [teams, setTeams] = useState([]);
const [dropdownOpen, setDropdownOpen] = useState(false);
const [selectedTeamName, setSelectedTeamName] = useState('Select a Team');
const [textButton, setTextButton] = useState('My Team');
const [usersSelectedTeam, setUsersSelectedTeam] = useState([]);
const [isLoadingTeams, setIsLoadingTeams] = useState(false);
const [userRole, setUserRole] = useState();
const [teamsUsers, setTeamsUsers] = useState(leaderBoardData);
const [innerWidth, setInnerWidth] = useState();

useEffect(() => {
const fetchInitial = async () => {
const url = ENDPOINTS.USER_PROFILE(displayUserId);
try {
const response = await axios.get(url);
setTeams(response.data.teams);
setUserRole(response.data.role);
} catch (error) {
toast.error(error);
}
};

fetchInitial();
}, []);

useEffect(() => {
if (!isEqual(leaderBoardData, teamsUsers)) {
if (selectedTeamName === 'Select a Team') {
setTeamsUsers(leaderBoardData);
}
}
}, [leaderBoardData]);

useEffect(() => {
setInnerWidth(window.innerWidth);
}, [window.innerWidth]);

const toggleDropdown = () => setDropdownOpen(prevState => !prevState);

const renderTeamsList = async team => {
if (!team) {
setIsLoadingTeams(true);

setTimeout(() => {
setIsLoadingTeams(false);
setTeamsUsers(leaderBoardData);
}, 1000);
} else {
try {
setIsLoadingTeams(true);
const response = await axios.get(ENDPOINTS.TEAM_MEMBERS(team._id));
const idUsers = response.data.map(item => item._id);
const usersTaks = leaderBoardData.filter(item => idUsers.includes(item.personId));
setTeamsUsers(usersTaks);
setIsLoadingTeams(false);
} catch (error) {
toast.error('Error fetching team members:', error);
setIsLoadingTeams(false);
}
}
};

const handleToggleButtonClick = () => {
if (textButton === 'View All') {
setTextButton('My Team');
renderTeamsList(null);
} else if (usersSelectedTeam.length === 0) {
toast.error(`You have not selected a team or the selected team does not have any members.`);
} else {
setTextButton('View All');
renderTeamsList(usersSelectedTeam);
}
};

const handleMouseoverTextUpdate = text => {
setMouseoverTextValue(text);
Expand All @@ -79,7 +168,7 @@ function LeaderBoard({
if (window.screen.width < 540) {
const scrollWindow = document.getElementById('leaderboard');
if (scrollWindow) {
const elem = document.getElementById(`id${userId}`); //
const elem = document.getElementById(`id${userId}`);

if (elem) {
const topPos = elem.offsetTop;
Expand Down Expand Up @@ -121,7 +210,14 @@ function LeaderBoard({
};
const updateLeaderboardHandler = async () => {
setIsLoading(true);
await getLeaderboardData(userId);
if (isEqual(leaderBoardData, teamsUsers)) {
await getLeaderboardData(userId);
setTeamsUsers(leaderBoardData);
} else {
await getLeaderboardData(userId);
renderTeamsList(usersSelectedTeam);
setTextButton('View All');
}
setIsLoading(false);
toast.success('Successfuly updated leaderboard');
};
Expand All @@ -130,6 +226,24 @@ function LeaderBoard({
showTimeOffRequestModal(request);
};

const teamName = (name, maxLength) =>
setSelectedTeamName(maxLength > 15 ? `${name.substring(0, 15)}...` : name);

const dropdownName = (name, maxLength) => {
if (innerWidth > 457) {
return maxLength > 50 ? `${name.substring(0, 50)}...` : name;
}
return maxLength > 27 ? `${name.substring(0, 27)}...` : name;
};

const TeamSelected = team => {
if (team.teamName.length !== undefined) {
teamName(team.teamName, team.teamName.length);
}
setUsersSelectedTeam(team);
setTextButton('My Team');
};

return (
<div>
<h3>
Expand All @@ -155,6 +269,47 @@ function LeaderBoard({
/>
</div>
</h3>
{userRole === 'Administrator' || userRole === 'Owner' ? (
<section className="d-flex flex-row flex-wrap mb-3">
<Dropdown isOpen={dropdownOpen} toggle={toggleDropdown} className=" mr-3">
<DropdownToggle caret>
{selectedTeamName} {/* Display selected team or default text */}
</DropdownToggle>
<DropdownMenu>
{teams.length === 0 ? (
<DropdownItem
onClick={() => toast.warning('Please, create a team to use the filter.')}
>
Please, create a team to use the filter.
</DropdownItem>
) : (
teams.map(team => (
<DropdownItem key={team._id} onClick={() => TeamSelected(team)}>
{dropdownName(team.teamName, team.teamName.length)}
</DropdownItem>
))
)}
</DropdownMenu>
</Dropdown>

{teams.length === 0 ? (
<Link to="/teams">
<Button color="success" className="fw-bold" boxstyle={boxStyle}>
Create Team
</Button>
</Link>
) : (
<Button
color="primary"
onClick={handleToggleButtonClick}
disabled={isLoadingTeams}
boxstyle={boxStyle}
>
{isLoadingTeams ? <Spinner animation="border" size="sm" /> : textButton}
</Button>
)}
</section>
) : null}
{!isVisible && (
<Alert color="warning">
<div className="d-flex align-items-center">
Expand Down Expand Up @@ -239,7 +394,7 @@ function LeaderBoard({
</span>
</td>
</tr>
{leaderBoardData.map(item => (
{teamsUsers.map(item => (
<tr key={item.personId} className={darkMode ? 'bg-yinmn-blue' : ''}>
<td className="align-middle">
<div>
Expand Down Expand Up @@ -288,7 +443,7 @@ function LeaderBoard({
}
}}
>
{hasLeaderboardPermissions(loggedInUser.role) &&
{hasLeaderboardPermissions(item.role) &&
showStar(item.tangibletime, item.weeklycommittedHours) ? (
<i
className="fa fa-star"
Expand Down Expand Up @@ -428,7 +583,7 @@ function LeaderBoard({
<span
title={mouseoverTextValue}
id="Total time"
className={item.totalintangibletime_hrs > 0 ? 'leaderboard-totals-title' : null}
className={item.totalintangibletime_hrs > 0 ? 'boldClass' : null}
>
{item.totaltime}
</span>
Expand Down
Loading
Loading