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

connecting team page to the store #54

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import styled from 'styled-components';
import Landing from './containers/landing';
import AdminDashboard from './containers/adminDashboard';
import TreePage from './containers/treePage';
import TeamPage from './containers/teamPage';
import MyTrees from './containers/myTrees';
import { Layout } from 'antd';
import Home from './containers/home';
Expand Down Expand Up @@ -51,7 +52,7 @@ export enum Routes {
HOME = '/home',
SETTINGS = '/settings',
// VOLUNTEER = '/volunteer',
// TEAM = '/team/:id',
TEAM = '/team/:id',
TREE = '/tree/:id',
MY_TREES = '/my-trees',
// TEAM_LEADERBOARD = '/team-leaderboard',
Expand Down Expand Up @@ -97,9 +98,9 @@ const App: React.FC = () => {
<AuthRedirect from={Routes.HOME} />
<AuthRedirect from={Routes.SETTINGS} />
<AuthRedirect from={Routes.MY_TREES} />
<AuthRedirect from={Routes.TEAM} />
{/*
<AuthRedirect from={Routes.VOLUNTEER} />
<AuthRedirect from={Routes.TEAM} />
<AuthRedirect from={Routes.TEAM_LEADERBOARD} />
<AuthRedirect from={Routes.AVAILABLE_TEAMS} />
<AuthRedirect from={Routes.RESERVATIONS} />
Expand Down Expand Up @@ -137,6 +138,7 @@ const App: React.FC = () => {
component={Settings}
/>
<Route path={Routes.MY_TREES} exact component={MyTrees} />
<Route path={Routes.TEAM} exact component={TeamPage} />
{/*
<Route
path={Routes.VOLUNTEER}
Expand Down Expand Up @@ -184,6 +186,7 @@ const App: React.FC = () => {
component={Settings}
/>
<Route path={Routes.MY_TREES} exact component={MyTrees} />
<Route path={Routes.TEAM} exact component={TeamPage} />
{/*
<Route
path={Routes.VOLUNTEER}
Expand All @@ -200,7 +203,7 @@ const App: React.FC = () => {
exact
component={AvailableTeams}
/>
<Route path={Routes.TEAM} exact component={TeamPage} />

<Route
path={Routes.RESERVATIONS}
exact
Expand Down
6 changes: 3 additions & 3 deletions src/api/test/protectedApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ describe('Protected API Client Tests', () => {
const response: TeamResponse[] = [
{
id: 1,
name: 'team 1',
teamName: 'team 1',
bio: 'this is team 1',
members: [
{
Expand All @@ -532,7 +532,7 @@ describe('Protected API Client Tests', () => {
},
{
id: 2,
name: 'team 2',
teamName: 'team 2',
bio: 'this is team 2',
members: [
{
Expand Down Expand Up @@ -571,7 +571,7 @@ describe('Protected API Client Tests', () => {
it('makes the right request', async () => {
const response: TeamResponse = {
id: 1,
name: 'team 1',
teamName: 'team 1',
bio: 'this is team 1',
members: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/containers/availableTeams/ducks/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const availableTeamsToTabItems = (
return availableTeams.result.map((team) => {
return {
id: team.id,
name: team.name,
name: team.teamName,
rightSide: '',
};
});
Expand Down
28 changes: 25 additions & 3 deletions src/containers/teamPage/ducks/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import {
AsyncRequest,
asyncRequestIsComplete,
} from '../../../utils/asyncRequest';
import { TeamResponse, TeamProps, GoalProps, GoalResponseJSON } from './types';
import {
TeamResponse,
TeamProps,
GoalProps,
GoalResponseJSON,
TeamRole,
} from './types';

export const teamResponseRequestToTeamProps = (
team: AsyncRequest<TeamResponse, any>,
Expand All @@ -16,7 +22,7 @@ export const teamResponseRequestToTeamProps = (
const teamResponseToTeamProps = (team: TeamResponse): TeamProps => {
return {
id: team.id,
name: team.name,
teamName: team.teamName,
bio: team.bio,
members: team.members,
goals: mapGoalResponseJSONToGoalProps(team.goals),
Expand All @@ -41,8 +47,24 @@ const mapGoalResponseJSONToGoalProps = (
// This is to prevent the TeamProps from being undefined
const emptyTeam: () => TeamProps = () => ({
id: 0,
name: '',
teamName: '',
bio: '',
members: [],
goals: [],
});

export const getTeamRole = (
team: AsyncRequest<TeamResponse, any>,
userId: number,
): TeamRole => {
if (asyncRequestIsComplete(team)) {
const member = team.result.members.find(
(potentialMember) => potentialMember.userId === userId,
);
if (member) {
return member.teamRole;
}
return TeamRole.NONE;
}
return TeamRole.NONE;
};
3 changes: 2 additions & 1 deletion src/containers/teamPage/ducks/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TeamResponse, TeamThunkAction } from './types';
import { teamResponse } from './actions';
import protectedApiClient from '../../../api/protectedApiClient';

export const getTeam = (teamId: number): TeamThunkAction<void> => {
return (dispatch, getState, { protectedApiClient }) => {
return (dispatch, getState) => {
dispatch(teamResponse.loading());
return protectedApiClient
.getTeam(teamId)
Expand Down
12 changes: 6 additions & 6 deletions src/containers/teamPage/ducks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ProtectedApiExtraArgs } from '../../../api/protectedApiClient';

export interface TeamProps {
id: number;
name: string;
teamName: string;
bio: string;
members: MemberProps[];
goals: GoalProps[];
Expand All @@ -28,10 +28,10 @@ export interface GoalProps {
}

export enum TeamRole {
NONE = 'none',
MEMBER = 'member',
LEADER = 'leader',
PENDING = 'pending',
NONE = 'NONE',
MEMBER = 'MEMBER',
LEADER = 'LEADER',
PENDING = 'PENDING',
}

export interface UserInvite {
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface TransferOwnershipRequest {

export interface TeamResponse {
id: number;
name: string;
teamName: string;
bio: string;
members: MemberProps[];
goals: GoalResponseJSON[];
Expand Down
Loading