Skip to content

Commit 84c2abd

Browse files
committed
Add team page
1 parent eea3b35 commit 84c2abd

File tree

8 files changed

+2684
-2525
lines changed

8 files changed

+2684
-2525
lines changed

package-lock.json

Lines changed: 2513 additions & 2513 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Terms from './landing/Terms'
99
import Privacy from './landing/Privacy'
1010
import Tshirt from './landing/Tshirt'
1111
import Welcome from './landing/Welcome'
12+
import Team from './landing/Team'
1213
import logo from '../logo.svg'
1314
import StarCount from './StarCount'
1415
import TableOfContents from './TableOfContents'
@@ -66,6 +67,14 @@ class App extends Component {
6667
</header>
6768
<Switch>
6869
{/* <Route exact path="/" render={() => <Redirect to="/Preface" />} /> */}
70+
<Route
71+
path="/team/:token"
72+
render={({
73+
match: {
74+
params: { token }
75+
}
76+
}) => <Team {...authProps} urlToken={token} />}
77+
/>
6978
<Route
7079
exact
7180
path="/me"

src/components/landing/Payment.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,24 @@ class Payment extends Component {
8989
state: { packageInfo, licenses: this.state.licenses }
9090
}}
9191
>
92-
by Paypal
92+
by PayPal
9393
</Link>
9494
<br />
9595
or by check to:
9696
</p>
9797
<p>
9898
The GraphQL Guide
99-
<br />2443 Fillmore St #380-2914
100-
<br />San Francisco, CA 94115
99+
<br />
100+
2443 Fillmore St #380-2914
101+
<br />
102+
San Francisco, CA 94115
101103
</p>
102104
</div>
103105
) : (
104106
<p>
105107
or manually{' '}
106108
<Link to={{ pathname: '/paypal', state: { packageInfo } }}>
107-
via Paypal
109+
via PayPal
108110
</Link>
109111
</p>
110112
)}

