-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate UNSAFE_componentWillReceiveProps #1957
Changes from all commits
185c987
d3d21ce
23a02c6
f86d797
9462ac9
f6ce34d
0b0ccf9
cad3e1b
c58192d
f037661
ddca815
44e5d7f
2a95482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,29 +67,31 @@ class PaymentMethodChooser extends React.Component { | |
}); | ||
} | ||
|
||
UNSAFE_componentWillReceiveProps(newProps) { | ||
componentDidUpdate(prevProps) { | ||
// TODO: Remove these hacky fixes | ||
// Most likely means need to rework the logic split between this and SubscriptionCard component | ||
|
||
const { paymentMethodInUse, paymentMethodsList, editMode } = newProps; | ||
const { paymentMethodInUse, paymentMethodsList, editMode } = this.props; | ||
|
||
if (!paymentMethodInUse.name) { | ||
// set state to modified | ||
this.setState({ modified: true }); | ||
// If there was an existing card, select that | ||
if (paymentMethodsList.length > 0) { | ||
this.handleChange({ uuid: paymentMethodsList[0].uuid }); | ||
if (!prevProps.paymentMethodsList && paymentMethodsList) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why introducing this test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid infinite loops, since we're setting state in |
||
if (!paymentMethodInUse.name) { | ||
// set state to modified | ||
this.setState({ modified: true }); | ||
// If there was an existing card, select that | ||
if (paymentMethodsList.length > 0) { | ||
this.handleChange({ uuid: paymentMethodsList[0].uuid }); | ||
} | ||
} | ||
} | ||
|
||
// hack to revert back to cc selector | ||
if (!this.props.editMode && editMode) { | ||
this.setState({ showNewCreditCardForm: false }); | ||
} | ||
// hack to revert back to cc selector | ||
if (!prevProps.editMode && editMode) { | ||
this.setState({ showNewCreditCardForm: false }); | ||
} | ||
|
||
// handles the case where there are no existing credit cards | ||
if (paymentMethodsList.length === 0 && editMode) { | ||
this.setState({ showNewCreditCardForm: true }); | ||
// handles the case where there are no existing credit cards | ||
if (paymentMethodsList.length === 0 && editMode) { | ||
this.setState({ showNewCreditCardForm: true }); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially,
paypalEmail
isnull
before the prop updates.defaultValue
binds to the initial value during the first render so it doesn't change if the user is actually logged in and has a default email.This change fixes that.