forked from StateVoicesNational/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateOrganization.jsx
169 lines (161 loc) · 4.13 KB
/
CreateOrganization.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import PropTypes from "prop-types";
import React from "react";
import loadData from "./hoc/load-data";
import gql from "graphql-tag";
import Form from "react-formal";
import * as yup from "yup";
import { StyleSheet, css } from "aphrodite";
import theme from "../styles/theme";
import Paper from "@material-ui/core/Paper";
import { withRouter } from "react-router";
import GSForm from "../components/forms/GSForm";
import GSSubmitButton from "../components/forms/GSSubmitButton";
import GSTextField from "../components/forms/GSTextField";
import { dataTest } from "../lib/attributes";
const styles = StyleSheet.create({
container: {
marginTop: "5vh",
textAlign: "center"
},
formContainer: {
...theme.layouts.greenBox
},
bigHeader: {
...theme.text.header,
fontSize: 40
},
header: {
...theme.text.header,
marginRight: "auto",
marginLeft: "auto",
maxWidth: "80%"
},
form: {
marginTop: 40,
maxWidth: "80%",
marginRight: "auto",
marginLeft: "auto"
}
});
class CreateOrganization extends React.Component {
formSchema = yup.object({
name: yup.string().required()
});
renderInvalid() {
return (
<div>
That invite is no longer valid. This probably means it already got used!
</div>
);
}
renderForm() {
return (
<div>
<div className={css(styles.header)}>
Create your organization to get started.
</div>
<div className={css(styles.form)}>
<Paper style={{ padding: 20 }}>
<GSForm
schema={this.formSchema}
onSubmit={async formValues => {
const newOrganization = await this.props.mutations.createOrganization(
formValues.name,
this.props.userData.currentUser.id,
this.props.inviteData.inviteByHash[0].id
);
this.props.router.push(
`/admin/${newOrganization.data.createOrganization.id}`
);
}}
>
<Form.Field
as={GSTextField}
{...dataTest("organization")}
name="name"
label="Your organization"
hintText="Bartlet Campaign"
fullWidth
/>
<Form.Submit
as={GSSubmitButton}
label="Get Started"
name="submit"
value="Get Started"
fullWidth
secondary
style={{ marginTop: 40 }}
/>
</GSForm>
</Paper>
</div>
</div>
);
}
render() {
return (
<div className={css(styles.container)}>
<div className={css(styles.bigHeader)}>Spoke</div>
<div className={css(styles.formContainer)}>
{this.props.inviteData.inviteByHash &&
this.props.inviteData.inviteByHash[0].isValid
? this.renderForm()
: this.renderInvalid()}
</div>
</div>
);
}
}
CreateOrganization.propTypes = {
mutations: PropTypes.object,
router: PropTypes.object,
userData: PropTypes.object,
inviteData: PropTypes.object
};
const queries = {
inviteData: {
query: gql`
query getInvite($inviteId: String!) {
inviteByHash(hash: $inviteId) {
id
isValid
}
}
`,
options: ownProps => ({
variables: {
inviteId: ownProps.params.inviteId
},
fetchPolicy: "network-only"
})
},
userData: {
query: gql`
query getCurrentUser {
currentUser {
id
}
}
`,
options: ownProps => ({
fetchPolicy: "network-only"
})
}
};
const mutations = {
createOrganization: ownProps => (name, userId, inviteId) => ({
mutation: gql`
mutation createOrganization(
$name: String!
$userId: String!
$inviteId: String!
) {
createOrganization(name: $name, userId: $userId, inviteId: $inviteId) {
id
}
}
`,
variables: { name, userId, inviteId }
})
};
export default loadData({ queries, mutations })(withRouter(CreateOrganization));