Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Calculate finalAmount as per weekly param at payment.js level
Browse files Browse the repository at this point in the history
  • Loading branch information
venkateshf22 committed May 28, 2020
1 parent 7744443 commit b408689
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/javascript/components/ExpressDonation/ExpressDonation.js
Expand Up @@ -56,7 +56,7 @@ export class ExpressDonation extends Component {
return {
payment: {
currency: this.props.fundraiser.currency,
amount: this.props.fundraiser.donationAmount,
amount: this.props.getFinalDonationAmount,
recurring: this.props.fundraiser.recurring,
payment_method_id: this.state.currentPaymentMethod.id,
},
Expand Down Expand Up @@ -238,7 +238,7 @@ export class ExpressDonation extends Component {
values={{
amount: (
<CurrencyAmount
amount={this.props.fundraiser.donationAmount || 0}
amount={this.props.getFinalDonationAmount}
currency={this.props.fundraiser.currency}
/>
),
Expand Down
13 changes: 11 additions & 2 deletions app/javascript/components/Payment/Payment.js
Expand Up @@ -197,6 +197,14 @@ export class Payment extends Component {
ee.on('fundraiser:change_recurring', this.makePayment, this);
}

getFinalDonationAmount = () => {
return (
(!this.state.recurringDonor && this.props.weekly
? this.props.fundraiser.donationAmount * 4
: this.props.fundraiser.donationAmount) || 0
);
};

// this should actually be a selector (a fn that returns a slice of state)
donationData() {
const {
Expand All @@ -212,7 +220,7 @@ export class Payment extends Component {
} = this.props;

return {
amount: this.props.weekly ? donationAmount * 4 : donationAmount,
amount: this.getFinalDonationAmount(),
currency: currency,
recurring: recurring,
store_in_vault: storeInVault,
Expand Down Expand Up @@ -493,6 +501,7 @@ export class Payment extends Component {
hidden={this.isExpressHidden()}
showOneOffButton={this.showOneOffButton()}
showMonthlyButton={this.showMonthlyButton()}
getFinalDonationAmount={this.getFinalDonationAmount()}
weekly={this.props.weekly}
data={{
src: this.state.src,
Expand Down Expand Up @@ -579,7 +588,7 @@ export class Payment extends Component {
values={{
amount: (
<CurrencyAmount
amount={donationAmount || 0}
amount={this.getFinalDonationAmount()}
currency={currency}
/>
),
Expand Down

0 comments on commit b408689

Please sign in to comment.