This repository was archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPreferences.js
More file actions
73 lines (66 loc) · 1.87 KB
/
Copy pathPreferences.js
File metadata and controls
73 lines (66 loc) · 1.87 KB
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
function getPreferences() {
const prefs = PropertiesService.getUserProperties().getProperties();
if (prefs.token_v2 === undefined) {
prefs.token_v2 = "";
}
if (prefs.dbSettings === undefined) {
prefs.dbSettings = {};
} else {
prefs.dbSettings = JSON.parse(prefs.dbSettings);
}
return prefs;
}
function deletePreferences(e) {
PropertiesService.getUserProperties().deleteAllProperties();
return CardService.newActionResponseBuilder()
.setNotification(
CardService.newNotification().setText("Logged out successfully.")
)
.setNavigation(
CardService.newNavigation()
.popToRoot()
.updateCard(RootCard())
)
.build();
}
function savePreferences(e) {
const userProperties = PropertiesService.getUserProperties();
userProperties.setProperties(
{
token_v2: e.commonEventObject.formInputs.token_v2.stringInputs.value[0]
},
true
);
function getUserInfo() {
const data = post("loadUserContent");
const user =
data.recordMap.notion_user[Object.keys(data.recordMap.notion_user)[0]]
.value;
const name = user.given_name + " " + user.family_name;
const email = user.email;
const photo = user.profile_photo;
const settings =
data.recordMap.user_settings[Object.keys(data.recordMap.user_settings)[0]]
.value.settings;
const locale = settings.locale;
const timezone = settings.time_zone;
return {
user_name: name,
user_email: email,
user_photo: photo,
user_locale: locale,
user_timezone: timezone
};
}
userProperties.setProperties(getUserInfo());
return CardService.newActionResponseBuilder()
.setNotification(
CardService.newNotification().setText("Logged in successfully.")
)
.setNavigation(
CardService.newNavigation()
.popToRoot()
.updateCard(RootCard())
)
.build();
}