-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-events.js
More file actions
84 lines (82 loc) · 2.55 KB
/
client-events.js
File metadata and controls
84 lines (82 loc) · 2.55 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
74
75
76
77
78
79
80
81
82
83
84
const initialiseEventHandlers = (client) => {
console.log("Initialising event handlers", client.events.enums.TASK_UPDATE);
client.events.on(
client.events.enums.TASK_UPDATE,
async (event) => {
try {
console.log("Task updated", event);
const result = await client.interface.show("dialog", {
title: "Updating a task, blocking from marketplace app",
content: `Are you sure you want to update this task?`,
});
console.log({ event, result });
if (result) {
console.log("resolved", event);
event?.resolve();
} else {
console.log("rejected", event);
event?.reject("User cancelled");
}
} catch (error) {
console.error("Error updating task", error);
event?.reject("Error updating task");
}
},
{ intercept: true }
);
client.events.on(
client.events.enums.TASK_CREATE,
async (event) => {
try {
console.log("Task created", event);
const result = await client.interface.show("dialog", {
title: "Creating a task, blocking from marketplace app",
content: `Are you sure you want to create this task?`,
});
console.log({ event, result });
if (result) {
console.log("resolved", event);
event?.resolve();
} else {
console.log("rejected", event);
event?.reject("User cancelled");
}
} catch (error) {
console.error("Error creating task", error);
event?.reject("Error creating task");
}
},
{ intercept: true }
);
client.events.on(
client.events.enums.TASK_DELETE,
async (event) => {
try {
console.log("Task deleted", event);
const result = await client.interface.show("dialog", {
title: "Deleting a task, blocking from marketplace app",
content: `Are you sure you want to delete this task?`,
});
console.log({ event, result });
if (result) {
console.log("resolved", event);
event?.resolve();
} else {
console.log("rejected", event);
event?.reject("User cancelled");
}
} catch (error) {
console.error("Error creating task", error);
event?.reject("Error creating task");
}
},
// { intercept: true }
);
};
window.initialiseEventHandlers = initialiseEventHandlers;
if (window.rliSdk) {
window.rliSdk.init().then((client) => {
console.log("Client initialised", client);
initialiseEventHandlers(client);
});
}