From 241ac04fbddfb99a8c0f766792f3440333c1cd18 Mon Sep 17 00:00:00 2001 From: Rajaneesh Date: Wed, 27 Nov 2024 17:08:25 +0530 Subject: [PATCH] Fixe prettier issue --- .../__stories__/notice-choice.stories.ts | 4 +- .../components/notice-choice/notice-choice.ts | 272 +++++++++--------- .../src/components/notice-choice/services.ts | 2 - .../src/components/notice-choice/utils.ts | 4 +- 4 files changed, 144 insertions(+), 138 deletions(-) diff --git a/packages/web-components/src/components/notice-choice/__stories__/notice-choice.stories.ts b/packages/web-components/src/components/notice-choice/__stories__/notice-choice.stories.ts index 22296dd0846..2f756cace19 100644 --- a/packages/web-components/src/components/notice-choice/__stories__/notice-choice.stories.ts +++ b/packages/web-components/src/components/notice-choice/__stories__/notice-choice.stories.ts @@ -118,8 +118,6 @@ const props = () => { }; }; - - export const Default = (args) => { const { language, @@ -133,7 +131,7 @@ export const Default = (args) => { hiddenPhone, ncTeleDetail, ncEmailDetail, - combineEmailPhone + combineEmailPhone, } = args?.NoticeChoice ?? {}; return html` ${!this.hideErrorMessage && this.preventFormSubmission - ? html`${mandatoryCheckbox.error}` - : ''} + : ''}

@@ -487,7 +483,6 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { } checkBoxTemplate(checkbox, checked, hiddenBox) { - this._onChange(`${hiddenBox.id}_VALUE`, `NC_HIDDEN_${hiddenBox.value}`); return html`
{ - newValues[id] = !!checked; this.values = newValues; @@ -643,10 +638,10 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { this.emailPrechecked && !checked ? 'CU' : !this.emailPrechecked && checked - ? 'UC' - : this.emailPrechecked && checked - ? 'CC' - : 'UU'; + ? 'UC' + : this.emailPrechecked && checked + ? 'CC' + : 'UU'; break; case 'PHONE': @@ -654,48 +649,45 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { this.telephonePrechecked && checked ? 'CC' : this.telephonePrechecked && !checked - ? 'CU' - : !this.telephonePrechecked && checked - ? 'UC' - : 'UU'; + ? 'CU' + : !this.telephonePrechecked && checked + ? 'UC' + : 'UU'; break; } this.values[id]['punsStatus'] = statusPrechecked; this._onChange(hiddenFieldName, hiddenFieldStatus); - this._onChange(`${hiddenFieldName}_VALUE`, `NC_HIDDEN_${hiddenFieldStatus}`); - console.log("Test ME") - }) - - + this._onChange( + `${hiddenFieldName}_VALUE`, + `NC_HIDDEN_${hiddenFieldStatus}` + ); + console.log('Test ME'); + }); } renderCheckbox(preText, checked) { - const checkboxId = "EMAIL_PHONE_CHECKBOX"; + const checkboxId = 'EMAIL_PHONE_CHECKBOX'; return html`
+ part="checkbox-wrapper"> + ?checked="${checked}" + @change="${this.checkCombineEmailPhoneBoxChange}" /> @@ -706,114 +698,133 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { renderCombinedEmailPhoneSection() { const getPunsStatus = (key, checked) => - this.country?.toLocaleLowerCase() === 'us' ? 'NOTICE_ONLY' : (this.values[key]?.punsStatus || (checked ? 'CC' : 'UU')); + this.country?.toLocaleLowerCase() === 'us' + ? 'NOTICE_ONLY' + : this.values[key]?.punsStatus || (checked ? 'CC' : 'UU'); const createHiddenInput = (id, value) => html``; return html` -
-

- ${this.countryBasedLegalNotice()} ${this.combinedPreTextTemplate()} -

- ${Object.keys(this.checkboxes).map((key) => { - const checked = this.values.EMAIL; - const punsStatus = getPunsStatus(key, checked); - const hiddenBox = { - id: `NC_HIDDEN_${key}`, - value: this.values[key]['checkBoxStatus'] - ? this.values[key]['checkBoxStatus'] - : this.values[key] - ? 'PERMISSION' - : 'SUPPRESSION', - }; - - this._onChange(`NC_${key === 'PHONE' ? 'TELE' : key}_DETAIL`, `${key}_${punsStatus}`); - this._onChange(`${hiddenBox.id}_VALUE`, `NC_HIDDEN_${hiddenBox.value}`); - - return createHiddenInput(hiddenBox.id, hiddenBox.value); - })} -
- ${this.postTextTemplate()} -
- ${createHiddenInput('preventFormSubmission', this.preventFormSubmission)} - -
- `; - } +
+

+ ${this.countryBasedLegalNotice()} ${this.combinedPreTextTemplate()} +

+ ${Object.keys(this.checkboxes).map((key) => { + const checked = this.values.EMAIL; + const punsStatus = getPunsStatus(key, checked); + const hiddenBox = { + id: `NC_HIDDEN_${key}`, + value: this.values[key]['checkBoxStatus'] + ? this.values[key]['checkBoxStatus'] + : this.values[key] + ? 'PERMISSION' + : 'SUPPRESSION', + }; + this._onChange( + `NC_${key === 'PHONE' ? 'TELE' : key}_DETAIL`, + `${key}_${punsStatus}` + ); + this._onChange( + `${hiddenBox.id}_VALUE`, + `NC_HIDDEN_${hiddenBox.value}` + ); + return createHiddenInput(hiddenBox.id, hiddenBox.value); + })} +
+ ${this.postTextTemplate()} +
+ ${createHiddenInput( + 'preventFormSubmission', + this.preventFormSubmission + )} + +
+ `; + } render() { if ( this.isMandatoryCheckboxDisplayed.isDisplayed && this.country.toLocaleLowerCase() !== - this.isMandatoryCheckboxDisplayed.countryCode + this.isMandatoryCheckboxDisplayed.countryCode ) { const mrsField = this.ncData?.mandatoryCheckbox[ this.isMandatoryCheckboxDisplayed.countryCode ].countryTransferText ? this.ncData?.mandatoryCheckbox[ - this.isMandatoryCheckboxDisplayed.countryCode - ].countryTransferText.mrs_field + this.isMandatoryCheckboxDisplayed.countryCode + ].countryTransferText.mrs_field : this.ncData?.mandatoryCheckbox[ - this.isMandatoryCheckboxDisplayed.countryCode - ].chinaPIPLtext.mrs_field; + this.isMandatoryCheckboxDisplayed.countryCode + ].chinaPIPLtext.mrs_field; this._onChange(mrsField, 'countyBasedCheckedNo'); } if (this.combineEmailPhone) { - return this.renderCombinedEmailPhoneSection() + return this.renderCombinedEmailPhoneSection(); } return html`

${this.countryBasedLegalNotice()} ${this.preTextTemplate()}

- ${Object.keys(this.checkboxes).length !== 0 - ? Object.keys(this.checkboxes).length > 0 && - Object.keys(this.checkboxes).map((key) => { - const checked = this.values[key]; - const checkbox = this.checkboxes[key]; - const punsStatus = this.values[key]['punsStatus'] ? this.values[key]['punsStatus'] : checked ? 'CC' : 'UU'; - const hiddenBox = { - id: 'NC_HIDDEN_' + key, - value: this.values[key]['checkBoxStatus'] - ? this.values[key]['checkBoxStatus'] - : this.values[key] - ? 'PERMISSION' - : 'SUPPRESSION', - }; - switch (key) { - case 'EMAIL': - this.hiddenEmail = hiddenBox.value; - this.ncEmailDetail = punsStatus; - if (typeof checked !== 'object') { - this.emailPrechecked = checked ? true : false; - } - break; - case 'PHONE': - this.hiddenPhone = hiddenBox.value; - this.ncTeleDetail = punsStatus; - if (typeof checked !== 'object') { - this.telephonePrechecked = checked ? true : false; - } - break; - } - const punsValue = key === 'PHONE' ? 'TELE' : key; - this._onChange( - `NC_${punsValue}_DETAIL`, - `${key}_${punsStatus}` - ); - return this.checkBoxTemplate(checkbox, checked, hiddenBox); - }) - : '' - } + ${ + Object.keys(this.checkboxes).length !== 0 + ? Object.keys(this.checkboxes).length > 0 && + Object.keys(this.checkboxes).map((key) => { + const checked = this.values[key]; + const checkbox = this.checkboxes[key]; + const punsStatus = this.values[key]['punsStatus'] + ? this.values[key]['punsStatus'] + : checked + ? 'CC' + : 'UU'; + const hiddenBox = { + id: 'NC_HIDDEN_' + key, + value: this.values[key]['checkBoxStatus'] + ? this.values[key]['checkBoxStatus'] + : this.values[key] + ? 'PERMISSION' + : 'SUPPRESSION', + }; + switch (key) { + case 'EMAIL': + this.hiddenEmail = hiddenBox.value; + this.ncEmailDetail = punsStatus; + if (typeof checked !== 'object') { + this.emailPrechecked = checked ? true : false; + } + break; + case 'PHONE': + this.hiddenPhone = hiddenBox.value; + this.ncTeleDetail = punsStatus; + if (typeof checked !== 'object') { + this.telephonePrechecked = checked ? true : false; + } + break; + } + const punsValue = key === 'PHONE' ? 'TELE' : key; + this._onChange( + `NC_${punsValue}_DETAIL`, + `${key}_${punsStatus}` + ); + return this.checkBoxTemplate(checkbox, checked, hiddenBox); + }) + : '' + }
${this.postTextTemplate()}
- +
`; } @@ -903,8 +914,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { PHONE_UC: 'PHONE_UC', PHONE_UU: 'PHONE_UU', EMAIL_NOTICE_ONLY: 'EMAIL_NOTICE_ONLY', - PHONE_NOTICE_ONLY: 'PHONE_NOTICE_ONLY' - + PHONE_NOTICE_ONLY: 'PHONE_NOTICE_ONLY', }; if (Object.prototype.hasOwnProperty.call(pwsFieldsMap, field)) { diff --git a/packages/web-components/src/components/notice-choice/services.ts b/packages/web-components/src/components/notice-choice/services.ts index c5b30ee9a9b..a3a5dbea204 100644 --- a/packages/web-components/src/components/notice-choice/services.ts +++ b/packages/web-components/src/components/notice-choice/services.ts @@ -6,7 +6,6 @@ */ export function loadContent(locale: string, onSuccess: any, onError: any) { - const script = document.createElement('script'); script.async = false; script.charset = 'utf-8'; @@ -15,7 +14,6 @@ export function loadContent(locale: string, onSuccess: any, onError: any) { script.onload = () => { try { if (onSuccess) { - onSuccess(window.NoticeChoice.Content); } } catch (e) { diff --git a/packages/web-components/src/components/notice-choice/utils.ts b/packages/web-components/src/components/notice-choice/utils.ts index 581966d4b9e..c69520ee687 100644 --- a/packages/web-components/src/components/notice-choice/utils.ts +++ b/packages/web-components/src/components/notice-choice/utils.ts @@ -49,8 +49,8 @@ export function pwsValueMap(value) { PHONE_CC: 'CC', PHONE_UC: 'UC', PHONE_UU: 'UU', - EMAIL_NOTICE_ONLY:'NOTICE_ONLY', - PHONE_NOTICE_ONLY:'NOTICE_ONLY' + EMAIL_NOTICE_ONLY: 'NOTICE_ONLY', + PHONE_NOTICE_ONLY: 'NOTICE_ONLY', }[value] || null ); }