diff --git a/packages/styles/scss/components/notice-choice/_notice-choice.scss b/packages/styles/scss/components/notice-choice/_notice-choice.scss index 5a80d29e5ae..9a2cad8820b 100644 --- a/packages/styles/scss/components/notice-choice/_notice-choice.scss +++ b/packages/styles/scss/components/notice-choice/_notice-choice.scss @@ -9,6 +9,9 @@ @use '@carbon/styles/scss/spacing' as *; @use '@carbon/styles/scss/theme' as *; @use '@carbon/styles/scss/utilities/convert'; +@use '@carbon/type'; + +@include type.reset(); @mixin notice-choice { .#{$prefix}--nc { @@ -17,6 +20,7 @@ p, .#{$prefix}--checkbox-group { margin-block-end: $spacing-06; + @include type.type-style('legal-02'); } a { diff --git a/packages/web-components/src/components/notice-choice/__stories__/README.stories.mdx b/packages/web-components/src/components/notice-choice/__stories__/README.stories.mdx index d2074f16cd0..46c3c2ff64b 100644 --- a/packages/web-components/src/components/notice-choice/__stories__/README.stories.mdx +++ b/packages/web-components/src/components/notice-choice/__stories__/README.stories.mdx @@ -39,7 +39,8 @@ import '@carbon/ibmdotcom-web-components/es/components/notice-choice/index.js'; state="CA" terms-condition-link="" hide-error-message="false" - enable-all-opt-in=""> + combine-email-phone="false" + > ``` @@ -65,6 +66,8 @@ document.addEventListener('cds-notice-choice-change', (event) => { | language | form based on the country and language | en | | terms-condition-link | Terms and conditions link appended to the end of the privacy statement - should be specific | | | hide-error-message | Hide Error Messages for PUNS statement | false | +| combine-email-phone | Combine Email and Phone | false | +| environment | Set environment variable Prod or Stage | Prod | 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 98d8541e375..c391880c2d1 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 @@ -44,7 +44,7 @@ const languages = { 'Ukrainian [uk]': 'uk', }; const countryList = { - 'Unites States': 'US', + 'United States': 'US', Germany: 'DE', India: 'IN', China: 'CN', @@ -87,6 +87,16 @@ const hideErrorMessages = { true: 'true', false: 'false', }; + +const combineEmailPhone = { + true: 'true', + false: 'false', +}; + +const environment = { + Production: 'prod', + Stage: 'stage', +}; const onChange = (event: CustomEvent) => { console.log(event.detail); }; @@ -109,11 +119,15 @@ const props = () => { hideErrorMessages, 'false' ), + combineEmailPhone: select( + 'Combine Email Phone', + combineEmailPhone, + 'false' + ), + environment: select('Environment', environment, 'prod'), }; }; -console.log(props); - export const Default = (args) => { const { language, @@ -127,6 +141,8 @@ export const Default = (args) => { hiddenPhone, ncTeleDetail, ncEmailDetail, + combineEmailPhone, + environment, } = args?.NoticeChoice ?? {}; return html` { .hiddenPhone="${hiddenPhone}" .nc-tele-detail="${ncTeleDetail}" .nc-email-detail="${ncEmailDetail}" + combine-email-phone="${combineEmailPhone}" + environment="${environment}" @c4d-notice-choice-change=${onChange}> `; }; diff --git a/packages/web-components/src/components/notice-choice/notice-choice.ts b/packages/web-components/src/components/notice-choice/notice-choice.ts index e0f1ad1b51a..95aa58e32b4 100644 --- a/packages/web-components/src/components/notice-choice/notice-choice.ts +++ b/packages/web-components/src/components/notice-choice/notice-choice.ts @@ -56,6 +56,9 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { @property({ type: String, attribute: 'language' }) language = 'en'; + @property({ type: String, attribute: 'currentLanguage' }) + currentLanguage = 'en'; + @property({ type: String, attribute: 'terms-condition-link' }) termsConditionLink = html``; @@ -68,6 +71,12 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { @property({ type: Boolean, attribute: 'hide-error-message' }) hideErrorMessage = false; + @property({ type: Boolean, attribute: 'combine-email-phone' }) + combineEmailPhone = false; + + @property({ type: String, attribute: 'environment' }) + environment = 'prod'; + @property({ type: Object, attribute: false }) checkboxes = {}; @@ -98,6 +107,9 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { @property({ type: Boolean, attribute: false }) telephonePrechecked = false; + @property({ type: Boolean, attribute: false }) + combinedEmailPhonePrechecked = false; + /** * End properties for passed attributes. */ @@ -144,6 +156,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { defaultLoadContent() { loadContent( 'en', + this.environment, (ncData) => { this.ncData = ncData; this.prepareCheckboxes(); @@ -174,6 +187,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { } else if (supportedLanguages(language)) { defaultLanguage = supportedLanguages(language); } + loadSettings( (countryPreferencesSettings) => { this.countrySettings = countryPreferencesSettings; @@ -184,6 +198,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { ); loadContent( defaultLanguage, + this.environment, (ncData) => { this.ncData = ncData; this.prepareCheckboxes(); @@ -211,7 +226,17 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { const hiddenFieldName = `NC_HIDDEN_${key}`; newValues[hiddenFieldName] = option[hiddenFieldName]; - this._onChange(hiddenFieldName, newValues[key] ? 'OPT_IN' : 'OPT_OUT'); + if (this.combineEmailPhone) { + this._onChange( + hiddenFieldName, + newValues.EMAIL ? 'OPT_IN' : 'OPT_OUT' + ); + } else { + this._onChange( + hiddenFieldName, + newValues[key] ? 'OPT_IN' : 'OPT_OUT' + ); + } }); if (JSON.stringify(this.values) !== JSON.stringify(newValues)) { this.values = newValues; @@ -250,6 +275,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { * @description * change checkbox checked option based on new country. */ + this.setDefaultSelections(); } } @@ -266,6 +292,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { attributeChangedCallback(name, oldVal, newVal) { const hasValue = newVal !== null && oldVal !== null; super.attributeChangedCallback(name, oldVal, newVal); + switch (name) { case 'question-choices': { // Reload checkbox options when questionchoices changed @@ -275,7 +302,8 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { } break; } - case 'language': { + case 'language': + case 'environment': { // load content when locale changed. const [language] = newVal.split(/[-_]/); @@ -285,10 +313,11 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { } else if (supportedLanguages(language)) { defaultLanguage = supportedLanguages(language); } - + this.currentLanguage = defaultLanguage; if (hasValue && oldVal !== newVal) { loadContent( defaultLanguage, + this.environment, (ncData) => { this.ncData = ncData; this.prepareCheckboxes(); @@ -327,6 +356,12 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { break; } + case 'combine-email-phone': { + if (oldVal !== newVal) { + this.combineEmailPhone = JSON.parse(newVal); + } + break; + } } } @@ -565,6 +600,183 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { return html``; } } + + combinedPreTextTemplate() { + if (!this.ncData) { + return html``; + } + + const ecmTranslateContent = this.ncData; + const country = this.country?.toLocaleLowerCase() || ''; + const state = this.state?.toLocaleLowerCase() || ''; + let preText = ecmTranslateContent.combinedConsent; + + if (ecmTranslateContent.state[country]) { + if (country === 'us') { + preText = + state === 'ca' || state === '' + ? ecmTranslateContent.state[country]['ca'].noticeOnly + : ecmTranslateContent.noticeOnly; + } else { + preText = + ecmTranslateContent.state[country][state]?.combinedConsent || + ecmTranslateContent.combinedConsent; + } + } else if (country === 'us') { + preText = + state === 'ca' || state === '' || typeof state === 'undefined' + ? ecmTranslateContent.state?.[country]?.['ca']?.noticeOnly + ? ecmTranslateContent.state?.[country]?.['ca']?.noticeOnly + : ecmTranslateContent.noticeOnly + : ecmTranslateContent.noticeOnly; + } + + if (ecmTranslateContent.country?.[country]) { + preText = ecmTranslateContent.country[country].combinedConsent; + } + + if (country !== 'us') { + const checked = this.values.EMAIL; + preText = preText + ? this.renderCheckbox(preText, checked) + : this.renderCheckbox(ecmTranslateContent.preText, checked); + return preText; + } + + return html`${unsafeHTML(preText)}`; + } + + checkCombineEmailPhoneBoxChange($event: any) { + const checked = $event.target.checked; + const newValues = { + ...this.values, + }; + this.changed = true; + + Object.keys(this.checkboxes).map((id) => { + newValues[id] = !!checked; + this.values = newValues; + console.log(this.combinedEmailPhonePrechecked); + const hiddenFieldName = `NC_HIDDEN_${id}`; + const hiddenFieldStatus = checked ? 'PERMISSION' : 'SUPPRESSION'; + this.values[id] = {}; + this.values[id]['checkBoxStatus'] = hiddenFieldStatus; + let statusPrechecked = ''; + switch (id) { + case 'EMAIL': + case 'PHONE': + statusPrechecked = + this.combinedEmailPhonePrechecked && !checked + ? 'CU' + : !this.combinedEmailPhonePrechecked && checked + ? 'UC' + : this.combinedEmailPhonePrechecked && checked + ? 'CC' + : 'UU'; + + break; + } + this.values[id]['punsStatus'] = statusPrechecked; + + this._onChange(hiddenFieldName, hiddenFieldStatus); + this._onChange( + `${hiddenFieldName}_VALUE`, + `NC_HIDDEN_${hiddenFieldStatus}` + ); + }); + } + renderCheckbox(preText, checked) { + const checkboxId = 'EMAIL_PHONE_CHECKBOX'; + return html` + +
+ + +
+
+ `; + } + + renderCombinedEmailPhoneSection() { + const getPunsStatus = (key, checked) => + 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.EMAIL + ? 'PERMISSION' + : 'SUPPRESSION', + }; + if (typeof checked !== 'object') { + this.combinedEmailPhonePrechecked = checked ? true : false; + } + + this._onChange( + `NC_${key === 'PHONE' ? 'TELE' : key}_DETAIL`, + `${key}_${punsStatus}` + ); + console.log(`${hiddenBox.id}_VALUE`, `NC_HIDDEN_${hiddenBox.value}`); + this._onChange( + `${hiddenBox.id}_VALUE`, + `NC_HIDDEN_${hiddenBox.value}` + ); + + if (Object.keys(this.checkboxes).length === 1) { + this._onChange(`NC_HIDDEN_PHONE_VALUE`, `NC_HIDDEN_PHONE_NONE`); + } + + return createHiddenInput(hiddenBox.id, hiddenBox.value); + })} +
+ ${this.postTextTemplate()} +
+ ${createHiddenInput( + 'preventFormSubmission', + this.preventFormSubmission + )} + +
+ `; + } + render() { if ( this.isMandatoryCheckboxDisplayed.isDisplayed && @@ -582,6 +794,11 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { ].chinaPIPLtext.mrs_field; this._onChange(mrsField, 'countyBasedCheckedNo'); } + + if (this.combineEmailPhone) { + return this.renderCombinedEmailPhoneSection(); + } + return html`

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

@@ -724,12 +941,14 @@ class NoticeChoice extends StableSelectorMixin(LitElement) { PHONE_CC: 'PHONE_CC', PHONE_UC: 'PHONE_UC', PHONE_UU: 'PHONE_UU', + EMAIL_NOTICE_ONLY: 'EMAIL_NOTICE_ONLY', + PHONE_NOTICE_ONLY: 'PHONE_NOTICE_ONLY', + NC_HIDDEN_PHONE_NONE: 'NC_HIDDEN_PHONE_NONE', }; if (Object.prototype.hasOwnProperty.call(pwsFieldsMap, field)) { field = pwsFieldsMap[field]; } - const init = { bubbles: true, detail: { diff --git a/packages/web-components/src/components/notice-choice/services.ts b/packages/web-components/src/components/notice-choice/services.ts index 96a3a957b8a..c2514492983 100644 --- a/packages/web-components/src/components/notice-choice/services.ts +++ b/packages/web-components/src/components/notice-choice/services.ts @@ -5,11 +5,17 @@ * LICENSE file in the root directory of this source tree. */ -export function loadContent(locale: string, onSuccess: any, onError: any) { +export function loadContent( + locale: string, + env: string, + onSuccess: any, + onError: any +) { const script = document.createElement('script'); + const environment = env === 'prod' ? '1.www.s81c.com' : '1.wwwstage.s81c.com'; script.async = false; script.charset = 'utf-8'; - script.src = `https://www.ibm.com/common/translations/notice/v23/${locale.toLocaleLowerCase()}/ncContent_v23.js`; // URL for the third-party library being loaded. + script.src = `https://${environment}/common/translations/notice/v23/${locale.toLocaleLowerCase()}/ncContent_v23.js`; // URL for the third-party library being loaded. document.body.appendChild(script); script.onload = () => { try { diff --git a/packages/web-components/src/components/notice-choice/utils.ts b/packages/web-components/src/components/notice-choice/utils.ts index b29e554ee8c..ad7e65ac585 100644 --- a/packages/web-components/src/components/notice-choice/utils.ts +++ b/packages/web-components/src/components/notice-choice/utils.ts @@ -49,6 +49,9 @@ export function pwsValueMap(value) { PHONE_CC: 'CC', PHONE_UC: 'UC', PHONE_UU: 'UU', + EMAIL_NOTICE_ONLY: 'NOTICE_ONLY', + PHONE_NOTICE_ONLY: 'NOTICE_ONLY', + NC_HIDDEN_PHONE_NONE: 'N', }[value] || null ); }