diff options
author | 2022-05-08 21:00:17 -0500 | |
---|---|---|
committer | 2022-05-08 22:19:29 -0400 | |
commit | db25991927e9b74eda2f3a9df5d01908abc04208 (patch) | |
tree | 28b82e6e50512ceecdae4e6d2ddec50f0c7835b5 /src/containers/auth/SetupAssistantScreen.tsx | |
parent | New Crowdin updates (#119) [skip ci] (diff) | |
download | ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.tar.gz ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.tar.zst ferdium-app-db25991927e9b74eda2f3a9df5d01908abc04208.zip |
Converted some javascript files to typescript
Diffstat (limited to 'src/containers/auth/SetupAssistantScreen.tsx')
-rw-r--r-- | src/containers/auth/SetupAssistantScreen.tsx | 116 |
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 */ | ||
2 | import { Component } from 'react'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | |||
5 | import { RouterStore } from 'mobx-react-router'; | ||
6 | import { sleep } from '../../helpers/async-helpers'; | ||
7 | import SetupAssistant from '../../components/auth/SetupAssistant'; | ||
8 | import ServicesStore from '../../stores/ServicesStore'; | ||
9 | import RecipesStore from '../../stores/RecipesStore'; | ||
10 | import UserStore from '../../stores/UserStore'; | ||
11 | |||
12 | interface 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 | |||
26 | class 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 | |||
116 | export default inject('stores', 'actions')(observer(SetupAssistantScreen)); | ||