src/components/landing/Paypal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Paypal = ({ user, login, loading, location, match }) => {
2727
</p>
2828
<p>
2929
<b>Step 1: </b>
30-
Send ${price} via Paypal. Put your Github username in the payment
30+
Send ${price} via PayPal. Put your Github username in the payment
3131
note.
3232
</p>
3333
<p style={{ textAlign: 'center' }}>

src/components/landing/Team.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import React from 'react'
2+
import { Query, withApollo } from 'react-apollo'
3+
import gql from 'graphql-tag'
4+
import Button from 'material-ui/Button'
5+
import { withRouter } from 'react-router'
6+
7+
let attemptingToClaim = false
8+
9+
const Team = ({ urlToken, user, login, client, history }) => {
10+
const claimSeat = async () => {
11+
if (user) {
12+
if (user.hasPurchased && !attemptingToClaim) {
13+
alert(
14+
'You already have access to the Guide. Contact us with questions: team@graphql.guide'
15+
)
16+
} else {
17+
// todo spinner
18+
await client.mutate({ mutation: JOIN_TEAM, variables: { urlToken } })
19+
history.push('/welcome')
20+
}
21+
attemptingToClaim = false
22+
} else {
23+
attemptingToClaim = true
24+
login()
25+
}
26+
}
27+
28+
const claimerJustLoggedIn = attemptingToClaim && user
29+
if (claimerJustLoggedIn) {
30+
claimSeat()
31+
}
32+
33+
return (
34+
<main className="Team">
35+
<Query query={TEAM_QUERY} variables={{ urlToken }}>
36+
{({ loading, data }) => {
37+
if (loading) return <div className="Spinner" />
38+
39+
if (!data.team) return 'No such team'
40+
const {
41+
team: { name, totalSeats, members }
42+
} = data
43+
const seatsLeft = totalSeats - members.length
44+
45+
return (
46+
<div>
47+
<div className="Team-header-wrapper">
48+
<header className="Team-header">
49+
<h1>Team {name}</h1>
50+
</header>
51+
</div>
52+
<div className="Team-content">
53+
{seatsLeft && (
54+
<p>
55+
{seatsLeft} seats left
56+
<Button
57+
color="primary"
58+
variant="raised"
59+
className="Team-claim-seat"
60+
onClick={claimSeat}
61+
>
62+
Claim seat
63+
</Button>
64+
</p>
65+
)}
66+
<div className="Team-member-list">
67+
<p>Team members:</p>
68+
<ul>
69+
{members.map(({ name, id }) => (
70+
<li key={id}>{name}</li>
71+
))}
72+
</ul>
73+
</div>
74+
<p className="Team-summary">
75+
{totalSeats}-seat license. Add 5 more seats{' '}
76+
<a href="//paypal.me/graphqlguide/1000">by PayPal</a>. (Put
77+
the team name in the payment note.)
78+
</p>
79+
</div>
80+
</div>
81+
)
82+
}}
83+
</Query>
84+
</main>
85+
)
86+
}
87+
88+
const TEAM_QUERY = gql`
89+
query TeamQuery($urlToken: String!) {
90+
team(urlToken: $urlToken) {
91+
id
92+
members {
93+
id
94+
name
95+
}
96+
name
97+
totalSeats
98+
}
99+
}
100+
`
101+
102+
const JOIN_TEAM = gql`
103+
mutation JoinTeamMutation($urlToken: String!) {
104+
joinTeam(urlToken: $urlToken) {
105+
id
106+
members {
107+
id
108+
name
109+
hasPurchased
110+
}
111+
}
112+
}
113+
`
114+
115+
export default withApollo(withRouter(Team))

src/components/landing/Welcome.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class Welcome extends Component {
5757
We're emailing you at {user.email} with the latest version of the
5858
book.
5959
</p>
60+
{user.hasPurchased === 'TEAM' && (
61+
<p>
62+
We're also sending an email explaining how to use your team
63+
license.
64+
</p>
65+
)}
6066
{this.state.offerTshirt && (
6167
<div className="Welcome-tshirt">
6268
Would you like a tshirt?

src/index.css

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ li.numbered > .TableOfContents-chapter-link {
326326

327327
.Section,
328328
.Profile,
329+
.Team,
329330
.Reviews {
330331
position: absolute;
331332
top: var(--header-h);
@@ -335,6 +336,7 @@ li.numbered > .TableOfContents-chapter-link {
335336

336337
.Section-header-wrapper,
337338
.Profile-header-wrapper,
339+
.Team-header-wrapper,
338340
.Reviews-header-wrapper {
339341
padding: 30px 0;
340342
margin-bottom: 60px;
@@ -350,6 +352,8 @@ li.numbered > .TableOfContents-chapter-link {
350352
.Section-content,
351353
.Profile-header,
352354
.Profile-content,
355+
.Team-header,
356+
.Team-content,
353357
.Reviews-header,
354358
.Reviews-content {
355359
width: 80%;
@@ -358,6 +362,7 @@ li.numbered > .TableOfContents-chapter-link {
358362
}
359363

360364
.Section-header h1,
365+
.Team-header h1,
361366
.Profile-header h1 {
362367
font-size: 2.5em;
363368
font-weight: normal;
@@ -421,28 +426,49 @@ body {
421426
padding: 60px 0 30px;
422427
}
423428

424-
.Profile {
429+
.Profile,
430+
.Team {
425431
left: 0;
426432
right: 0;
427433
bottom: 0;
428434
}
429435

430-
.Profile {
436+
.Profile,
437+
.Team {
431438
text-align: center;
432439
}
433440

434-
.Profile-header-wrapper {
441+
.Profile-header-wrapper,
442+
.Team-header-wrapper {
435443
justify-self: start;
436444
}
437445

438-
.Profile h1 {
446+
.Profile h1,
447+
.Team h1 {
439448
font-weight: normal;
440449
}
441450

442-
.Profile-content {
451+
.Profile-content,
452+
.Team-content {
443453
width: 500px;
444454
}
445455

456+
.Team-member-list {
457+
margin: 80px 0;
458+
text-align: left;
459+
}
460+
461+
.Team-claim-seat {
462+
margin-left: 20px !important;
463+
margin-bottom: 3px !important;
464+
}
465+
466+
.Team-summary {
467+
border-top: 1px solid var(--gray700);
468+
margin: 0px 16px;
469+
padding: 20px;
470+
}
471+
446472
.Profile a {
447473
color: var(--pink);
448474
}
@@ -466,7 +492,8 @@ body {
466492
margin-top: var(--vert-spacer);
467493
}
468494

469-
.Profile > .Spinner {
495+
.Profile > .Spinner,
496+
.Team > .Spinner {
470497
margin-left: calc(50% - 12.5px); /* half of spinner width */
471498
margin-top: var(--vert-spacer);
472499
color: var(--pink);

src/lib/payment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const associateToken = async () => {
137137
return
138138
}
139139

140-
const done = localStorage.getItem('stripe.associatedTokenWithUser')
140+
const done = localStorage.getItem('stripe.associatedTokenWithUser') === 'true'
141141
if (done) {
142142
return
143143
}

0 commit comments

Comments
 (0)