-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (72 loc) · 2.35 KB
/
index.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
const { withUiHook } = require("@zeit/integration-utils");
//Actions
const {
disconnect,
sendMsg,
returnWithNav,
messageLogs,
callLogs,
setProjEnvs
} = require("./lib");
//Views
const {
MessageView,
EditEnvView,
CallsView,
TextsView,
Disconnected
} = require("./views");
module.exports = withUiHook(async ({ payload, zeitClient }) => {
const metadata = await zeitClient.getMetadata();
const { action, clientState, projectId } = payload;
try {
switch (action) {
case "disconnect":
await disconnect(zeitClient, metadata);
return returnWithNav(Disconnected)(metadata);
case "send-message":
await sendMsg(metadata, clientState);
return returnWithNav(MessageView)(metadata);
case "clear-message":
clientState.toNumber = "";
clientState.fromNumber = "";
clientState.textMessage = "";
return returnWithNav(MessageView)(metadata);
case "set-envs":
metadata.userTwilioSID = clientState.userTwilioSID;
metadata.twilioAuth = clientState.twilioAuth;
await zeitClient.setMetadata(metadata);
return returnWithNav(EditEnvView)({ metadata, projectId });
case "set-project-envs":
if (projectId) {
await setProjEnvs(metadata, zeitClient, projectId);
}
return returnWithNav(EditEnvView)({ metadata, projectId });
case "clear-envs":
clientState.userTwilioSID = "";
clientState.twilioAuth = "";
metadata.userTwilioSID = "";
metadata.twilioAuth = "";
await zeitClient.setMetadata(metadata);
return returnWithNav(EditEnvView)({metadata});
case "go-to-message-view":
return returnWithNav(MessageView)(clientState);
case "go-to-env-view":
return returnWithNav(EditEnvView)({ metadata, projectId });
case "go-to-calls-view":
const callList = await callLogs(metadata);
return returnWithNav(CallsView)(callList);
case "go-to-texts-view":
const messageList = await messageLogs(metadata);
return returnWithNav(TextsView)(messageList);
default:
if (metadata.userTwilioSID && metadata.twilioAuth) {
return returnWithNav(MessageView)(metadata);
} else {
return returnWithNav(EditEnvView)({metadata});
}
}
} catch (error) {
console.log(error);
}
});