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.tsx133
1 files changed, 69 insertions, 64 deletions
diff --git a/src/containers/auth/SetupAssistantScreen.tsx b/src/containers/auth/SetupAssistantScreen.tsx
index 661d688aa..0d4c3feec 100644
--- a/src/containers/auth/SetupAssistantScreen.tsx
+++ b/src/containers/auth/SetupAssistantScreen.tsx
@@ -1,88 +1,93 @@
1/* eslint-disable no-await-in-loop */
2import { Component, ReactElement } from 'react'; 1import { Component, ReactElement } from 'react';
3import { inject, observer } from 'mobx-react'; 2import { inject, observer } from 'mobx-react';
4
5import { StoresProps } from '../../@types/ferdium-components.types'; 3import { StoresProps } from '../../@types/ferdium-components.types';
6import sleep from '../../helpers/async-helpers'; 4import sleep from '../../helpers/async-helpers';
7import SetupAssistant from '../../components/auth/SetupAssistant'; 5import SetupAssistant from '../../components/auth/SetupAssistant';
6import { ILegacyServices } from '../../@types/legacy-types';
7
8interface IProps extends StoresProps {}
9
10interface IState {
11 isSettingUpServices: boolean;
12}
13
14@inject('stores', 'actions')
15@observer
16class SetupAssistantScreen extends Component<IProps, IState> {
17 services: ILegacyServices;
18
19 constructor(props: IProps) {
20 super(props);
8 21
9class SetupAssistantScreen extends Component<StoresProps> { 22 this.state = {
10 state = { 23 isSettingUpServices: false,
11 isSettingUpServices: false, 24 };
12 };
13 25
14 // 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 26 // 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
15 services = { 27 this.services = {
16 whatsapp: { 28 whatsapp: {
17 name: 'WhatsApp', 29 name: 'WhatsApp',
18 hasTeamId: false, 30 hasTeamId: false,
19 }, 31 },
20 messenger: { 32 messenger: {
21 name: 'Messenger', 33 name: 'Messenger',
22 hasTeamId: false, 34 hasTeamId: false,
23 }, 35 },
24 gmail: { 36 gmail: {
25 name: 'Gmail', 37 name: 'Gmail',
26 hasTeamId: false, 38 hasTeamId: false,
27 }, 39 },
28 skype: { 40 skype: {
29 name: 'Skype', 41 name: 'Skype',
30 hasTeamId: false, 42 hasTeamId: false,
31 }, 43 },
32 telegram: { 44 telegram: {
33 name: 'Telegram', 45 name: 'Telegram',
34 hasTeamId: false, 46 hasTeamId: false,
35 }, 47 },
36 instagram: { 48 instagram: {
37 name: 'Instagram', 49 name: 'Instagram',
38 hasTeamId: false, 50 hasTeamId: false,
39 }, 51 },
40 slack: { 52 slack: {
41 name: 'Slack', 53 name: 'Slack',
42 hasTeamId: true, 54 hasTeamId: true,
43 }, 55 },
44 hangouts: { 56 hangouts: {
45 name: 'Hangouts', 57 name: 'Hangouts',
46 hasTeamId: false, 58 hasTeamId: false,
47 }, 59 },
48 linkedin: { 60 linkedin: {
49 name: 'LinkedIn', 61 name: 'LinkedIn',
50 hasTeamId: false, 62 hasTeamId: false,
51 }, 63 },
52 }; 64 };
65 }
53 66
54 async setupServices(serviceConfig: any): Promise<void> { 67 async setupServices(serviceConfig: any): Promise<void> {
55 const { 68 const { services, router } = this.props.stores;
56 stores: { services, router },
57 } = this.props;
58 69
59 this.setState({ 70 this.setState({ isSettingUpServices: true });
60 isSettingUpServices: true,
61 });
62 71
63 // The store requests are not build for parallel requests so we need to finish one request after another 72 // The store requests are not build for parallel requests so we need to finish one request after another
64 for (const config of serviceConfig) { 73 for (const config of serviceConfig) {
65 const serviceData = { 74 // eslint-disable-next-line no-await-in-loop
66 name: this.services[config.id].name,
67 team: config.team,
68 };
69
70 await services._createService({ 75 await services._createService({
71 recipeId: config.id, 76 recipeId: config.id,
72 serviceData, 77 serviceData: {
78 name: this.services[config.id].name,
79 team: config.team,
80 },
73 redirect: false, 81 redirect: false,
74 skipCleanup: true, 82 skipCleanup: true,
75 }); 83 });
76 84
85 // eslint-disable-next-line no-await-in-loop
77 await sleep(100); 86 await sleep(100);
78 } 87 }
79 88
80 this.setState({ 89 this.setState({ isSettingUpServices: false });
81 isSettingUpServices: false,
82 });
83
84 await sleep(100); 90 await sleep(100);
85
86 router.push('/'); 91 router.push('/');
87 } 92 }
88 93
@@ -91,11 +96,11 @@ class SetupAssistantScreen extends Component<StoresProps> {
91 <SetupAssistant 96 <SetupAssistant
92 onSubmit={config => this.setupServices(config)} 97 onSubmit={config => this.setupServices(config)}
93 services={this.services} 98 services={this.services}
94 embed={false} 99 // embed={false} // TODO - [TS DEBT][PROP NOT USED IN COMPONENT] check legacy services type
95 isSettingUpServices={this.state.isSettingUpServices} 100 isSettingUpServices={this.state.isSettingUpServices}
96 /> 101 />
97 ); 102 );
98 } 103 }
99} 104}
100 105
101export default inject('stores', 'actions')(observer(SetupAssistantScreen)); 106export default SetupAssistantScreen;