@@ -34,6 +34,7 @@ interface MandatoryCheckbox {
3434 *
3535 * @element c4d-notice-choice
3636 * @fires c4d-notice-choice-change
37+ * @fires c4d-notice-choice-email-status-changed
3738 * The custom event fired when default choice loaded or user change some preferences.
3839 * The field and value should be taken from the detail object and send it to MRS.
3940 * @csspart checkbox-wrapper - The checkbox wrapper. Usage `c4d-notice-choice::part(checkbox-wrapper)`
@@ -193,9 +194,18 @@ class NoticeChoice extends StableSelectorMixin(LitElement) {
193194
194195 case 'language' :
195196 case 'environment' : {
196- const langPart = ( value as string | undefined ) ?. split ( / [ - _ ] / ) [ 0 ] ;
197+ if ( [ 'stage' , 'prod' ] . includes ( value as string ) ) {
198+ this . environment = value as string ;
199+ } else {
200+ this . language = value as string ;
201+ }
202+ const langPart = ( this . language as string | undefined ) ?. split (
203+ / [ - _ ] /
204+ ) [ 0 ] ;
197205 const supportedLang =
198- supportedLanguages ( value ) || supportedLanguages ( langPart ) || 'en' ;
206+ supportedLanguages ( this . language ) ||
207+ supportedLanguages ( langPart ) ||
208+ 'en' ;
199209
200210 this . isLoading = true ;
201211 loadSettings (
@@ -297,7 +307,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) {
297307 this . isAnnualPeriodExpired = emailStatus !== 'P' || isExpired ;
298308 this . showCheckBox = isExpired || emailStatus !== 'P' ;
299309
300- this . _emailChanged ( 'emailStats' , {
310+ this . _onEmailStatusChanged ( 'emailStats' , {
301311 ...data ,
302312 isAnnualPeriodExpired : isExpired ,
303313 } ) ;
@@ -318,7 +328,7 @@ class NoticeChoice extends StableSelectorMixin(LitElement) {
318328 this . isAnnualPeriodExpired = expired ;
319329 this . showCheckBox = true ;
320330 this . renderCombinedEmailPhoneSection ( ) ;
321- this . _emailChanged ( 'emailStats' , {
331+ this . _onEmailStatusChanged ( 'emailStats' , {
322332 ...responseData ,
323333 isAnnualPeriodExpired : expired ,
324334 } ) ;
@@ -853,30 +863,42 @@ class NoticeChoice extends StableSelectorMixin(LitElement) {
853863 /**
854864 * Dispatch field change event to parent form
855865 */
856- _onChange ( field : string , value : string | null ) : void {
857- const mappedField = this . pwsFieldsMap . get ( field ) ?? field ;
858-
859- this . dispatchEvent (
860- new CustomEvent ( `${ c4dPrefix } -notice-choice-change` , {
866+ private dispatchCustomEvent (
867+ eventName : string ,
868+ field : string ,
869+ value : string | null
870+ ) : void {
871+ try {
872+ const eventDetail = {
861873 bubbles : true ,
862874 detail : {
863- field : mappedField ,
864- value : pwsValueMap ( value ) ,
875+ field,
876+ value,
865877 } ,
866- } )
878+ } ;
879+
880+ this . dispatchEvent ( new CustomEvent ( eventName , eventDetail ) ) ;
881+ } catch ( error ) {
882+ console . error ( `[${ eventName } ] dispatch failed:` , error ) ;
883+ }
884+ }
885+
886+ _onChange ( field : string , value : string | null ) : void {
887+ const mappedField = this . pwsFieldsMap ?. get ( field ) ?? field ;
888+ const mappedValue = pwsValueMap ?.( value ) ?? value ;
889+
890+ this . dispatchCustomEvent (
891+ `${ c4dPrefix } -notice-choice-change` ,
892+ mappedField ,
893+ mappedValue
867894 ) ;
868895 }
869896
870- _emailChanged ( field : string , value : string | null ) {
871- const init = {
872- bubbles : true ,
873- detail : {
874- field,
875- value : value ,
876- } ,
877- } ;
878- this . dispatchEvent (
879- new CustomEvent ( `${ c4dPrefix } -notice-choice-blur` , init )
897+ _onEmailStatusChanged ( field : string , value : string | null ) : void {
898+ this . dispatchCustomEvent (
899+ `${ c4dPrefix } -notice-choice-email-status-changed` ,
900+ field ,
901+ value
880902 ) ;
881903 }
882904
0 commit comments