Skip to content

Commit 78f94e4

Browse files
committed
Fixed Email Status
1 parent dc883c6 commit 78f94e4

2 files changed

Lines changed: 50 additions & 29 deletions

File tree

packages/web-components/src/components/notice-choice/__stories__/notice-choice.stories.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ const environment = {
9494
};
9595

9696
const onChange = (event: CustomEvent) => {
97-
console.log(event.detail);
97+
console.log(`[${event.type}] :`, event.detail);
9898
};
9999

100-
const emailChanged = (event: CustomEvent) => {
101-
console.log('onBlur', event);
100+
const onEmailStatusChanged = (events: CustomEvent) => {
101+
console.log(`[${events.type}] :`, events.detail);
102102
};
103103

104104
const props = () => {
@@ -115,7 +115,7 @@ const props = () => {
115115
'https://www.ibm.com/legal'
116116
),
117117
onChange: action('c4d-notice-choice-change'),
118-
emailChanged: action('c4d-notice-choice-emailChange'),
118+
onEmailStatusChanged: action('c4d-notice-choice-email-status-changed'),
119119
hideErrorMessages: select(
120120
'Hide Error Messages',
121121
hideErrorMessages,
@@ -158,7 +158,8 @@ export const Default = (args) => {
158158
.nc-email-detail="${ncEmailDetail}"
159159
environment="${environment}"
160160
@c4d-notice-choice-change=${onChange}
161-
@c4d-notice-choice-emailChange=${emailChanged}</c4d-notice-choice>
161+
@c4d-notice-choice-email-status-changed=${onEmailStatusChanged}>
162+
</c4d-notice-choice>
162163
`;
163164
};
164165

@@ -189,8 +190,6 @@ export default {
189190
default: {
190191
NoticeChoice: {
191192
'question-choices': [1, 2],
192-
onChange: 'c4d-notice-choice-change',
193-
onBlur: 'c4d-notice-choice-blur',
194193
},
195194
},
196195
},

packages/web-components/src/components/notice-choice/notice-choice.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)