From 036b19188b4bf15ca9e5b836bef3aadc9c591776 Mon Sep 17 00:00:00 2001 From: Tommy Poa <35573990+tommypoa@users.noreply.github.com> Date: Sun, 19 Apr 2020 03:07:32 +0800 Subject: [PATCH] Additional reward cards for point history (#93) * Implement additional reward cards for point history. * PR change requests: change reward card order, cleanup. --- components/rewards/PointsHistory.js | 2 + components/rewards/Transaction.js | 86 +++++++++++++++++++++++------ lib/rewardsUtils.js | 7 ++- 3 files changed, 77 insertions(+), 18 deletions(-) diff --git a/components/rewards/PointsHistory.js b/components/rewards/PointsHistory.js index a22629b9..4a6abfaa 100644 --- a/components/rewards/PointsHistory.js +++ b/components/rewards/PointsHistory.js @@ -29,6 +29,8 @@ function PointsHistory({ transactions }) { storeName={item.storeName} subtotal={item.subtotal} totalSale={item.totalSale} + rewardsUnlocked={item.rewardsUnlocked} + rewardsApplied={item.rewardsApplied} /> )} keyExtractor={item => item.id} diff --git a/components/rewards/Transaction.js b/components/rewards/Transaction.js index 8d92a955..45ec8750 100644 --- a/components/rewards/Transaction.js +++ b/components/rewards/Transaction.js @@ -1,5 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; +import { View } from 'react-native'; import Colors from '../../constants/Colors'; import { displayDollarValue } from '../../lib/common'; import { ContentContainer, TransactionCard } from '../../styled/transaction'; @@ -11,7 +12,14 @@ import CircleIcon from '../CircleIcon'; * */ function Transaction(props) { - const { date, storeName, pointsEarned, totalSale } = props; + const { + date, + storeName, + pointsEarned, + totalSale, + rewardsUnlocked, + rewardsApplied, + } = props; const options = { weekday: 'short', year: 'numeric', @@ -19,22 +27,62 @@ function Transaction(props) { day: 'numeric', }; return ( - - - - - {`${date.toLocaleDateString('en-US', options)} • ${storeName}`} - - {`${pointsEarned} points earned`} - - {`for ${displayDollarValue(totalSale || 0)} of healthy products`} - - - + + {/* Display rewards unlocked */} + {[...Array(rewardsUnlocked).keys()].map(() => ( + + + + + {`${date.toLocaleDateString('en-US', options)} • ${storeName}`} + + {`$5 reward unlocked`} + + {`for 500 earned points`} + + + + ))} + + {/* Display points earned */} + + + + + {`${date.toLocaleDateString('en-US', options)} • ${storeName}`} + + {`${pointsEarned} points earned`} + + {`for ${displayDollarValue(totalSale || 0)} of healthy products`} + + + + + {/* Display rewards applied */} + {[...Array(rewardsApplied).keys()].map(() => ( + + + + + {`${date.toLocaleDateString('en-US', options)} • ${storeName}`} + + {`$5 reward redeemed`} + + + ))} + ); } @@ -43,12 +91,16 @@ Transaction.propTypes = { storeName: PropTypes.array, pointsEarned: PropTypes.number, totalSale: PropTypes.number, + rewardsUnlocked: PropTypes.number, + rewardsApplied: PropTypes.number, }; Transaction.defaultProps = { storeName: null, pointsEarned: 0, totalSale: 0, + rewardsUnlocked: null, + rewardsApplied: 0, }; export default Transaction; diff --git a/lib/rewardsUtils.js b/lib/rewardsUtils.js index a6966f0c..acbad84e 100644 --- a/lib/rewardsUtils.js +++ b/lib/rewardsUtils.js @@ -1,8 +1,13 @@ +import { rewardPointValue } from '../constants/Rewards'; import { getAllTransactions } from './airtable/request'; // Transform date to Date object function updateTransactionData(record) { - return { ...record, date: new Date(record.date) }; + const rewardsUnlocked = parseInt( + ((record.currentPoints % rewardPointValue) + record.pointsEarned) / + rewardPointValue + ); + return { ...record, rewardsUnlocked, date: new Date(record.date) }; } export async function getCustomerTransactions(customerId) {