2022-04-14 17:40:04 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-11-18 14:55:21 +03:00
|
|
|
import moment from 'moment-timezone';
|
2022-10-07 19:03:45 +03:00
|
|
|
import {action} from '@ember/object';
|
2022-04-14 17:40:04 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
export default class MembersNewsletterPreference extends Component {
|
|
|
|
@tracked filterValue;
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
get newsletters() {
|
|
|
|
if (this.args.newsletters?.length > 0) {
|
|
|
|
return this.args.newsletters.map((d) => {
|
|
|
|
return {
|
|
|
|
name: d.name,
|
|
|
|
description: d.description,
|
2022-10-07 19:03:45 +03:00
|
|
|
subscribed: !!this.args.member?.newsletters?.find((n) => {
|
2022-04-14 17:40:04 +03:00
|
|
|
return n.id === d.id;
|
|
|
|
}),
|
|
|
|
id: d.id,
|
|
|
|
forId: `${d.id}-checkbox`
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-11-18 14:55:21 +03:00
|
|
|
get suppressionData() {
|
|
|
|
const {emailSuppression} = this.args.member;
|
|
|
|
const timestamp = emailSuppression?.info?.timestamp;
|
|
|
|
const formattedDate = timestamp ? moment(new Date(timestamp)).format('D MMM YYYY') : null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
suppressed: emailSuppression?.suppressed,
|
|
|
|
reason: emailSuppression?.info?.reason,
|
|
|
|
date: formattedDate
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-14 17:40:04 +03:00
|
|
|
@action
|
|
|
|
updateNewsletterPreference(newsletter, event) {
|
|
|
|
let updatedNewsletters = [];
|
2022-04-19 20:09:48 +03:00
|
|
|
|
2022-04-14 17:40:04 +03:00
|
|
|
const selectedNewsletter = this.args.newsletters.find((d) => {
|
|
|
|
return d.id === newsletter.id;
|
|
|
|
});
|
2022-04-19 20:09:48 +03:00
|
|
|
|
2022-04-14 17:40:04 +03:00
|
|
|
if (!event.target.checked) {
|
2022-10-07 19:03:45 +03:00
|
|
|
updatedNewsletters = this.args.member.newsletters.filter((d) => {
|
2022-04-14 17:40:04 +03:00
|
|
|
return d.id !== newsletter.id;
|
|
|
|
});
|
|
|
|
} else {
|
2022-10-07 19:03:45 +03:00
|
|
|
updatedNewsletters = this.args.member.newsletters.filter((d) => {
|
2022-04-14 17:40:04 +03:00
|
|
|
return d.id !== newsletter.id;
|
|
|
|
}).concat(selectedNewsletter);
|
|
|
|
}
|
|
|
|
this.args.setMemberNewsletters(updatedNewsletters);
|
|
|
|
}
|
|
|
|
}
|