chore(donate): unify donation config
This commit can be further optimised to DRY out values
This commit is contained in:
		| @@ -3,6 +3,11 @@ import debug from 'debug'; | ||||
| import crypto from 'crypto'; | ||||
| import { isEmail, isNumeric } from 'validator'; | ||||
|  | ||||
| import { | ||||
|   durationKeysConfig, | ||||
|   donationOneTimeConfig, | ||||
|   donationSubscriptionConfig | ||||
| } from '../../../config/donation-settings'; | ||||
| import keys from '../../../config/secrets'; | ||||
|  | ||||
| const log = debug('fcc:boot:donate'); | ||||
| @@ -12,19 +17,6 @@ export default function donateBoot(app, done) { | ||||
|   const api = app.loopback.Router(); | ||||
|   const donateRouter = app.loopback.Router(); | ||||
|  | ||||
|   const durationKeys = ['year', 'month', 'onetime']; | ||||
|   const donationOneTimeConfig = [100000, 25000, 3500]; | ||||
|   const donationSubscriptionConfig = { | ||||
|     duration: { | ||||
|       year: 'Yearly', | ||||
|       month: 'Monthly' | ||||
|     }, | ||||
|     plans: { | ||||
|       year: [100000, 25000, 3500], | ||||
|       month: [5000, 3500, 500] | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   const subscriptionPlans = Object.keys( | ||||
|     donationSubscriptionConfig.plans | ||||
|   ).reduce( | ||||
| @@ -62,7 +54,7 @@ export default function donateBoot(app, done) { | ||||
|   function validStripeForm(amount, duration, email) { | ||||
|     return isEmail('' + email) && | ||||
|       isNumeric('' + amount) && | ||||
|       durationKeys.includes(duration) && | ||||
|       durationKeysConfig.includes(duration) && | ||||
|       duration === 'onetime' | ||||
|       ? donationOneTimeConfig.includes(amount) | ||||
|       : donationSubscriptionConfig.plans[duration]; | ||||
|   | ||||
| @@ -13,6 +13,12 @@ import { | ||||
|   Radio | ||||
| } from '@freecodecamp/react-bootstrap'; | ||||
| import { StripeProvider, Elements } from 'react-stripe-elements'; | ||||
|  | ||||
| import { | ||||
|   amountsConfig, | ||||
|   durationsConfig, | ||||
|   defaultStateConfig | ||||
| } from '../../../../../config/donation-settings'; | ||||
| import { apiLocation } from '../../../../config/env.json'; | ||||
| import Spacer from '../../helpers/Spacer'; | ||||
| import DonateFormChildViewForHOC from './DonateFormChildViewForHOC'; | ||||
| @@ -64,23 +70,13 @@ class DonateForm extends Component { | ||||
|   constructor(...args) { | ||||
|     super(...args); | ||||
|  | ||||
|     this.durations = durationsConfig; | ||||
|     this.amounts = amountsConfig; | ||||
|  | ||||
|     this.state = { | ||||
|       processing: false, | ||||
|       isDonating: this.props.isDonating, | ||||
|       donationAmount: 5000, | ||||
|       donationDuration: 'month', | ||||
|       paymentType: 'Card' | ||||
|     }; | ||||
|  | ||||
|     this.durations = { | ||||
|       year: 'yearly', | ||||
|       month: 'monthly', | ||||
|       onetime: 'one-time' | ||||
|     }; | ||||
|     this.amounts = { | ||||
|       year: [100000, 25000, 3500], | ||||
|       month: [5000, 3500, 500], | ||||
|       onetime: [100000, 25000, 3500] | ||||
|       ...defaultStateConfig | ||||
|     }; | ||||
|  | ||||
|     this.getActiveDonationAmount = this.getActiveDonationAmount.bind(this); | ||||
|   | ||||
							
								
								
									
										39
									
								
								config/donation-settings.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								config/donation-settings.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| // Configuration for client side | ||||
| const durationsConfig = { | ||||
|   year: 'yearly', | ||||
|   month: 'monthly', | ||||
|   onetime: 'one-time' | ||||
| }; | ||||
| const amountsConfig = { | ||||
|   year: [100000, 25000, 3500], | ||||
|   month: [5000, 3500, 500], | ||||
|   onetime: [100000, 25000, 3500] | ||||
| }; | ||||
| const defaultStateConfig = { | ||||
|   donationAmount: 5000, | ||||
|   donationDuration: 'month', | ||||
|   paymentType: 'Card' | ||||
| }; | ||||
|  | ||||
| // Configuration for server side | ||||
| const durationKeysConfig = ['year', 'month', 'onetime']; | ||||
| const donationOneTimeConfig = [100000, 25000, 3500]; | ||||
| const donationSubscriptionConfig = { | ||||
|   duration: { | ||||
|     year: 'Yearly', | ||||
|     month: 'Monthly' | ||||
|   }, | ||||
|   plans: { | ||||
|     year: [100000, 25000, 3500], | ||||
|     month: [5000, 3500, 500] | ||||
|   } | ||||
| }; | ||||
|  | ||||
| module.exports = { | ||||
|   durationsConfig, | ||||
|   amountsConfig, | ||||
|   defaultStateConfig, | ||||
|   durationKeysConfig, | ||||
|   donationOneTimeConfig, | ||||
|   donationSubscriptionConfig | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user