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

Final changes #802

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
96 changes: 63 additions & 33 deletions src/combined/ClientApp/src/components/TeamsInfo/TeamDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function TeamDetails() {
if (list[1] !== null) {
ownerId = parseInt(list[1]); // parse the string back to a number.
}

console.log("I am the owner Id", ownerId);
const accessToken = localStorage.getItem("access_token");

const config = useMemo(() => {
Expand All @@ -41,6 +41,7 @@ export function TeamDetails() {


const api = process.env.PUBLIC_URL + `/api/teams/${tId}`;
const personApi = process.env.PUBLIC_URL + `/api/Person/${ownerId}`;
const [currentTeam, setCurrentTeam] = useState<any>();
const [loggedInUserId, setLoggedInUserId] = useState<number>();
const [loggedInUserTeamId, setLoggedInUserTeamId] = useState<number>();
Expand All @@ -62,7 +63,7 @@ export function TeamDetails() {
const [progressBarIsUptodate, setprogressBarIsUptodate] = useState<boolean>(false);

const [previousTeam, setpreviousTeam] = useState<Team>();

const [teamOwner, setteamOwner] = useState<Person>();

useEffect(() => {
const config = {
Expand All @@ -76,15 +77,15 @@ export function TeamDetails() {
setCanSwitchTeam(false)
}
});
}
}

async function PreviousTeamInfo() {

if(loggedInUserId!= null){

var res = await axios.get(process.env.PUBLIC_URL + `/api/PersonTeamAssociation/${loggedInUserId}/${currentEvent?.id}`)
if (res.status === 200) {
console.log("previous team name", res.data?.name)

setpreviousTeam(res.data)
}
}
Expand Down Expand Up @@ -172,6 +173,7 @@ export function TeamDetails() {
await currentTeamMembers();
await getDonationTotal();
await PreviousTeamInfo();

};
if(currentEvent?.id != null){

Expand All @@ -190,7 +192,26 @@ if(currentEvent?.id != null){
}


}, [api, ownerId, currentEvent, loggedInUserId, tId, currentTeam?.ownerID, deleteUserId, members.length, currentEvent?.id, currentTeam?.id]);
}, [api, personApi, ownerId, currentEvent, loggedInUserId, tId, currentTeam?.ownerID, deleteUserId, members.length, currentEvent?.id, currentTeam?.id]);


useEffect(() => {
async function fetchTeamOwner() {

var perRes = await axios.get(personApi, config);
var personResponse = perRes.data;
setteamOwner(personResponse);

}


const callServise = async () => {
await fetchTeamOwner();
};

callServise();
}, [personApi, config]);

const closeModal = () => {
setopenArchiveModal(false)
setOpenSwitchTeamsModal(false)
Expand Down Expand Up @@ -416,51 +437,60 @@ if(currentEvent?.id != null){
<ul>
{members.map((j: any) => (
<li key={j.id}>
{(isAdmin || loggedInUserId === currentTeam?.ownerID) ? (
<Button
variant="contained"
color="primary"
onClick={() => { setopenDeleteModal(true); setDeleteUserId(j.id); setMessage("Are you sure you want to remove memeber " + j.name + " from your team?") }}
size="small"
className="DeleteMembersButton"
>
X
</Button>
) : null}
{j.nickname}

{
{!isAdmin && loggedInUserId !== currentTeam?.ownerID ? null : (
j.id !== teamOwner?.id && (
<Button
variant="contained"
color="primary"
onClick={() => {
setopenDeleteModal(true);
setDeleteUserId(j.id);
setMessage(`Are you sure you want to remove member ${j.name} from your team?`);
}}
size="small"
className="DeleteMembersButton"
>
X
</Button>
)
)}
{j.id === teamOwner?.id ? (
<p>Team owner: <span style={{ color: 'red' }}>{teamOwner?.name}</span></p>
) : (
<span>{j.nickname}</span>
)}
{openErrorModal && (
<DynamicModal
open={openErrorModal}
close={closeModal}
message={"You cannot delete the team owner if there are other members on the team"}
onConfirm={closeModal}
isOkConfirm={true}
/>
}
{
)}
{openZeroPersonModal && (
<DynamicModal
open={openZeroPersonModal}
close={closeModal}
message={"A (zero)person team is not allowed. If you want to delete the team, use DELETE TEAM button on this page."}
onConfirm={closeModal}
isOkConfirm={true}
/>
}
{
!openErrorModal && !openZeroPersonModal && (
<DynamicModal
open={openDeleteModal}
close={closeModal}
message={message}
onConfirm={() => handleDeleteUser()}
isOkConfirm={isOkModal}
/>
)
}
)}
{!openErrorModal && !openZeroPersonModal && (
<DynamicModal
open={openDeleteModal}
close={closeModal}
message={message}
onConfirm={() => handleDeleteUser()}
isOkConfirm={isOkModal}
/>
)}
</li>
))}
</ul>

</Typography>
</CardContent>
</Card>
</Box>
Expand Down