From 8fbd26ff333f223d495b0e1070b6b326fa96df89 Mon Sep 17 00:00:00 2001
From: Ahmad Abdolsaheb
Date: Tue, 12 Feb 2019 18:37:04 +0300
Subject: [PATCH] fix: optimize donate other
---
client/src/pages/donate-other.js | 86 +++++++++++++-------------------
1 file changed, 35 insertions(+), 51 deletions(-)
diff --git a/client/src/pages/donate-other.js b/client/src/pages/donate-other.js
index 54d4abd66b..250d137451 100644
--- a/client/src/pages/donate-other.js
+++ b/client/src/pages/donate-other.js
@@ -1,12 +1,13 @@
/* eslint-disable max-len */
import React, { Component, Fragment } from 'react';
import Helmet from 'react-helmet';
-import ReactGA from 'react-ga';
+import ReactGA from '../analytics/index.js';
+import { Link } from 'gatsby';
import { Grid, Col, Row } from '@freecodecamp/react-bootstrap';
import Spacer from '../components/helpers/Spacer';
-const payPalPayments = [
+const paypalMonthlyDonations = [
{ eventLabel: 'paypal',
eventValue: 5,
defaultValueHash: 'KTAXU8B4MYAT8',
@@ -36,61 +37,42 @@ const payPalPayments = [
eventValue: 250,
defaultValueHash: '69JGTY4DHSTEN',
defaultValue: 'Donate $250 each month'
- },
- { eventLabel: 'paypal one time donation',
- eventValue: 0,
- defaultValueHash: 'B256JC6ZCWD3J',
- defaultValue: 'Make a one-time donation'
}
];
+const paypalOneTimeDonation = {
+ eventLabel: 'paypal one time donation',
+ eventValue: 0,
+ defaultValueHash: 'B256JC6ZCWD3J',
+ defaultValue: 'Make a one-time donation'
+};
+
class IndexPage extends Component {
- constructor(props, context) {
- super(props, context);
- }
- formbuilder(eventLabel, eventValue, defaultValueHash, defaultValue) {
+ renderForm(item) {
return (
- ReactGA.event({category: 'Donation', action: 'paypal', label: eventValue.toString()})}>
-
-
+
);
}
- formfilter = (array, frequency) => {
- if (frequency === 'monthly') {
- return array
- .filter(item => item.eventValue > 0)
- .map((item) => {
- return this.formbuilder(item.eventLabel, item.eventValue, item.defaultValueHash, item.defaultValue);
- });
- } else {
- return array
- .filter(item => item.eventValue === 0)
- .map((item) => {
- return this.formbuilder(item.eventLabel, item.eventValue, item.defaultValueHash, item.defaultValue);
- });
- }
- }
-
render() {
return (
@@ -117,7 +99,9 @@ class IndexPage extends Component {
the links below and following the instructions on PayPal. You can
easily stop your donations at any time in the future.
- {this.formfilter(payPalPayments, 'monthly')}
+ {paypalMonthlyDonations.map((item) => {
+ return this.renderForm(item);
+ })}
Make a one-time donation using PayPal
@@ -125,7 +109,7 @@ class IndexPage extends Component {
amount of money by clicking one of the links below and following the
instructions on PayPal:
- {this.formfilter(payPalPayments)}
+ {this.renderForm(paypalOneTimeDonation)}
Get your employer to match your donation
@@ -198,7 +182,7 @@ class IndexPage extends Component {