-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestandsend.html
More file actions
123 lines (111 loc) · 3.6 KB
/
testandsend.html
File metadata and controls
123 lines (111 loc) · 3.6 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document Editor</title>
<link
rel="stylesheet"
href="https://unpkg.com/legalesign-document-viewer/ls-document-viewer.css"
/>
<script
type="module"
src="https://unpkg.com/legalesign-document-viewer"
></script>
</head>
<body style="padding: 0; margin: 0">
NOTE::: THIS EXAMPLE IS A WORK IN PROGRESS AND DOES NOT WORK YET. ASW.
<ls-document-viewer
id="my-editor"
templateid="<YOUR_LEGALESIGN_TEMPLATE_ID_HERE>"
token="<YOUR_LEGALESIGN_JWT_TOKEN_HERE>"
mode="compose"
recipients='[{"email": "alice@smashtest.com", "firstname": "Alice", "lastname": "Test", "signerIndex": 1}, {"email": "bob@smashtest.com", "firstname": "Bob", "lastname": "Test", "signerIndex": 2}]'
filtertoolbox="signature|initials|date"
>
<span slot="left-button">
<button onclick="handleCancel()">Cancel</button>
</span>
<span slot="right-button">
<button onclick="handleSend()">Send</button>
</span>
</ls-document-viewer>
<script>
const editor = document.querySelector("ls-document-viewer");
let recipients = [
{
email: "alice@smashtest.com",
firstname: "Alice",
lastname: "Test",
signerIndex: 1,
},
{
email: "bob@smashtest.com",
firstname: "Bob",
lastname: "Test",
signerIndex: 2,
},
];
editor.addEventListener("update", (event) => {
// match any created roles to the recipients and add the id to our recipient array
if (e.detail?.template) {
recipients = recipients.map((r) => {
return e.detail.template.roles.find(
(role) => role.signerIndex === r.signerIndex
) !== undefined
? { ...r, roleId: role.id }
: r;
});
}
});
function handleCancel() {
// Implement the cancel logic, e.g. go to a home page
console.log("Cancelled...");
}
async function send() {
try {
const doc = {
title: "Test Document",
groupId: selectedGroup?.id || null,
templateId: "<YOUR_LEGALESIGN_TEMPLATE_ID_HERE>",
recipients: recipients.map((r, index) => ({
id: index,
role: "SIGNER",
firstName: r.firstName,
lastName: r.lastName,
email: r.email,
roleId: r.roleId,
phoneNumber: r.phoneNumber,
order: index + 1,
timeZone: "Europe/London",
experience: "<YOUR_LEGALESIGN_EXPERIENCE_ID_HERE>",
})),
participantFields: [],
senderFields: [],
allowCopying: false,
allowPrinting: false,
sequentialSigning: true,
};
const client = generateClient();
await client.graphql({
query: `mutation sendSingleDocument {
send(input: ${cleanJSONForGraphQL(doc)})
}`,
});
navigate("/");
} catch (error) {
const message =
error?.errors?.[0]?.message || error?.message || "Unknown error";
console.error("Error sending document:", message);
}
}
function handleSend() {
// Implement send logic if required.
console.log("Sending...");
send().then(() => {
console.log("Sent!");
});
}
</script>
</body>
</html>