This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
CreateOrganizationFlow.js
127 lines (117 loc) · 3.25 KB
/
CreateOrganizationFlow.js
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
import React from "react";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import { addOrganization } from "queries/organizations";
import { createUserAndProfile } from "auth";
import { handleError } from "utils";
import CreateOrganizationForm from "./CreateOrganizationForm";
import SignUpForm from "./SignUpForm";
import InviteLink from "./InviteLink";
const OrganizationStep = ({ onDone }) => {
return (
<div>
<Typography gutterBottom>
Start using Boxwise to manage your warehouse by signing up here.
</Typography>
<Typography gutterBottom>
After giving us a few details about your organization, you'll then be
able to invite your co-workers to join you in using Boxwise.
</Typography>
<br />
<br />
<CreateOrganizationForm
onSubmit={(data, { setSubmitting, setErrors }) => {
setSubmitting(false);
onDone(data);
}}
/>
</div>
);
};
const UserStep = ({ organizationData, onDone }) => {
return (
<SignUpForm
submitButtonText="Continue"
onSubmit={({ name, email, password }, { setSubmitting, setErrors }) => {
return addOrganization(organizationData)
.then(organization => {
return createUserAndProfile(
{ email, password },
{ name, organization }
);
})
.then(onDone)
.catch(error => {
setSubmitting(false);
// TODO: handle user errors, log everything else
handleError(error);
setErrors({ form: error.message });
});
}}
/>
);
};
const InviteStep = ({ onDone }) => {
return (
<div>
{/* put the button inside the component so it doesn't show while loading */}
<InviteLink
extra={
<React.Fragment>
<br />
<br />
<Button variant="contained" color="primary" onClick={onDone}>
Continue
</Button>
</React.Fragment>
}
/>
</div>
);
};
const DoneStep = ({ onDone }) => {
return (
<div>
<Typography gutterBottom>
That’s it! You’re all set up. Let’s start making some boxes...
</Typography>
<br />
<br />
<Button variant="contained" color="primary" onClick={onDone}>
Start using Boxwise
</Button>
</div>
);
};
class CreateOrganizationFlow extends React.Component {
state = {
step: "organization",
organizationData: null
};
render() {
switch (this.state.step) {
case "organization":
return (
<OrganizationStep
onDone={data => {
this.setState({ organizationData: data, step: "user" });
}}
/>
);
case "user":
return (
<UserStep
organizationData={this.state.organizationData}
onDone={user => this.setState({ step: "invite" })}
/>
);
case "invite":
return <InviteStep onDone={() => this.setState({ step: "done" })} />;
case "done":
return <DoneStep onDone={this.props.onDone} />;
default:
throw new Error("unknown step");
}
}
}
export default CreateOrganizationFlow;