Fixed newsletter subscription toggles on member details screen

no issue

- member records are not re-fetched when navigating from the members list to the member details screen, instead the already loaded member object is passed through to the route directly to provide a faster navigation experience
- however, the objects used in the member list are proxy objects in order to support the lazy-loading infinite scroll. Proxy objects require the use of `get()` so errors were thrown when the newsletter subscription toggles were used
This commit is contained in:
Kevin Ansfield 2022-04-19 18:09:48 +01:00
parent 86a69ece65
commit 5437063d4b

View File

@ -1,5 +1,5 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {action, get} from '@ember/object';
import {tracked} from '@glimmer/tracking';
export default class MembersNewsletterPreference extends Component {
@ -29,15 +29,19 @@ export default class MembersNewsletterPreference extends Component {
@action
updateNewsletterPreference(newsletter, event) {
let updatedNewsletters = [];
const selectedNewsletter = this.args.newsletters.find((d) => {
return d.id === newsletter.id;
});
// get() is required because member can be a proxy object when loaded
// directly from the members list
if (!event.target.checked) {
updatedNewsletters = this.args.member.newsletters.filter((d) => {
updatedNewsletters = get(this.args.member, 'newsletters').filter((d) => {
return d.id !== newsletter.id;
});
} else {
updatedNewsletters = this.args.member.newsletters.filter((d) => {
updatedNewsletters = get(this.args.member, 'newsletters').filter((d) => {
return d.id !== newsletter.id;
}).concat(selectedNewsletter);
}