Просмотр исходного кода

fix(settings): fix bug where subscription settings get duplicated (#42976)

This bug happens when you have multiple emails and so the index in one
set doesn't match the index within all of them.
Stephen Cefali 2 лет назад
Родитель
Сommit
787490a6c7
1 измененных файлов с 9 добавлено и 3 удалено
  1. 9 3
      static/app/views/settings/account/accountSubscriptions.tsx

+ 9 - 3
static/app/views/settings/account/accountSubscriptions.tsx

@@ -1,5 +1,6 @@
 import {Fragment} from 'react';
 import styled from '@emotion/styled';
+import findIndex from 'lodash/findIndex';
 import groupBy from 'lodash/groupBy';
 import moment from 'moment';
 
@@ -40,12 +41,13 @@ class AccountSubscriptions extends AsyncView<AsyncView['props'], State> {
     return 'Subscriptions';
   }
 
-  handleToggle = (subscription: Subscription, index: number, _e: React.MouseEvent) => {
+  handleToggle = (subscription: Subscription, listId: number, _e: React.MouseEvent) => {
     const subscribed = !subscription.subscribed;
     const oldSubscriptions = this.state.subscriptions;
 
     this.setState(state => {
       const newSubscriptions = state.subscriptions.slice();
+      const index = findIndex(newSubscriptions, {listId});
       newSubscriptions[index] = {
         ...subscription,
         subscribed,
@@ -109,7 +111,7 @@ class AccountSubscriptions extends AsyncView<AsyncView['props'], State> {
                       </Heading>
                     )}
 
-                    {subscriptions.map((subscription, index) => (
+                    {subscriptions.map(subscription => (
                       <PanelItem center key={subscription.listId}>
                         <SubscriptionDetails>
                           <SubscriptionName>{subscription.listName}</SubscriptionName>
@@ -139,7 +141,11 @@ class AccountSubscriptions extends AsyncView<AsyncView['props'], State> {
                           <Switch
                             isActive={subscription.subscribed}
                             size="lg"
-                            toggle={this.handleToggle.bind(this, subscription, index)}
+                            toggle={this.handleToggle.bind(
+                              this,
+                              subscription,
+                              subscription.listId
+                            )}
                           />
                         </div>
                       </PanelItem>