aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/auth/SetupAssistantScreen.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/auth/SetupAssistantScreen.tsx')
-rw-r--r--src/containers/auth/SetupAssistantScreen.tsx116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/containers/auth/SetupAssistantScreen.tsx b/src/containers/auth/SetupAssistantScreen.tsx
new file mode 100644
index 000000000..44bd32772
--- /dev/null
+++ b/src/containers/auth/SetupAssistantScreen.tsx
@@ -0,0 +1,116 @@
1/* eslint-disable no-await-in-loop */
2import { Component } from 'react';
3import { inject, observer } from 'mobx-react';
4
5import { RouterStore } from 'mobx-react-router';
6import { sleep } from '../../helpers/async-helpers';
7import SetupAssistant from '../../components/auth/SetupAssistant';
8import ServicesStore from '../../stores/ServicesStore';
9import RecipesStore from '../../stores/RecipesStore';
10import UserStore from '../../stores/UserStore';
11
12interface IProps {
13 stores: {
14 services?: ServicesStore,
15 router: RouterStore,
16 recipes?: RecipesStore,
17 user?: UserStore,
18 },
19 actions: {
20 user: UserStore,
21 service: ServicesStore,
22 recipe: RecipesStore,
23 },
24};
25
26class SetupAssistantScreen extends Component<IProps> {
27 state = {
28 isSettingUpServices: false,
29 }
30
31 // TODO: Why are these hardcoded here? Do they need to conform to specific services in the packaged recipes? If so, its more important to fix this
32 services = {
33 whatsapp: {
34 name: 'WhatsApp',
35 hasTeamId: false,
36 },
37 messenger: {
38 name: 'Messenger',
39 hasTeamId: false,
40 },
41 gmail: {
42 name: 'Gmail',
43 hasTeamId: false,
44 },
45 skype: {
46 name: 'Skype',
47 hasTeamId: false,
48 },
49 telegram: {
50 name: 'Telegram',
51 hasTeamId: false,
52 },
53 instagram: {
54 name: 'Instagram',
55 hasTeamId: false,
56 },
57 slack: {
58 name: 'Slack',
59 hasTeamId: true,
60 },
61 hangouts: {
62 name: 'Hangouts',
63 hasTeamId: false,
64 },
65 linkedin: {
66 name: 'LinkedIn',
67 hasTeamId: false,
68 },
69 };
70
71 async setupServices(serviceConfig) {
72 const { stores: { services, router } } = this.props;
73
74 this.setState({
75 isSettingUpServices: true,
76 });
77
78 // The store requests are not build for parallel requests so we need to finish one request after another
79 for (const config of serviceConfig) {
80 const serviceData = {
81 name: this.services[config.id].name,
82 team: config.team
83 };
84
85 await services._createService({
86 recipeId: config.id,
87 serviceData,
88 redirect: false,
89 skipCleanup: true,
90 });
91
92 await sleep(100);
93 }
94
95 this.setState({
96 isSettingUpServices: false,
97 });
98
99 await sleep(100);
100
101 router.push('/');
102 }
103
104 render() {
105 return (
106 <SetupAssistant
107 onSubmit={config => this.setupServices(config)}
108 services={this.services}
109 embed={false}
110 isSettingUpServices={this.state.isSettingUpServices}
111 />
112 );
113 }
114}
115
116export default inject('stores', 'actions')(observer(SetupAssistantScreen));