Skip to content

Commit

Permalink
Additional reward cards for point history (#93)
Browse files Browse the repository at this point in the history
* Implement additional reward cards for point history.

* PR change requests: change reward card order, cleanup.
  • Loading branch information
tommypoa authored Apr 18, 2020
1 parent 0fd2f50 commit 036b191
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 18 deletions.
2 changes: 2 additions & 0 deletions components/rewards/PointsHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
86 changes: 69 additions & 17 deletions components/rewards/Transaction.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,30 +12,77 @@ 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',
month: 'short',
day: 'numeric',
};
return (
<TransactionCard>
<CircleIcon
icon="check"
iconColor={Colors.primaryGreen}
circleColor={Colors.lightestGreen}
/>
<ContentContainer>
<Caption color={Colors.secondaryText}>
{`${date.toLocaleDateString('en-US', options)}${storeName}`}
</Caption>
<Subhead>{`${pointsEarned} points earned`}</Subhead>
<Caption color={Colors.secondaryText}>
{`for ${displayDollarValue(totalSale || 0)} of healthy products`}
</Caption>
</ContentContainer>
</TransactionCard>
<View>
{/* Display rewards unlocked */}
{[...Array(rewardsUnlocked).keys()].map(() => (
<TransactionCard>
<CircleIcon
icon="star"
iconColor={Colors.primaryGreen}
circleColor={Colors.lightestGreen}
/>
<ContentContainer>
<Caption color={Colors.secondaryText}>
{`${date.toLocaleDateString('en-US', options)}${storeName}`}
</Caption>
<Subhead>{`$5 reward unlocked`}</Subhead>
<Caption color={Colors.secondaryText}>
{`for 500 earned points`}
</Caption>
</ContentContainer>
</TransactionCard>
))}

{/* Display points earned */}
<TransactionCard>
<CircleIcon
icon="check"
iconColor={Colors.primaryGreen}
circleColor={Colors.lightestGreen}
/>
<ContentContainer>
<Caption color={Colors.secondaryText}>
{`${date.toLocaleDateString('en-US', options)}${storeName}`}
</Caption>
<Subhead>{`${pointsEarned} points earned`}</Subhead>
<Caption color={Colors.secondaryText}>
{`for ${displayDollarValue(totalSale || 0)} of healthy products`}
</Caption>
</ContentContainer>
</TransactionCard>

{/* Display rewards applied */}
{[...Array(rewardsApplied).keys()].map(() => (
<TransactionCard>
<CircleIcon
icon="star"
iconColor={Colors.primaryOrange}
circleColor={Colors.lightestOrange}
/>
<ContentContainer>
<Caption color={Colors.secondaryText}>
{`${date.toLocaleDateString('en-US', options)}${storeName}`}
</Caption>
<Subhead>{`$5 reward redeemed`}</Subhead>
</ContentContainer>
</TransactionCard>
))}
</View>
);
}

Expand All @@ -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;
7 changes: 6 additions & 1 deletion lib/rewardsUtils.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 036b191

Please sign in to comment.