From 0264edcb5fcbf9e19380cd27e9ba5c17a8fe6866 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Tue, 15 Aug 2023 05:03:58 +0530 Subject: [PATCH 01/13] Add files via upload --- .../miawCustomPrechat/customPrechatForm.css | 13 ++++ .../miawCustomPrechat/customPrechatForm.html | 12 ++++ .../miawCustomPrechat/customPrechatForm.js | 61 +++++++++++++++++++ .../customPrechatForm.js-meta.xml | 8 +++ .../customPrechatFormField.html | 18 ++++++ .../customPrechatFormField.js | 60 ++++++++++++++++++ .../customPrechatFormField.js-meta.xml | 7 +++ 7 files changed, 179 insertions(+) create mode 100644 npachpande/async/miawCustomPrechat/customPrechatForm.css create mode 100644 npachpande/async/miawCustomPrechat/customPrechatForm.html create mode 100644 npachpande/async/miawCustomPrechat/customPrechatForm.js create mode 100644 npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml create mode 100644 npachpande/async/miawCustomPrechat/customPrechatFormField.html create mode 100644 npachpande/async/miawCustomPrechat/customPrechatFormField.js create mode 100644 npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.css b/npachpande/async/miawCustomPrechat/customPrechatForm.css new file mode 100644 index 0000000000..36ffef43b9 --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.css @@ -0,0 +1,13 @@ +:host { + display: flex; + flex-direction: column; + flex: 1 1 auto; + overflow: hidden; + background: #FFFFFF; + padding: 2em; +} + +lightning-button { + padding-top: 2em; + text-align: center; +} \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.html b/npachpande/async/miawCustomPrechat/customPrechatForm.html new file mode 100644 index 0000000000..d60e43a392 --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.html @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js b/npachpande/async/miawCustomPrechat/customPrechatForm.js new file mode 100644 index 0000000000..866df4644f --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.js @@ -0,0 +1,61 @@ +import { track, api, LightningElement } from "lwc"; + +export default class CustomPrechatForm extends LightningElement { + @api configuration = {}; + + startConversationLabel; + + get prechatForm() { + const forms = this.configuration.forms || []; + return forms.find(form => form.formType === "PreChat") || {}; + } + + get prechatFormFields() { + return this.prechatForm.formFields || []; + } + + get fields() { + let fields = JSON.parse(JSON.stringify(this.prechatFormFields)); + this.addChoiceListValues(fields); + return fields.sort((fieldA, fieldB) => fieldA.order - fieldB.order); + } + + connectedCallback() { + this.startConversationLabel = "Start Conversation"; + } + + addChoiceListValues(fields) { + for (let field of fields) { + if (field.type === "ChoiceList") { + const valueList = this.configuration.choiceListConfig.choiceList.find(list => list.choiceListId === field.choiceListId) || {}; + field.choiceListValues = valueList.choiceListValues || []; + } + } + } + + isValid() { + let isFormValid = true; + this.template.querySelectorAll("c-custom-prechat-form-field").forEach(formField => { + if (!formField.reportValidity()) { + isFormValid = false; + } + }); + return isFormValid; + } + + handleStartConversation() { + const prechatData = {}; + if (this.isValid()) { + this.template.querySelectorAll("c-custom-prechat-form-field").forEach(formField => { + prechatData[formField.name] = String(formField.value); + }); + + this.dispatchEvent(new CustomEvent( + "prechatsubmit", + { + detail: { value: prechatData } + } + )); + } + } +} \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml b/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml new file mode 100644 index 0000000000..f194978956 --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml @@ -0,0 +1,8 @@ + + + 55.0 + true + + lightningSnapin__MessagingPreChat + + \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.html b/npachpande/async/miawCustomPrechat/customPrechatFormField.html new file mode 100644 index 0000000000..c9d6828916 --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatFormField.html @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js b/npachpande/async/miawCustomPrechat/customPrechatFormField.js new file mode 100644 index 0000000000..68038a4222 --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatFormField.js @@ -0,0 +1,60 @@ +import { track, api, LightningElement } from "lwc"; + +export default class CustomPrechatFormField extends LightningElement { + choiceListDefaultValue; + + @api fieldInfo = {}; + + @api + get name() { + return this.fieldInfo.name; + } + + @api + get value() { + const lightningCmp = this.isTypeChoiceList ? this.template.querySelector("lightning-combobox") : this.template.querySelector("lightning-input"); + return this.isTypeCheckbox ? lightningCmp.checked : lightningCmp.value; + } + + @api + reportValidity() { + const lightningCmp = this.isTypeChoiceList ? this.template.querySelector("lightning-combobox") : this.template.querySelector("lightning-input"); + return lightningCmp.reportValidity(); + } + + get type() { + switch (this.fieldInfo.type) { + case "Phone": + return "tel"; + case "Text": + case "Email": + case "Number": + case "Checkbox": + case "ChoiceList": + return this.fieldInfo.type.toLowerCase(); + default: + return "text"; + } + } + + get isTypeCheckbox() { + return this.type === "Checkbox".toLowerCase(); + } + + get isTypeChoiceList() { + return this.type === "ChoiceList".toLowerCase(); + } + + get choiceListOptions() { + let choiceListOptions = []; + const choiceListValues = [...this.fieldInfo.choiceListValues]; + choiceListValues.sort((valueA, valueB) => valueA.order - valueB.order); + for (const listValue of choiceListValues) { + if (listValue.isDefaultValue) { + this.choiceListDefaultValue = listValue.choiceListValueName; + } + choiceListOptions.push({ label: listValue.label, value: listValue.choiceListValueName }); + } + return choiceListOptions; + } +} \ No newline at end of file diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml b/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml new file mode 100644 index 0000000000..7afe7a234e --- /dev/null +++ b/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml @@ -0,0 +1,7 @@ + + + 55.0 + true + + + \ No newline at end of file From afd603b920d4a4d618fef8e60ac1001fea442481 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Thu, 28 Sep 2023 10:00:09 -0700 Subject: [PATCH 02/13] Update customPrechatForm.js --- .../miawCustomPrechat/customPrechatForm.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js b/npachpande/async/miawCustomPrechat/customPrechatForm.js index 866df4644f..38d20db921 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.js +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.js @@ -1,6 +1,10 @@ import { track, api, LightningElement } from "lwc"; export default class CustomPrechatForm extends LightningElement { + /** + * Deployment configuration data. + * @type {Object} + */ @api configuration = {}; startConversationLabel; @@ -14,6 +18,10 @@ export default class CustomPrechatForm extends LightningElement { return this.prechatForm.formFields || []; } + /** + * Returns prechat form fields in a sorted display order. + * @type {Object[]} + */ get fields() { let fields = JSON.parse(JSON.stringify(this.prechatFormFields)); this.addChoiceListValues(fields); @@ -24,6 +32,9 @@ export default class CustomPrechatForm extends LightningElement { this.startConversationLabel = "Start Conversation"; } + /** + * Adds choicelist values to fields of type choiceList (dropdown). + */ addChoiceListValues(fields) { for (let field of fields) { if (field.type === "ChoiceList") { @@ -33,6 +44,10 @@ export default class CustomPrechatForm extends LightningElement { } } + /** + * Iterates over and reports validity for each form field. Returns true if all the fields are valid. + * @type {boolean} + */ isValid() { let isFormValid = true; this.template.querySelectorAll("c-custom-prechat-form-field").forEach(formField => { @@ -43,6 +58,10 @@ export default class CustomPrechatForm extends LightningElement { return isFormValid; } + /** + * Gathers and submits prechat data to the app on start converation button click. + * @type {boolean} + */ handleStartConversation() { const prechatData = {}; if (this.isValid()) { @@ -58,4 +77,4 @@ export default class CustomPrechatForm extends LightningElement { )); } } -} \ No newline at end of file +} From dd9ccb83843c6e0475d175c5f7a7bb951f3035b2 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Thu, 28 Sep 2023 14:08:41 -0700 Subject: [PATCH 03/13] Update customPrechatForm.js --- npachpande/async/miawCustomPrechat/customPrechatForm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js b/npachpande/async/miawCustomPrechat/customPrechatForm.js index 38d20db921..10e5b73e7e 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.js +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.js @@ -19,7 +19,7 @@ export default class CustomPrechatForm extends LightningElement { } /** - * Returns prechat form fields in a sorted display order. + * Returns prechat form fields sorted by their display order. * @type {Object[]} */ get fields() { @@ -33,7 +33,7 @@ export default class CustomPrechatForm extends LightningElement { } /** - * Adds choicelist values to fields of type choiceList (dropdown). + * Adds values to fields of type choiceList (dropdown). */ addChoiceListValues(fields) { for (let field of fields) { From 7c83a710ee7c86f7b35826486864361225ead410 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Thu, 28 Sep 2023 14:12:23 -0700 Subject: [PATCH 04/13] Update customPrechatForm.js-meta.xml --- .../async/miawCustomPrechat/customPrechatForm.js-meta.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml b/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml index f194978956..c179b82f4b 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml +++ b/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml @@ -1,8 +1,8 @@ - 55.0 + 59.0 true lightningSnapin__MessagingPreChat - \ No newline at end of file + From 8e687455e90f18da754ecd914f7528b03e62fcbb Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Thu, 28 Sep 2023 14:16:39 -0700 Subject: [PATCH 05/13] Update customPrechatFormField.js --- .../async/miawCustomPrechat/customPrechatFormField.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js b/npachpande/async/miawCustomPrechat/customPrechatFormField.js index 68038a4222..74eccd9e69 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatFormField.js +++ b/npachpande/async/miawCustomPrechat/customPrechatFormField.js @@ -3,6 +3,10 @@ import { track, api, LightningElement } from "lwc"; export default class CustomPrechatFormField extends LightningElement { choiceListDefaultValue; + /** + * Form field data. + * @type {Object} + */ @api fieldInfo = {}; @api @@ -45,6 +49,10 @@ export default class CustomPrechatFormField extends LightningElement { return this.type === "ChoiceList".toLowerCase(); } + /** + * Formats choiceList options and sets the default value. + * @type {Array} + */ get choiceListOptions() { let choiceListOptions = []; const choiceListValues = [...this.fieldInfo.choiceListValues]; @@ -57,4 +65,4 @@ export default class CustomPrechatFormField extends LightningElement { } return choiceListOptions; } -} \ No newline at end of file +} From f47e6ae2c7c976604d8ccbbde4143bbc6623cc26 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Thu, 28 Sep 2023 14:17:04 -0700 Subject: [PATCH 06/13] Update customPrechatFormField.js-meta.xml --- .../miawCustomPrechat/customPrechatFormField.js-meta.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml b/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml index 7afe7a234e..ae48dcb034 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml +++ b/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml @@ -1,7 +1,7 @@ - 55.0 + 59.0 true - \ No newline at end of file + From 3f4f188e5eda1773a57de0d2a8891096b5fc1aee Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:37:53 -0700 Subject: [PATCH 07/13] Rename customPrechatForm.css to customPreChatForm.css --- .../{customPrechatForm.css => customPreChatForm.css} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename npachpande/async/miawCustomPrechat/{customPrechatForm.css => customPreChatForm.css} (99%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.css b/npachpande/async/miawCustomPrechat/customPreChatForm.css similarity index 99% rename from npachpande/async/miawCustomPrechat/customPrechatForm.css rename to npachpande/async/miawCustomPrechat/customPreChatForm.css index 36ffef43b9..fe8e7a1697 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.css +++ b/npachpande/async/miawCustomPrechat/customPreChatForm.css @@ -10,4 +10,4 @@ lightning-button { padding-top: 2em; text-align: center; -} \ No newline at end of file +} From 535e2353157f92fae7290e1c85bd2e624e7b064f Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:38:47 -0700 Subject: [PATCH 08/13] Update and rename customPrechatForm.html to customPreChatForm.html --- .../{customPrechatForm.html => customPreChatForm.html} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename npachpande/async/miawCustomPrechat/{customPrechatForm.html => customPreChatForm.html} (67%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.html b/npachpande/async/miawCustomPrechat/customPreChatForm.html similarity index 67% rename from npachpande/async/miawCustomPrechat/customPrechatForm.html rename to npachpande/async/miawCustomPrechat/customPreChatForm.html index d60e43a392..5d1f8ef35c 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.html +++ b/npachpande/async/miawCustomPrechat/customPreChatForm.html @@ -1,12 +1,12 @@ \ No newline at end of file + From dd3752cee75a753a362a86ee65ce8cc6e319789c Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:39:31 -0700 Subject: [PATCH 09/13] Update and rename customPrechatForm.js to customPreChatForm.js --- .../{customPrechatForm.js => customPreChatForm.js} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename npachpande/async/miawCustomPrechat/{customPrechatForm.js => customPreChatForm.js} (87%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js b/npachpande/async/miawCustomPrechat/customPreChatForm.js similarity index 87% rename from npachpande/async/miawCustomPrechat/customPrechatForm.js rename to npachpande/async/miawCustomPrechat/customPreChatForm.js index 10e5b73e7e..83c6116d1d 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatForm.js +++ b/npachpande/async/miawCustomPrechat/customPreChatForm.js @@ -1,6 +1,6 @@ import { track, api, LightningElement } from "lwc"; -export default class CustomPrechatForm extends LightningElement { +export default class CustomPreChatForm extends LightningElement { /** * Deployment configuration data. * @type {Object} @@ -50,7 +50,7 @@ export default class CustomPrechatForm extends LightningElement { */ isValid() { let isFormValid = true; - this.template.querySelectorAll("c-custom-prechat-form-field").forEach(formField => { + this.template.querySelectorAll("c-custom-pre-chat-form-field").forEach(formField => { if (!formField.reportValidity()) { isFormValid = false; } @@ -62,10 +62,10 @@ export default class CustomPrechatForm extends LightningElement { * Gathers and submits prechat data to the app on start converation button click. * @type {boolean} */ - handleStartConversation() { + onStartConversationClick() { const prechatData = {}; if (this.isValid()) { - this.template.querySelectorAll("c-custom-prechat-form-field").forEach(formField => { + this.template.querySelectorAll("c-custom-pre-chat-form-field").forEach(formField => { prechatData[formField.name] = String(formField.value); }); From 5118b6557563bc5002cd4db99010bee968013a6d Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:39:50 -0700 Subject: [PATCH 10/13] Rename customPrechatForm.js-meta.xml to customPreChatForm.js-meta.xml --- ...ustomPrechatForm.js-meta.xml => customPreChatForm.js-meta.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename npachpande/async/miawCustomPrechat/{customPrechatForm.js-meta.xml => customPreChatForm.js-meta.xml} (100%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml b/npachpande/async/miawCustomPrechat/customPreChatForm.js-meta.xml similarity index 100% rename from npachpande/async/miawCustomPrechat/customPrechatForm.js-meta.xml rename to npachpande/async/miawCustomPrechat/customPreChatForm.js-meta.xml From b09323f332caa301628e9e6534f9c82fa2ab65af Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:40:11 -0700 Subject: [PATCH 11/13] Rename customPrechatFormField.html to customPreChatFormField.html --- ...{customPrechatFormField.html => customPreChatFormField.html} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename npachpande/async/miawCustomPrechat/{customPrechatFormField.html => customPreChatFormField.html} (98%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.html b/npachpande/async/miawCustomPrechat/customPreChatFormField.html similarity index 98% rename from npachpande/async/miawCustomPrechat/customPrechatFormField.html rename to npachpande/async/miawCustomPrechat/customPreChatFormField.html index c9d6828916..c6e92858e6 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatFormField.html +++ b/npachpande/async/miawCustomPrechat/customPreChatFormField.html @@ -15,4 +15,4 @@ required={fieldInfo.required}> - \ No newline at end of file + From fbffe0ed83a5ed2b8b3d911927adac098ab57830 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:40:31 -0700 Subject: [PATCH 12/13] Update and rename customPrechatFormField.js to customPreChatFormField.js --- .../{customPrechatFormField.js => customPreChatFormField.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename npachpande/async/miawCustomPrechat/{customPrechatFormField.js => customPreChatFormField.js} (96%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js b/npachpande/async/miawCustomPrechat/customPreChatFormField.js similarity index 96% rename from npachpande/async/miawCustomPrechat/customPrechatFormField.js rename to npachpande/async/miawCustomPrechat/customPreChatFormField.js index 74eccd9e69..7ba92c0b42 100644 --- a/npachpande/async/miawCustomPrechat/customPrechatFormField.js +++ b/npachpande/async/miawCustomPrechat/customPreChatFormField.js @@ -1,6 +1,6 @@ import { track, api, LightningElement } from "lwc"; -export default class CustomPrechatFormField extends LightningElement { +export default class CustomPreChatFormField extends LightningElement { choiceListDefaultValue; /** From ad1befdb4e1d538b33f69cf9783f00c7e35f5055 Mon Sep 17 00:00:00 2001 From: ESW1234 Date: Fri, 6 Oct 2023 15:40:50 -0700 Subject: [PATCH 13/13] Rename customPrechatFormField.js-meta.xml to customPreChatFormField.js-meta.xml --- ...atFormField.js-meta.xml => customPreChatFormField.js-meta.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename npachpande/async/miawCustomPrechat/{customPrechatFormField.js-meta.xml => customPreChatFormField.js-meta.xml} (100%) diff --git a/npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml b/npachpande/async/miawCustomPrechat/customPreChatFormField.js-meta.xml similarity index 100% rename from npachpande/async/miawCustomPrechat/customPrechatFormField.js-meta.xml rename to npachpande/async/miawCustomPrechat/customPreChatFormField.js-meta.xml