Skip to content

Commit 13594ed

Browse files
committed
Roughs in the accept invitation routes
1 parent 6d8a13b commit 13594ed

9 files changed

Lines changed: 104 additions & 28 deletions

File tree

apps/authentication/Routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default () => (
2626
/>
2727

2828
<Route
29-
path="/register/:token"
29+
path="/register/:invitation_token"
3030
render={parseRoute(({ params, query }) => (
3131
<AcceptInvitationPage
3232
{...params}

apps/authentication/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ app
1313
.set('views', `${__dirname}/templates`)
1414
.set('view engine', 'jade')
1515

16-
.get(/^\/(sign_up|log_in|forgot|register\/\w+)/, apolloMiddleware, (req, res) => {
16+
.get(/^\/(sign_up|log_in|forgot|register\/\w+)/, apolloMiddleware, (req, res, next) => {
1717
if (req.user && req.user.id) return res.redirect('/');
1818

1919
res.locals.sd.REDIRECT_TO = req.query['redirect-to'] || '/';
2020

2121
return req.apollo.render(withStaticRouter(Routes))
22-
.then(apollo => res.render('index', { apollo }));
22+
.then(apollo => res.render('index', { apollo }))
23+
.catch(next);
2324
})
2425
.get('/me/sign_out', logoutMiddleware, redirectToMiddleware)
2526
.get('/me/refresh', (req, res, next) => {

assets/auth.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import sharify from 'sharify';
2-
31
import { mountWithApolloProvider } from 'react/apollo';
42

53
import withBrowserRouter from 'react/hocs/WithBrowserRouter';
64

75
import Routes from 'apps/authentication/Routes';
86

9-
const { data: { APOLLO } } = sharify;
10-
11-
document.addEventListener('DOMContentLoaded', () => {
12-
const mountPoint = document.getElementById('apolloMount');
13-
mountWithApolloProvider(withBrowserRouter(Routes), APOLLO, mountPoint);
14-
});
7+
document.addEventListener('DOMContentLoaded', () =>
8+
mountWithApolloProvider(withBrowserRouter(Routes), {}, document.getElementById('apolloMount')));

react/components/RegistrationForm/index.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,30 @@ const { REDIRECT_TO } = require('sharify').data;
1919
class RegistrationForm extends Component {
2020
static propTypes = {
2121
register: PropTypes.func.isRequired,
22+
email: PropTypes.string,
23+
invite_token: PropTypes.string,
2224
}
2325

24-
state = {
25-
mode: 'resting',
26-
email: '',
27-
first_name: '',
28-
last_name: '',
29-
password: '',
30-
password_confirmation: '',
31-
accept_terms: false,
32-
receive_newsletter: false,
33-
attributeErrors: {},
34-
errorMessage: null,
26+
static defaultProps = {
27+
email: null,
28+
invite_token: null,
29+
}
30+
31+
constructor(props) {
32+
super(props);
33+
34+
this.state = {
35+
mode: 'resting',
36+
email: props.email || '',
37+
first_name: '',
38+
last_name: '',
39+
password: '',
40+
password_confirmation: '',
41+
accept_terms: false,
42+
receive_newsletter: false,
43+
attributeErrors: {},
44+
errorMessage: null,
45+
};
3546
}
3647

3748
handleInput = fieldName => ({ target: { value: fieldValue } }) =>
@@ -58,6 +69,8 @@ class RegistrationForm extends Component {
5869
handleSubmit = (e) => {
5970
e.preventDefault();
6071

72+
// TODO: Switch on invite_token
73+
6174
const { register } = this.props;
6275

6376
const {
@@ -127,6 +140,7 @@ class RegistrationForm extends Component {
127140
onChange={this.handleEmail}
128141
value={email}
129142
errorMessage={attributeErrors.email}
143+
readOnly={!!this.props.email}
130144
required
131145
/>
132146

react/components/UI/Box/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import styled from 'styled-components';
2-
import { display, space, width, alignItems, minHeight } from 'styled-system';
2+
import { display, space, width, alignItems, minHeight, justifyContent, flexDirection } from 'styled-system';
33

44
export default styled.div`
55
${display}
66
${width}
7+
${minHeight}
78
${space}
89
${alignItems}
9-
${minHeight}
10+
${justifyContent}
11+
${flexDirection}
1012
`;

react/components/UI/CenteringBox/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default styled(Box).attrs({
77
width: '100%',
88
minHeight: '100vh',
99
alignItems: 'center',
10+
justifyContent: 'center',
1011
})`
1112
`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import gql from 'graphql-tag';
2+
3+
export default gql`
4+
fragment Invitee on Invitee {
5+
__typename
6+
id
7+
email
8+
}
9+
`;
Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Query } from 'react-apollo';
24

5+
import inviteeQuery from 'react/pages/authentication/AcceptInvitationPage/queries/invitee';
6+
7+
import Icon from 'react/components/UI/Icon';
38
import CenteringBox from 'react/components/UI/CenteringBox';
9+
import Text from 'react/components/UI/Text';
410
import RegistrationForm from 'react/components/RegistrationForm';
511

6-
export default class RegistrationPage extends Component {
12+
export default class AcceptInvitationPage extends Component {
13+
static propTypes = {
14+
invitation_token: PropTypes.string.isRequired,
15+
// Double check this actually does what it says it does
16+
invite_token: PropTypes.string.isRequired,
17+
}
18+
719
render() {
20+
const { invitation_token, invite_token } = this.props;
21+
822
return (
9-
<CenteringBox p={7}>
10-
<RegistrationForm />
11-
</CenteringBox>
23+
<Query query={inviteeQuery} variables={{ invitation_token }}>
24+
{({ loading, error, data }) => {
25+
if (loading) return <div />;
26+
27+
if (error) {
28+
return (
29+
<CenteringBox p={7} flexDirection="column">
30+
<Icon name="ArenaMark" size={7} mb={9} />
31+
32+
<Text f={5} mb={6}>
33+
We cannot find that invitation code.
34+
</Text>
35+
36+
<Text f={2} underlineLinks>
37+
If you believe this is in error please contact
38+
{' '}
39+
<a href="mailto:help@are.na">help@are.na</a>
40+
</Text>
41+
</CenteringBox>
42+
);
43+
}
44+
45+
return (
46+
<CenteringBox p={7}>
47+
<RegistrationForm
48+
email={data.invitee.email}
49+
invite_token={invite_token}
50+
/>
51+
</CenteringBox>
52+
);
53+
}}
54+
</Query>
1255
);
1356
}
1457
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import gql from 'graphql-tag';
2+
3+
import inviteeFragment from 'react/pages/authentication/AcceptInvitationPage/fragments/invitee';
4+
5+
export default gql`
6+
query Invitee($invitation_token: String!) {
7+
invitee(invitation_token: $invitation_token) {
8+
...Invitee
9+
}
10+
}
11+
${inviteeFragment}
12+
`;

0 commit comments

Comments
 (0)