diff --git a/components/Layouts/BackgroundLayout.js b/components/Layouts/BackgroundLayout.js
index 7d4431e..5da50a9 100644
--- a/components/Layouts/BackgroundLayout.js
+++ b/components/Layouts/BackgroundLayout.js
@@ -1,7 +1,7 @@
export default function BackgroundLayout({ children }) {
return (
-
+
{children}
)
diff --git a/pages/teams/[teamid].tsx b/pages/teams/[teamid].tsx
index 8053291..7da697f 100644
--- a/pages/teams/[teamid].tsx
+++ b/pages/teams/[teamid].tsx
@@ -1,12 +1,88 @@
+import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'
import { useRouter } from 'next/router'
+import { useEffect, useState } from 'react'
+import BackgroundLayout from '../../components/Layouts/BackgroundLayout'
+import { useAuth } from '../../contexts/authContext'
+import { Team } from '../../models/team'
+import { TeamMemberStatus } from '../../models/teamMember'
+import TeamService from '../../services/teamService'
-export default function Team() {
+const teamService = new TeamService()
+
+export default function TeamDashboard() {
+ const { currUser } = useAuth()
const router = useRouter()
const { teamid } = router.query
- // check if the team is a valid team route and show the dashboard for the team
+ const [loading, setLoading] = useState
(true)
+ const [team, setTeam] = useState(null)
+
+ useEffect(() => {
+ (async function() {
+ try {
+ // if not authenticated, take user to the login
+ if (!currUser) {
+ console.log('not authenticated...routing from dashboard to teams home')
+ router.push('/teams/login')
+ return
+ }
+
+ // check if the team is a valid team and that user is in it
+ if (typeof teamid === "string") {
+ const returnedTeam = await teamService.getTeam(teamid)
+ const returnedTeamMember = await teamService.getTeamMember(teamid, currUser.uid)
+
+ console.log(returnedTeam)
+ console.log(returnedTeamMember)
+
+ // if there is no such team OR
+ // if you are not a member of this team, then get out of here
+ if (!returnedTeam || !returnedTeamMember || returnedTeamMember.status == TeamMemberStatus.deleted) {
+ console.log('no team exists, or am not activated in it')
+ // router.push('/teams')
+ return
+ }
+
+ // if I am new to the team but I was invited, and this is my first time, then activate me into the team
+ // and proceed with showing the dashboard stuff
+
+ } else {
+ console.log('not a proper query with teamid')
+ router.push('/teams')
+ return
+ }
+ } catch(error) {
+ console.log(error)
+ router.push('/teams/login')
+ }
+
+ setLoading(false)
+ })();
+ }, [])
+
+ if (loading) {
+ return (
+ loading
+ )
+ }
return (
- the team is {teamid}
+
+ the team is {teamid}
+
+
+
)
+}
+
+export async function getServerSideProps(context: GetServerSidePropsContext) {
+ // basic check if this team exists
+
+ // todo check if authenticated
+
+ // todo check if this user is in this team
+
+ return {
+ props: {},
+ }
}
\ No newline at end of file
diff --git a/pages/teams/create.tsx b/pages/teams/create.tsx
index 5351385..f885286 100644
--- a/pages/teams/create.tsx
+++ b/pages/teams/create.tsx
@@ -22,7 +22,7 @@ export default function CreateTeam() {
// if not authenticated, take user to the login
if (!currUser) {
console.log('not authenticated...routing from dashboard to teams home')
- // router.push('/teams/login')
+ router.push('/teams/login')
}
// todo if user is in a team already, notify them to make sure
@@ -32,9 +32,9 @@ export default function CreateTeam() {
console.log(error)
router.push('/teams/login')
}
- })();
- setLoading(false)
+ setLoading(false)
+ })();
}, [])
async function handleSubmit(e) {
diff --git a/services/teamService.tsx b/services/teamService.tsx
index ec7df5a..d8b58e8 100644
--- a/services/teamService.tsx
+++ b/services/teamService.tsx
@@ -1,4 +1,4 @@
-import { addDoc, collection, doc, DocumentReference, Firestore, getFirestore, serverTimestamp } from 'firebase/firestore'
+import { addDoc, collection, doc, DocumentReference, Firestore, getDoc, getDocs, getFirestore, orderBy, query, serverTimestamp, where } from 'firebase/firestore'
import { Team } from '../models/team'
import { TeamMember, TeamMemberRole, TeamMemberStatus } from '../models/teamMember'
import { Collections } from './collections'
@@ -30,4 +30,46 @@ export default class TeamService implements IService {
return teamDocRef.id
}
+
+ async getTeam(teamId: string): Promise {
+ const docRef = doc(this.db, Collections.teams, teamId);
+ const docSnap = await getDoc(docRef);
+
+ if (docSnap.exists()) {
+ console.log('got team data')
+ let team: Team = docSnap.data() as Team
+ return team
+ } else {
+ // doc.data() will be undefined in this case
+ console.log("team not found!");
+
+ return null
+ }
+ }
+
+ async getTeamMember(teamId: string, userId: string): Promise {
+ const q = query(
+ collection(this.db, Collections.teamMembers),
+ where("teamId", "==", teamId),
+ where("userId", "==", userId)
+ )
+
+ const querySnapshot = await getDocs(q);
+
+ if (querySnapshot.size > 1) {
+ console.log('there are multiple teammembers for this user...error in teamservice')
+ }
+
+ console.log(querySnapshot)
+
+ var teamMember: TeamMember | null = null
+ querySnapshot.forEach((doc) => {
+ // doc.data() is never undefined for query doc snapshots
+ // get the first one and just return...shouldn't be more
+ console.log('got teammember data')
+ teamMember = doc.data() as TeamMember
+ });
+
+ return teamMember
+ }
}
\ No newline at end of file