Skip to content

Commit

Permalink
Merge pull request #62 from cepdnaclk/main
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
KATTA-00 authored Jan 25, 2024
2 parents 0c8caf2 + bf007ab commit 5f5778f
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 95 deletions.
2 changes: 1 addition & 1 deletion code/backend/src/services/managers.in.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ManagersInTeamService {
teamPlayers[playerTeam.jerseyId] = {
name: player.fullName,
email: player.playerEmail,
isVerified: player.isVerified
verification: player.isVerified
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/services/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class PlayerService {



console.log(previous);
// console.log(previous);

if (previous>=0){
const filteredSessionsPrevious = sessions.filter(session => {
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type ImpactStats = {
export type TeamPlayerResponse = {
name: string;
email: string;
isVerified: string;
verification: string;
};


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FaUsers } from "react-icons/fa";
import React, { useEffect, useState } from "react";
import styles from "./PlayerManagement.module.scss";
import tableStyles from "./PlayersTable/PlayersTable.module.scss";
import { FieldValues, set, useForm } from "react-hook-form";
import { FieldValues, useForm } from "react-hook-form";

import {
ColumnDef,
Expand Down Expand Up @@ -146,24 +146,20 @@ const PlayerManagement = () => {
const [addPlayerOpen, setAddPlayerOpen] = useState<boolean>(false);

// Form Hook
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
} = useForm();
const setPlayerDetails = useAppState((state) => state.setPlayerDetails);
const { register, handleSubmit, reset } = useForm();
const addPlayer = useAppState((state) => state.addPlayer);

const onSubmit = async (data: FieldValues) => {
setAddPlayerOpen(false);
setPlayerDetails({
...playerDetails,
[data.jersey_number]: {
name: data.name,
email: data.email,
verification: "pending",
},
});
addPlayer(data.jersey_number, data.name, data.email);
// setPlayerDetails({
// ...playerDetails,
// [data.jersey_number]: {
// name: data.name,
// email: data.email,
// verification: "pending",
// },
// });

// const { teamId, email, password } = data;
// const response = await fetch("http://13.235.86.11:5000/exampleURL", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,26 @@ import DialogModal from "../../../Modal/DialogModal";
import { FaCheck } from "react-icons/fa6";
import { useAppState } from "../../../../states/appState";
import { FieldValues, useForm } from "react-hook-form";
import { players } from "../../../../data/players";
const PlayerActions: React.FC<{ jerseyId: number }> = ({ jerseyId }) => {
const playerDetails = useAppState((state) => state.playerDetails);
const setPlayerDetails = useAppState((state) => state.setPlayerDetails);
const removePlayer = useAppState((state) => state.removePlayer);
const editPlayer = useAppState((state) => state.editPlayer);
const [openEdit, setOpenEdit] = useState<boolean>(false);
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
} = useForm();
const { register, handleSubmit, reset } = useForm();

const onSubmit = async (data: FieldValues) => {
// localStorage.setItem("playerDetails", JSON.stringify(players));

setOpenEdit(false);
setPlayerDetails({
...playerDetails,
[jerseyId]: {
name: data.name,
email: data.email,
verification: playerDetails[jerseyId]?.verification,
},
});
editPlayer(jerseyId, data.name, data.email);
// setPlayerDetails({
// ...playerDetails,
// [jerseyId]: {
// name: data.name,
// email: data.email,
// verification: playerDetails[jerseyId]?.verification,
// },
// });
// const response = await fetch("http://13.235.86.11:5000/exampleURL", {
// method: "POST",
// body: JSON.stringify({
Expand Down Expand Up @@ -132,6 +128,9 @@ const PlayerActions: React.FC<{ jerseyId: number }> = ({ jerseyId }) => {
}
action={
<Btn
onClick={() => {
removePlayer(jerseyId);
}}
bgColor="transparent"
buttonStyle="secondary"
Icon={FaTrash}
Expand Down
20 changes: 6 additions & 14 deletions code/client/impax/src/components/Profile/LoginManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { useSignupState } from "../../states/formState";
import { FieldValues, useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useLoginState } from "../../states/profileState";
import { getAccessTokenFromRefreshToken } from "../../services/authService";
import { useAppState } from "../../states/appState";
import { getPlayers } from "../../services/httpClient";

const LoginManager = () => {
const setPlayerDetails = useAppState((state) => state.setPlayerDetails);
const setIsSignup = useSignupState((state) => state.setIsSignup);
const setIsLoggedInManager = useSignupState(
(state) => state.setIsLoggedInManager
Expand Down Expand Up @@ -62,20 +66,8 @@ const LoginManager = () => {
setLoginInfo({ teamId, teamName: teamName, email });

// FETCH PLAYERS array and store it in local storage
// try {
// const playersResponse = await fetch(
// "'https://api.example.com/players'"
// );
// const playersData = await playersResponse.json();
// const timestamp = new Date().getTime();
// const playersWithTimestamp = {
// timestamp,
// playersData,
// };
// localStorage.setItem("players", JSON.stringify(playersWithTimestamp));
// } catch (error) {
// console.log(error);
// }

await getPlayers();

navigate("/login/manager");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import styles from "./PlayerProfile.module.scss";
import { FaRegUserCircle } from "react-icons/fa";
import { useLoginState } from "../../../states/profileState";
import { useSignupState } from "../../../states/formState";
import { useState } from "react";
import MyTeamsTable from "./MyTeamsTable";

const PlayerProfile = () => {
Expand All @@ -18,16 +17,13 @@ const PlayerProfile = () => {
const loginInfo = useLoginState((state) => state.loginInfo);
const setLoginInfo = useLoginState((state) => state.setLoginInfo);

const [addManagerOpen, setAddManagerOpen] = useState<boolean>(false);
// TODO: Stay logged in for 90 days and so much more
return (
<main>
<Title Icon={FaRegUserCircle} title="Player's Profile" />
<div className={styles.loggedInStatus}>
<div className={styles.info}>
<h2>
{loginInfo.teamName} <span>({loginInfo.teamId})</span>
</h2>
<h2>Add, remove your teams</h2>
<span>player email: {loginInfo.email}</span>
</div>
<div className={styles.controls}>
Expand Down
4 changes: 2 additions & 2 deletions code/client/impax/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const Sidebar: React.FC = () => {
const activePage = useAppState((state) => state.activePage);
const setActivePage = useAppState((state) => state.setActivePage);
const navigate = useNavigate();
let isLoggedInPlayer = useSignupState((state) => state.isLoggedInPlayer);
let isLoggedInManager = useSignupState((state) => state.isLoggedInManager);
const isLoggedInPlayer = useSignupState((state) => state.isLoggedInPlayer);
const isLoggedInManager = useSignupState((state) => state.isLoggedInManager);
// isLoggedIn = true;
// isLoggedInManager = true;

Expand Down
24 changes: 24 additions & 0 deletions code/client/impax/src/services/authService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


export async function getAccessTokenFromRefreshToken(refreshToken: string): Promise<string> {
try {
const response = await fetch('/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ refreshToken }),
});

if (response.ok) {
const data = await response.json();
const accessToken: string = data.accessToken;
return accessToken;
} else {
throw new Error('Failed to get access token from refresh token');
}
} catch (error) {
console.error('Error getting access token:', error);
throw error;
}
}
72 changes: 47 additions & 25 deletions code/client/impax/src/services/httpClient.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
import { sessionToBeUploaded } from "../types";
import { updatePlayersDetails } from "../states/updateAppStates";
import { Players, SessionToBeUploaded } from "../types";

export const uploadSession = async () => {
if(localStorage.getItem("sessionDetails") === null) return;
else{
if (localStorage.getItem("sessionDetails") === null) return;
else {
// Retrieve the array of objects from local storage
const sessionDetails = JSON.parse(localStorage.getItem("sessionDetails") as string);

// Iterate through each object in the array
sessionDetails.forEach(function(object:sessionToBeUploaded) {
// Send the object to the server
sendToServer(object);

// Remove the object from the array in local storage
const index = sessionDetails.indexOf(object);
if (index > -1) {
sessionDetails.splice(index, 1);
}
});

// Update the modified array in local storage
localStorage.setItem("sessionDetails", JSON.stringify(sessionDetails));

}
const sessionsToBeUploaded: SessionToBeUploaded[] = JSON.parse(
localStorage.getItem("sessionDetails") as string
);

if (sessionsToBeUploaded.length === 0) return;

// Iterate through each object in the array
sessionsToBeUploaded.forEach(function (object: SessionToBeUploaded) {
// Send the object to the server
sendToServer(object);

// Remove the object from the array in local storage
const index = sessionsToBeUploaded.indexOf(object);
if (index > -1) {
sessionsToBeUploaded.splice(index, 1);
}
});


// Update the modified array in local storage
localStorage.setItem(
"sessionDetails",
JSON.stringify(sessionsToBeUploaded)
);
}
};

function sendToServer(object: SessionToBeUploaded) {
console.log(object);
}

function sendToServer(object:sessionToBeUploaded) {
console.log(object);
}
export const getPlayers = async () => {
const token = localStorage.getItem("accessToken");
try {
const playersResponse = await fetch("http://13.235.86.11:5000/manager/getTeamPlayers",{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});
const playersData: Players = await playersResponse.json();

updatePlayersDetails(playersData);
} catch (error) {
console.log(error);
}
};
5 changes: 5 additions & 0 deletions code/client/impax/src/services/mqttClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
updatePlayersImpactHistory,
checkBuddiesAvailability,
flushStates,
validateTimestampAndSetPlayerDetails,
} from "../states/updateAppStates";
import { Session } from "../types";

Expand Down Expand Up @@ -36,6 +37,7 @@ class MqttClient {
"player/+/impact_with_timestamp",
"player/+/concussion",
"player_map",
"playerDetails",
"hub/old_session",
];

Expand Down Expand Up @@ -73,6 +75,9 @@ class MqttClient {
setPlayerMap(message.toString());
break;

case /^playerDetails$/.test(topic):
validateTimestampAndSetPlayerDetails(message.toString());
break;
case /^session$/.test(topic):
setSessionDetails(message.toString());
break;
Expand Down
Loading

0 comments on commit 5f5778f

Please sign in to comment.