Skip to content

Commit 28ed150

Browse files
authored
Sara/csb 165 create team info in team settings page (codesandbox#4059)
1 parent 14deb9f commit 28ed150

File tree

10 files changed

+130
-9
lines changed

10 files changed

+130
-9
lines changed

packages/app/src/app/graphql/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# source: https://codesandbox.io/api/graphql
2-
# timestamp: Thu Apr 30 2020 18:52:01 GMT+0200 (Central European Summer Time)
2+
# timestamp: Thu Apr 30 2020 19:12:48 GMT+0200 (Central European Summer Time)
33

44
schema {
55
query: RootQuery

packages/app/src/app/graphql/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,10 @@ export type GetTeamQuery = { __typename?: 'RootQueryType' } & {
14711471
me: Maybe<
14721472
{ __typename?: 'CurrentUser' } & {
14731473
team: Maybe<
1474-
{ __typename?: 'Team' } & Pick<Team, 'id' | 'creatorId'> & {
1474+
{ __typename?: 'Team' } & Pick<
1475+
Team,
1476+
'id' | 'creatorId' | 'description' | 'name'
1477+
> & {
14751478
users: Array<
14761479
{ __typename?: 'User' } & Pick<
14771480
User,

packages/app/src/app/overmind/effects/gql/dashboard/queries.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export const getTeam: Query<GetTeamQuery, GetTeamQueryVariables> = gql`
216216
team(id: $teamId) {
217217
id
218218
creatorId
219+
description
220+
name
219221
users {
220222
avatarUrl
221223
name

packages/app/src/app/overmind/namespaces/dashboard/actions.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ export const getTeams: AsyncAction = async ({ state, effects }) => {
139139

140140
state.dashboard.teams = teams.me.teams;
141141
};
142+
143+
export const getTeam: AsyncAction = withLoadApp(async ({ state, effects }) => {
144+
if (!state.dashboard.activeTeam) return;
145+
const team = await effects.gql.queries.getTeam({
146+
teamId: state.dashboard.activeTeam,
147+
});
148+
149+
if (!team || !team.me) {
150+
return;
151+
}
152+
153+
state.dashboard.activeTeamInfo = team.me.team;
154+
});
155+
142156
export const getRecentSandboxes: AsyncAction = withLoadApp(
143157
async ({ state, effects }) => {
144158
const { dashboard } = state;

packages/app/src/app/overmind/namespaces/dashboard/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type State = {
5050
teams: Array<{ __typename?: 'Team' } & Pick<Team, 'id' | 'name'>>;
5151
allCollections: DELETE_ME_COLLECTION[] | null;
5252
activeTeam: string | null;
53+
activeTeamInfo: any | null;
5354
selectedSandboxes: string[];
5455
trashSandboxIds: string[];
5556
isDragging: boolean;
@@ -93,6 +94,7 @@ export const state: State = {
9394
viewMode: 'grid',
9495
allCollections: null,
9596
activeTeam: null,
97+
activeTeamInfo: null,
9698
teams: [],
9799
recentSandboxesByTime: ({ sandboxes }) => {
98100
const recentSandboxes = sandboxes.RECENT;
Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,89 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { useOvermind } from 'app/overmind';
3+
import css from '@styled-system/css';
4+
import { Grid, Element, Stack, Button } from '@codesandbox/components';
5+
import { Box } from './components/Box';
6+
import { Text } from './components/Typography';
7+
import { randomColor } from '../../utils';
38
import { Header } from '../../../Components/Header';
49

510
export const TeamSettings = () => {
611
const {
7-
state: { dashboard },
12+
state: {
13+
dashboard: { activeTeamInfo: team },
14+
},
15+
actions,
816
} = useOvermind();
17+
18+
useEffect(() => {
19+
actions.dashboard.getTeam();
20+
}, [actions.dashboard]);
21+
22+
if (!team) {
23+
return <Header title="Team Settings" />;
24+
}
25+
const created = team.users.find(user => user.id === team.creatorId);
926
return (
1027
<>
1128
<Header title="Team Settings" />
12-
{dashboard.activeTeam}
29+
<Grid
30+
columnGap={4}
31+
css={css({
32+
gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',
33+
})}
34+
>
35+
<Box>
36+
<Stack gap={4} align="flex-start">
37+
{team.avatarUrl ? (
38+
<img src={team.avatarUrl} width="55" alt={team.name} />
39+
) : (
40+
<Stack
41+
align="center"
42+
justify="center"
43+
css={css({
44+
minWidth: 55,
45+
width: 55,
46+
height: 55,
47+
borderRadius: 'medium',
48+
color: 'grays.800',
49+
fontSize: 7,
50+
background: randomColor,
51+
fontWeight: 'bold',
52+
})}
53+
>
54+
{team.name.charAt(0)}
55+
</Stack>
56+
)}
57+
58+
<Element>
59+
<Text weight="bold" block marginBottom={4} size={6}>
60+
{team.name}
61+
</Text>
62+
<Text>Community Plan (Free)</Text>
63+
<Text>{team.description}</Text>
64+
</Element>
65+
</Stack>
66+
</Box>
67+
<Box
68+
title={`${team.users.length} Team Member${
69+
team.users.length === 1 ? '' : 's'
70+
}`}
71+
>
72+
<Text>Created by {created.username}</Text>
73+
</Box>
74+
<Box white title="Team Pro">
75+
<Text white marginBottom={6}>
76+
Get early access and product updates?
77+
</Text>
78+
<Button
79+
href="https://airtable.com/shrlgLSJWiX8rYqyG"
80+
as="a"
81+
target="_blank"
82+
>
83+
Subscribe to Pro
84+
</Button>
85+
</Box>
86+
</Grid>
1387
</>
1488
);
1589
};

packages/app/src/app/pages/NewDashboard/Content/routes/Settings/UserSettings.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const UserSettings = () => {
1414

1515
useEffect(() => {
1616
actions.dashboard.newDashboardMounted();
17-
});
17+
}, [actions.dashboard]);
1818

1919
if (!user) {
2020
return <Header title="User Settings" />;
@@ -43,7 +43,9 @@ export const UserSettings = () => {
4343
</Text>
4444
<Text>{user.name}</Text>
4545
<Text>{user.email}</Text>
46-
<Link href="https://github.com">Managed by Github</Link>
46+
<Link href="https://github.com" target="_blank">
47+
Managed by Github
48+
</Link>
4749
</Element>
4850
</Stack>
4951
</Box>

packages/app/src/app/pages/NewDashboard/Content/routes/Settings/components/Typography.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ type TextProps = {
1111
size?: number;
1212
};
1313

14-
export const Link = ({ href, children }) => (
15-
<LinkBase size={3} css={css({ color: 'button.background' })} href={href}>
14+
type LinkProps = { href: string; children: any; target?: string };
15+
16+
export const Link = ({ href, children, ...props }: LinkProps) => (
17+
<LinkBase
18+
size={3}
19+
css={css({ color: 'button.background' })}
20+
href={href}
21+
{...props}
22+
>
1623
{children}
1724
</LinkBase>
1825
);

packages/app/src/app/pages/NewDashboard/Content/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ export function getPossibleTemplates(sandboxes: any[]) {
1818
template => template.id
1919
);
2020
}
21+
22+
const colors = [
23+
'rgb(0, 122, 255)',
24+
'rgb(52, 199, 89)',
25+
'rgb(255, 45, 85)',
26+
'rgb(88, 86, 214)',
27+
'rgb(255, 149, 0)',
28+
'rgb(90, 200, 250)',
29+
'rgb(175, 82, 22)',
30+
'rgb(255, 200, 250)',
31+
'rgb(69, 235, 195)',
32+
'rgb(255, 59, 48)',
33+
'rgb(212, 69, 235)',
34+
'rgb(192, 235, 69)',
35+
];
36+
export const randomColor = colors[Math.floor(Math.random() * colors.length)];

packages/components/src/components/Button/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface ButtonProps
107107
href?: string;
108108
to?: string;
109109
as?: any;
110+
target?: any;
110111
}
111112

112113
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(

0 commit comments

Comments
 (0)