@salesforcedevs/dw-components 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/lwc.config.json +24 -0
- package/package.json +26 -0
- package/src/modules/dw/blogsGrid/blogsGrid.css +89 -0
- package/src/modules/dw/blogsGrid/blogsGrid.html +73 -0
- package/src/modules/dw/blogsGrid/blogsGrid.ts +28 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.css +3 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.html +16 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.ts +29 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.css +3 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.html +12 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.ts +29 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.css +171 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.html +138 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.ts +431 -0
- package/src/modules/dw/contentArchive/altData.js +3 -0
- package/src/modules/dw/contentArchive/contentArchive.css +242 -0
- package/src/modules/dw/contentArchive/contentArchive.html +340 -0
- package/src/modules/dw/contentArchive/contentArchive.ts +519 -0
- package/src/modules/dw/contentArchive/contentArchive.types.ts +98 -0
- package/src/modules/dw/contentArchive/utils.ts +193 -0
- package/src/modules/dw/deSignupForm/deSignupForm.css +75 -0
- package/src/modules/dw/deSignupForm/deSignupForm.html +117 -0
- package/src/modules/dw/deSignupForm/deSignupForm.ts +269 -0
- package/src/modules/dw/deSignupForm/submitForm.ts +93 -0
- package/src/modules/dw/docsGrid/docsGrid.css +83 -0
- package/src/modules/dw/docsGrid/docsGrid.html +89 -0
- package/src/modules/dw/docsGrid/docsGrid.ts +540 -0
- package/src/modules/dw/eventsList/eventsList.css +113 -0
- package/src/modules/dw/eventsList/eventsList.html +98 -0
- package/src/modules/dw/eventsList/eventsList.ts +192 -0
- package/src/modules/dw/instrumentation/instrumentation.html +1 -0
- package/src/modules/dw/instrumentation/instrumentation.ts +97 -0
- package/src/modules/dw/newsletterForm/newsletterForm.css +74 -0
- package/src/modules/dw/newsletterForm/newsletterForm.html +67 -0
- package/src/modules/dw/newsletterForm/newsletterForm.ts +233 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.css +91 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.html +24 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.ts +52 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.css +5 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.html +29 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.ts +9 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.css +32 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.html +36 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.ts +3 -0
- package/src/modules/dw/rcgTable/altData.ts +78 -0
- package/src/modules/dw/rcgTable/getTableData.ts +10 -0
- package/src/modules/dw/rcgTable/rcgTable.css +39 -0
- package/src/modules/dw/rcgTable/rcgTable.html +31 -0
- package/src/modules/dw/rcgTable/rcgTable.ts +34 -0
- package/src/modules/dw/slackCta/slackCta.css +47 -0
- package/src/modules/dw/slackCta/slackCta.html +17 -0
- package/src/modules/dw/slackCta/slackCta.ts +12 -0
- package/src/modules/dw/slackSuccess/slackSuccess.css +65 -0
- package/src/modules/dw/slackSuccess/slackSuccess.html +32 -0
- package/src/modules/dw/slackSuccess/slackSuccess.ts +34 -0
- package/src/modules/dwBaseElements/postsGrid/postsGrid.ts +80 -0
- package/src/modules/dwHelpers/postsGrid/postsGrid.css +9 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import qs from "query-string";
|
|
2
|
+
import {
|
|
3
|
+
ArchivePost,
|
|
4
|
+
ArchivePostNormalized,
|
|
5
|
+
FilterMenuData,
|
|
6
|
+
FilterMenuItem
|
|
7
|
+
} from "./contentArchive.types";
|
|
8
|
+
import altData from "./altData.js";
|
|
9
|
+
|
|
10
|
+
let postsController: AbortController | null = null;
|
|
11
|
+
let filtersController: AbortController | null = null;
|
|
12
|
+
|
|
13
|
+
const ARCHIVE_BASE_URL = "https://developer.salesforce.com/blogs/wp-json/wp/v2";
|
|
14
|
+
const ARCHIVE_CONTENT_URL = `${ARCHIVE_BASE_URL}/latest-post-per-site`;
|
|
15
|
+
const ARCHIVE_FILTER_LIST_URL = `${ARCHIVE_BASE_URL}/archives-filters?order=DESC`;
|
|
16
|
+
export const PER_PAGE_COUNT = 10;
|
|
17
|
+
|
|
18
|
+
async function postsFetchHandler(url: string) {
|
|
19
|
+
if (postsController) {
|
|
20
|
+
postsController.abort();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
postsController = new AbortController();
|
|
24
|
+
const { signal } = postsController;
|
|
25
|
+
|
|
26
|
+
const response = await fetch(url, { signal });
|
|
27
|
+
|
|
28
|
+
if (response.ok) {
|
|
29
|
+
return {
|
|
30
|
+
posts: await response.json(),
|
|
31
|
+
totalPages: Number(response.headers.get("x-wp-totalpages")),
|
|
32
|
+
totalResults: Number(response.headers.get("x-wp-total"))
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.error("Error fetching posts");
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
posts: [],
|
|
40
|
+
totalResults: 0,
|
|
41
|
+
totalPages: 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getAudioDuration(duration: string) {
|
|
46
|
+
const durationSplit = duration.split(":");
|
|
47
|
+
const hours = Number(durationSplit[0]);
|
|
48
|
+
const minutes = Number(durationSplit[1]);
|
|
49
|
+
const seconds = Number(durationSplit[2]);
|
|
50
|
+
|
|
51
|
+
const roundSecondsIntoMinutes = Math.round(seconds / 60);
|
|
52
|
+
|
|
53
|
+
return hours
|
|
54
|
+
? `${minutes + roundSecondsIntoMinutes * (hours * 60)} MIN`
|
|
55
|
+
: `${minutes + roundSecondsIntoMinutes} MIN`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function normalizePosts(posts: Array<ArchivePost>, contentType: string) {
|
|
59
|
+
return posts.map((post) => ({
|
|
60
|
+
id: post.id,
|
|
61
|
+
title: post.title.rendered,
|
|
62
|
+
date: post.date,
|
|
63
|
+
contentType: post.sitename,
|
|
64
|
+
href: post.link,
|
|
65
|
+
...(contentType === "expanded" && {
|
|
66
|
+
excerpt: post.excerpt,
|
|
67
|
+
duration: getAudioDuration(post.podcast_audio.duration),
|
|
68
|
+
...(post._embedded &&
|
|
69
|
+
post._embedded.author[0].id && {
|
|
70
|
+
author: post._embedded.author[0],
|
|
71
|
+
authorImgSrc: post._embedded.author[0].avatar_urls["24"],
|
|
72
|
+
topics: post._embedded["wp:term"][0].map(
|
|
73
|
+
(term: any) => term.name
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function getArchivePosts({
|
|
81
|
+
count = PER_PAGE_COUNT,
|
|
82
|
+
page = 1,
|
|
83
|
+
contentType = "minimal",
|
|
84
|
+
filterMenuData = {
|
|
85
|
+
contentType: [],
|
|
86
|
+
dates: [],
|
|
87
|
+
authors: [],
|
|
88
|
+
categories: []
|
|
89
|
+
}
|
|
90
|
+
}: {
|
|
91
|
+
count: number;
|
|
92
|
+
page: number;
|
|
93
|
+
contentType: "minimal" | "expanded";
|
|
94
|
+
filterMenuData: FilterMenuData;
|
|
95
|
+
}): Promise<ArchivePostNormalized> {
|
|
96
|
+
const filterQuery = {
|
|
97
|
+
site: filterMenuData.contentType.map(
|
|
98
|
+
(siteType: FilterMenuItem) => siteType.id
|
|
99
|
+
),
|
|
100
|
+
dates: filterMenuData.dates.map((date: FilterMenuItem) =>
|
|
101
|
+
date.shortName ? date.shortName : date.id
|
|
102
|
+
),
|
|
103
|
+
author: filterMenuData.authors.map(
|
|
104
|
+
(author: FilterMenuItem) => author.id
|
|
105
|
+
),
|
|
106
|
+
category: filterMenuData.categories.map(
|
|
107
|
+
(category: FilterMenuItem) => category.id
|
|
108
|
+
)
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const COMMON_FIELDS = [
|
|
112
|
+
"id",
|
|
113
|
+
"title",
|
|
114
|
+
"date",
|
|
115
|
+
"sitename",
|
|
116
|
+
"link",
|
|
117
|
+
"podcast_audio"
|
|
118
|
+
];
|
|
119
|
+
const EXPANDED_FIELDS = [
|
|
120
|
+
"excerpt",
|
|
121
|
+
"_embedded",
|
|
122
|
+
"_links.author",
|
|
123
|
+
"_links.wp:term.0"
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const query: any = {
|
|
127
|
+
...filterQuery,
|
|
128
|
+
_fields: ["id", "title", "date", "sitename", "link"],
|
|
129
|
+
per_page: count,
|
|
130
|
+
page
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (contentType === "minimal") {
|
|
134
|
+
query._fields.filter((field: string) =>
|
|
135
|
+
EXPANDED_FIELDS.includes(field)
|
|
136
|
+
);
|
|
137
|
+
delete query._embed;
|
|
138
|
+
} else {
|
|
139
|
+
query._fields = [...COMMON_FIELDS, ...EXPANDED_FIELDS];
|
|
140
|
+
query._embed = ["author", "wp:term"];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const postsUrl = `${qs.stringifyUrl(
|
|
144
|
+
{
|
|
145
|
+
url: ARCHIVE_CONTENT_URL,
|
|
146
|
+
query
|
|
147
|
+
},
|
|
148
|
+
{ arrayFormat: "comma" }
|
|
149
|
+
)}`;
|
|
150
|
+
|
|
151
|
+
// need to format dates with brackets instead of commas
|
|
152
|
+
const urlWithoutDates = qs.pick(
|
|
153
|
+
postsUrl,
|
|
154
|
+
(name: string) => name !== "dates"
|
|
155
|
+
);
|
|
156
|
+
const dateString = qs.stringify(
|
|
157
|
+
{ dates: query.dates },
|
|
158
|
+
{ arrayFormat: "bracket" }
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const { posts, totalPages, totalResults } = await postsFetchHandler(
|
|
162
|
+
`${urlWithoutDates}${dateString && "&"}${dateString}`
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
posts: normalizePosts(posts, contentType),
|
|
167
|
+
totalPages,
|
|
168
|
+
totalResults
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function getArchiveFilterList(postType: string = "all") {
|
|
173
|
+
if (filtersController) {
|
|
174
|
+
filtersController.abort();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
filtersController = new AbortController();
|
|
178
|
+
const { signal } = filtersController;
|
|
179
|
+
|
|
180
|
+
const response = await fetch(
|
|
181
|
+
`${ARCHIVE_FILTER_LIST_URL}${
|
|
182
|
+
postType !== "all" ? `&post-type=${postType}` : ""
|
|
183
|
+
}`,
|
|
184
|
+
{ signal }
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
if (response.ok) {
|
|
188
|
+
return response.json();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
console.error("Error fetching filter list, using fallback instead");
|
|
192
|
+
return altData;
|
|
193
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
form {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dx-input {
|
|
11
|
+
--dx-c-input-width: 100%;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
dx-input,
|
|
15
|
+
dx-select {
|
|
16
|
+
display: block;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 80px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
span {
|
|
22
|
+
font-size: var(--dx-g-text-sm);
|
|
23
|
+
line-height: var(--dx-g-text-lg);
|
|
24
|
+
display: block;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dx-checkbox,
|
|
28
|
+
:not(dx-checkbox) > span {
|
|
29
|
+
margin-bottom: var(--dx-g-spacing-lg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
span a {
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
color: var(--dx-g-blue-vibrant-50);
|
|
35
|
+
transition: var(--dx-g-transition-hue-1x);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
span a:hover {
|
|
39
|
+
color: var(--dx-g-blue-vibrant-30);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dx-input.username-field {
|
|
43
|
+
height: initial;
|
|
44
|
+
min-height: 105px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
form > .full-name-field {
|
|
48
|
+
width: calc(50% - var(--dx-g-spacing-lg) / 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.legal-terms {
|
|
52
|
+
margin-top: var(--dx-g-spacing-lg);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.submit-button {
|
|
56
|
+
width: 100%;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.form-submit:hover {
|
|
60
|
+
background-color: var(--dx-g-blue-vibrant-40);
|
|
61
|
+
border-color: var(--dx-g-blue-vibrant-40);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@media screen and (min-width: 641px) {
|
|
65
|
+
form > .full-name-field:first-of-type {
|
|
66
|
+
margin-right: var(--dx-g-spacing-lg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@media screen and (max-width: 640px) {
|
|
71
|
+
form > dx-input.full-name-field {
|
|
72
|
+
width: 100%;
|
|
73
|
+
margin-right: 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<form onkeydown={handleKeyDown}>
|
|
3
|
+
<dx-input
|
|
4
|
+
class="full-name-field"
|
|
5
|
+
label="First Name"
|
|
6
|
+
missing-error-message="Enter your first name"
|
|
7
|
+
name="first_name"
|
|
8
|
+
placeholder="Your first name"
|
|
9
|
+
required
|
|
10
|
+
validity-on-blur
|
|
11
|
+
></dx-input>
|
|
12
|
+
<dx-input
|
|
13
|
+
class="full-name-field"
|
|
14
|
+
label="Last Name"
|
|
15
|
+
missing-error-message="Enter your last name"
|
|
16
|
+
name="last_name"
|
|
17
|
+
placeholder="Your last name"
|
|
18
|
+
required
|
|
19
|
+
validity-on-blur
|
|
20
|
+
></dx-input>
|
|
21
|
+
<dx-input
|
|
22
|
+
label="Email"
|
|
23
|
+
missing-error-message="Enter your email address"
|
|
24
|
+
name="email"
|
|
25
|
+
placeholder="Your email address"
|
|
26
|
+
required
|
|
27
|
+
type="email"
|
|
28
|
+
validity-on-blur
|
|
29
|
+
></dx-input>
|
|
30
|
+
<dx-select
|
|
31
|
+
label="Role"
|
|
32
|
+
message-when-value-missing="Select your job role"
|
|
33
|
+
name="job_role"
|
|
34
|
+
options={roles}
|
|
35
|
+
placeholder="Your job role"
|
|
36
|
+
required
|
|
37
|
+
value=""
|
|
38
|
+
></dx-select>
|
|
39
|
+
<dx-input
|
|
40
|
+
label="Company"
|
|
41
|
+
missing-error-message="Enter your company name"
|
|
42
|
+
name="company"
|
|
43
|
+
placeholder="Company Name"
|
|
44
|
+
required
|
|
45
|
+
validity-on-blur
|
|
46
|
+
></dx-input>
|
|
47
|
+
<dx-select
|
|
48
|
+
label="Country/Region"
|
|
49
|
+
message-when-value-missing="Select your country/region"
|
|
50
|
+
name="country"
|
|
51
|
+
options={countries}
|
|
52
|
+
placeholder="Select Country/Region"
|
|
53
|
+
required
|
|
54
|
+
value=""
|
|
55
|
+
onchange={handleCountryChange}
|
|
56
|
+
></dx-select>
|
|
57
|
+
<dx-input
|
|
58
|
+
label="Postal Code"
|
|
59
|
+
missing-error-message="Enter your postal code"
|
|
60
|
+
name="postal_code"
|
|
61
|
+
placeholder="Your postal code"
|
|
62
|
+
required
|
|
63
|
+
validity-on-blur
|
|
64
|
+
></dx-input>
|
|
65
|
+
<dx-input
|
|
66
|
+
class="username-field"
|
|
67
|
+
missing-error-message="Create a user name"
|
|
68
|
+
error-message={usernameError}
|
|
69
|
+
format-error-message='Enter a unique username. Your username must be in the form of an email address, but does not have to be a real email address. We suggest "name@yourcompany." It must be unique and not associated with another Salesforce login credential.'
|
|
70
|
+
description-markup='Your username must be in the form of an email address (it does not have to be real). It must be unique and cannot be associated with another Salesforce login credential. <a href="https://help.salesforce.com/s/articleView?id=sf.basics_intro_usernames_passwords.htm&type=5" target="_blank">Read more about username recommendations.</a>'
|
|
71
|
+
label="Username"
|
|
72
|
+
name="username"
|
|
73
|
+
placeholder="jane@company.sandbox"
|
|
74
|
+
required
|
|
75
|
+
type="email"
|
|
76
|
+
validity-on-blur={checkUsernameValidity}
|
|
77
|
+
onchange={handleUsernameChange}
|
|
78
|
+
></dx-input>
|
|
79
|
+
<dx-checkbox
|
|
80
|
+
if:true={showMarketingField}
|
|
81
|
+
name="opt_in"
|
|
82
|
+
value="explicit"
|
|
83
|
+
>
|
|
84
|
+
<span lwc:dom="manual" class="marketing-terms"></span>
|
|
85
|
+
</dx-checkbox>
|
|
86
|
+
<dx-checkbox
|
|
87
|
+
if:true={showLegalCheckbox}
|
|
88
|
+
required
|
|
89
|
+
name="eula"
|
|
90
|
+
value="accepted"
|
|
91
|
+
>
|
|
92
|
+
<span lwc:dom="manual" class="legal-terms"></span>
|
|
93
|
+
<span
|
|
94
|
+
if:true={learnMore}
|
|
95
|
+
lwc:dom="manual"
|
|
96
|
+
class="learn-more"
|
|
97
|
+
></span>
|
|
98
|
+
</dx-checkbox>
|
|
99
|
+
<template if:false={showLegalCheckbox}>
|
|
100
|
+
<span lwc:dom="manual" class="legal-terms"></span>
|
|
101
|
+
<span
|
|
102
|
+
if:true={learnMore}
|
|
103
|
+
lwc:dom="manual"
|
|
104
|
+
class="learn-more"
|
|
105
|
+
></span>
|
|
106
|
+
</template>
|
|
107
|
+
<dx-button
|
|
108
|
+
class="submit-button"
|
|
109
|
+
disabled={disableSubmit}
|
|
110
|
+
size="large"
|
|
111
|
+
type="submit"
|
|
112
|
+
onclick={handleSubmit}
|
|
113
|
+
>
|
|
114
|
+
{buttonLabel}
|
|
115
|
+
</dx-button>
|
|
116
|
+
</form>
|
|
117
|
+
</template>
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { LightningElement, api, track } from "lwc";
|
|
2
|
+
import { toJson } from "dxUtils/normalizers";
|
|
3
|
+
import { track as trackGtm } from "dxUtils/analytics";
|
|
4
|
+
import {
|
|
5
|
+
submitForm,
|
|
6
|
+
ErrorCode,
|
|
7
|
+
SignupForm,
|
|
8
|
+
UserData,
|
|
9
|
+
OptIn
|
|
10
|
+
} from "./submitForm";
|
|
11
|
+
|
|
12
|
+
type SelectOption = { value: string; label: string };
|
|
13
|
+
type Country = SelectOption & {
|
|
14
|
+
showMarketingField: boolean;
|
|
15
|
+
showLegalCheckbox: boolean;
|
|
16
|
+
checkboxTextSet?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type CheckboxSet = {
|
|
20
|
+
marketingText: string;
|
|
21
|
+
legalText: string;
|
|
22
|
+
learnMore?: string;
|
|
23
|
+
};
|
|
24
|
+
type CheckboxTextMap = {
|
|
25
|
+
[key: string]: CheckboxSet;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const DEFAULT_DRIVER = "7013000000005wb";
|
|
29
|
+
const DUPLICATE_USERNAME_MESSAGE =
|
|
30
|
+
"You are already using that username in another Salesforce login credential. Your username needs to be unique and in the form of an email address.";
|
|
31
|
+
const ACCEPTED = "accepted";
|
|
32
|
+
const SIGN_UP_LABEL = "Sign me Up";
|
|
33
|
+
|
|
34
|
+
const ANALYTICS_INFO = {
|
|
35
|
+
clickText: "Sign me Up",
|
|
36
|
+
itemTitle: "Dev Edition Sign Up Button",
|
|
37
|
+
formType: "Dev Edition Sign Up",
|
|
38
|
+
formName: "DEVELOPER:xx:signup:Developer-Edition",
|
|
39
|
+
method: "email",
|
|
40
|
+
clickUrl: "/signup/success",
|
|
41
|
+
elementType: "button",
|
|
42
|
+
destinationType: "internal",
|
|
43
|
+
ctaClick: true,
|
|
44
|
+
offerType: "Free Trial"
|
|
45
|
+
};
|
|
46
|
+
export default class DeSignupForm extends LightningElement {
|
|
47
|
+
@api
|
|
48
|
+
get countries() {
|
|
49
|
+
return this._countries;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set countries(value) {
|
|
53
|
+
this._countries = toJson(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@api
|
|
57
|
+
get roles() {
|
|
58
|
+
return this._roles;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
set roles(value) {
|
|
62
|
+
this._roles = toJson(value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@api
|
|
66
|
+
get checkboxTextMap() {
|
|
67
|
+
return this._checkboxTextMap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set checkboxTextMap(value) {
|
|
71
|
+
this._checkboxTextMap = toJson(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private country: Country = null;
|
|
75
|
+
private disableSubmit = false;
|
|
76
|
+
private username = "";
|
|
77
|
+
private updateCheckboxLabels = true;
|
|
78
|
+
private _checkboxTextMap: CheckboxTextMap = null;
|
|
79
|
+
private _countries: Array<Country>;
|
|
80
|
+
private _roles: Array<SelectOption>;
|
|
81
|
+
@track knownDuplicateUsers = [];
|
|
82
|
+
|
|
83
|
+
get usernameError(): string {
|
|
84
|
+
return this.knownDuplicateUsers.includes(this.username)
|
|
85
|
+
? DUPLICATE_USERNAME_MESSAGE
|
|
86
|
+
: "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get checkUsernameValidity(): boolean {
|
|
90
|
+
return !this.knownDuplicateUsers.includes(this.username);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get showMarketingField(): boolean {
|
|
94
|
+
return this.country && this.country.showMarketingField;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get marketingText(): string {
|
|
98
|
+
return (
|
|
99
|
+
this.checkboxSetByCountry && this.checkboxSetByCountry.marketingText
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get showLegalCheckbox(): boolean {
|
|
104
|
+
return this.country && this.country.showLegalCheckbox;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get legalText(): string {
|
|
108
|
+
return this.checkboxSetByCountry && this.checkboxSetByCountry.legalText;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get learnMore(): string | undefined {
|
|
112
|
+
return this.checkboxSetByCountry && this.checkboxSetByCountry.learnMore;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get checkboxSetByCountry(): CheckboxSet {
|
|
116
|
+
return (
|
|
117
|
+
(this.country &&
|
|
118
|
+
this.country.checkboxTextSet &&
|
|
119
|
+
this.checkboxTextMap[this.country.checkboxTextSet]) ||
|
|
120
|
+
this.checkboxTextMap.default
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get buttonLabel(): string {
|
|
125
|
+
return this.disableSubmit ? "Beep boop processing" : SIGN_UP_LABEL;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
renderedCallback(): void {
|
|
129
|
+
if (!this.updateCheckboxLabels) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.updateCheckboxLabels =
|
|
134
|
+
this.updateInnerHtml("span.legal-terms", this.legalText) ||
|
|
135
|
+
this.updateInnerHtml(
|
|
136
|
+
"span.marketing-terms",
|
|
137
|
+
this.marketingText,
|
|
138
|
+
this.showMarketingField
|
|
139
|
+
) ||
|
|
140
|
+
this.updateInnerHtml(
|
|
141
|
+
"span.learn-more",
|
|
142
|
+
this.learnMore,
|
|
143
|
+
!!this.learnMore
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
handleSubmit(event: Event): void {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
this.disableSubmit ||
|
|
152
|
+
this.knownDuplicateUsers.includes(this.username)
|
|
153
|
+
) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const formData = this.prepareUserData();
|
|
158
|
+
if (!formData) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.disableSubmit = true;
|
|
163
|
+
submitForm(formData)
|
|
164
|
+
.then(() => {
|
|
165
|
+
trackGtm(event.target!, "custEv_signUp", {
|
|
166
|
+
...ANALYTICS_INFO,
|
|
167
|
+
formId: "form-builder|DEVELOPER:xx:signup|<null>"
|
|
168
|
+
});
|
|
169
|
+
window.location.href = ANALYTICS_INFO.clickUrl;
|
|
170
|
+
})
|
|
171
|
+
.catch((error) => {
|
|
172
|
+
if (error.message === ErrorCode.DUPLICATE) {
|
|
173
|
+
this.knownDuplicateUsers.push(formData.user.username);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
console.log("Oops, something went wrong", error.message);
|
|
178
|
+
})
|
|
179
|
+
.finally(() => (this.disableSubmit = false));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
handleKeyDown(e: KeyboardEvent): void {
|
|
183
|
+
if (e.key === "Enter") {
|
|
184
|
+
this.handleSubmit(e);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
handleUsernameChange(event: CustomEvent<string>): void {
|
|
189
|
+
this.username = event.detail;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
handleCountryChange(event: CustomEvent<{ value: string }>): void {
|
|
193
|
+
this.country = this.countries.find(
|
|
194
|
+
({ value }) => value === event.detail.value
|
|
195
|
+
);
|
|
196
|
+
this.updateCheckboxLabels = true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private prepareUserData(): SignupForm | null {
|
|
200
|
+
const fields = Array.from(
|
|
201
|
+
this.template.querySelectorAll<HTMLFormElement>(
|
|
202
|
+
"dx-input, dx-select"
|
|
203
|
+
)
|
|
204
|
+
).map((element) => ({
|
|
205
|
+
valid: element.reportValidity(),
|
|
206
|
+
name: element.name,
|
|
207
|
+
value: element.value
|
|
208
|
+
}));
|
|
209
|
+
|
|
210
|
+
const checkboxes = this.getCheckboxesResult();
|
|
211
|
+
|
|
212
|
+
if (fields.some((field) => !field.valid) || !checkboxes.valid) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const userData = {};
|
|
217
|
+
fields.forEach((field) => {
|
|
218
|
+
userData[field.name] = field.value;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
(userData as UserData).opt_in = this.country.showMarketingField
|
|
222
|
+
? checkboxes.values.opt_in
|
|
223
|
+
: "implied";
|
|
224
|
+
|
|
225
|
+
const formData: SignupForm = {
|
|
226
|
+
user: userData as UserData,
|
|
227
|
+
eula: this.showLegalCheckbox ? checkboxes.values.eula : ACCEPTED,
|
|
228
|
+
default_driver: DEFAULT_DRIVER
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
return formData;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private getCheckboxesResult(): {
|
|
235
|
+
valid: boolean;
|
|
236
|
+
values: { eula: string; opt_in: OptIn };
|
|
237
|
+
} {
|
|
238
|
+
let valid = true;
|
|
239
|
+
const values: { eula: string; opt_in: OptIn } = {
|
|
240
|
+
eula: "",
|
|
241
|
+
opt_in: ""
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
Array.from(
|
|
245
|
+
this.template.querySelectorAll<HTMLInputElement>("dx-checkbox")
|
|
246
|
+
).forEach((checkbox) => {
|
|
247
|
+
valid = valid && checkbox.reportValidity();
|
|
248
|
+
values[checkbox.name] = (checkbox.checked && checkbox.value) || "";
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return { valid, values };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private updateInnerHtml(
|
|
255
|
+
selector: string,
|
|
256
|
+
html: string,
|
|
257
|
+
shouldUpdate = true
|
|
258
|
+
): boolean {
|
|
259
|
+
let element: HTMLElement;
|
|
260
|
+
if (shouldUpdate) {
|
|
261
|
+
element = this.template.querySelector(selector);
|
|
262
|
+
if (element) {
|
|
263
|
+
element.innerHTML = html;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return !element && shouldUpdate;
|
|
268
|
+
}
|
|
269
|
+
}
|