2018-03-26 14:32:43 -07:00
|
|
|
// @flow
|
2018-11-25 20:21:25 -05:00
|
|
|
import * as ICONS from 'constants/icons';
|
2017-12-21 18:08:54 -03:00
|
|
|
import React from 'react';
|
2018-03-26 14:32:43 -07:00
|
|
|
import Icon from 'component/common/icon';
|
2017-12-21 18:08:54 -03:00
|
|
|
import RewardLink from 'component/rewardLink';
|
2018-03-26 14:32:43 -07:00
|
|
|
import Button from 'component/button';
|
2019-09-26 12:07:11 -04:00
|
|
|
import Card from 'component/common/card';
|
2020-06-15 16:33:03 -04:00
|
|
|
import rewards from 'rewards';
|
2017-08-18 23:08:01 -04:00
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
type Props = {
|
2018-09-25 20:12:07 -04:00
|
|
|
openRewardCodeModal: () => void,
|
2020-01-14 15:44:07 -05:00
|
|
|
openSetReferrerModal: () => void,
|
2018-03-26 14:32:43 -07:00
|
|
|
reward: {
|
|
|
|
id: string,
|
|
|
|
reward_title: string,
|
|
|
|
reward_amount: number,
|
2019-09-04 17:37:28 -04:00
|
|
|
reward_range?: string,
|
2018-03-26 14:32:43 -07:00
|
|
|
transaction_id: string,
|
|
|
|
created_at: string,
|
|
|
|
reward_description: string,
|
|
|
|
reward_type: string,
|
2020-03-26 15:14:22 -04:00
|
|
|
claim_code: string,
|
2018-03-26 14:32:43 -07:00
|
|
|
},
|
2020-01-14 15:44:07 -05:00
|
|
|
user: User,
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
2017-08-18 23:08:01 -04:00
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
const RewardTile = (props: Props) => {
|
2020-01-14 15:44:07 -05:00
|
|
|
const { reward, openRewardCodeModal, openSetReferrerModal, user } = props;
|
|
|
|
const referrerSet = user && user.invited_by_id;
|
2017-08-18 23:08:01 -04:00
|
|
|
const claimed = !!reward.transaction_id;
|
2020-01-16 21:14:07 -05:00
|
|
|
const customActionsRewards = [rewards.TYPE_REFERRAL, rewards.TYPE_REFEREE];
|
2017-08-18 23:08:01 -04:00
|
|
|
|
|
|
|
return (
|
2019-09-26 12:07:11 -04:00
|
|
|
<Card
|
|
|
|
title={reward.reward_title}
|
|
|
|
subtitle={reward.reward_description}
|
|
|
|
actions={
|
2020-09-01 15:21:01 -04:00
|
|
|
<div className="section__actions">
|
2019-09-26 12:07:11 -04:00
|
|
|
{reward.reward_type === rewards.TYPE_GENERATED_CODE && (
|
|
|
|
<Button button="primary" onClick={openRewardCodeModal} label={__('Enter Code')} />
|
|
|
|
)}
|
|
|
|
{reward.reward_type === rewards.TYPE_REFERRAL && (
|
2020-06-20 17:23:50 +08:00
|
|
|
<Button button="primary" navigate="/$/invite" label={__('Go To Invites')} />
|
2020-01-14 15:44:07 -05:00
|
|
|
)}
|
|
|
|
{reward.reward_type === rewards.TYPE_REFEREE && (
|
2020-01-16 21:14:07 -05:00
|
|
|
<>
|
|
|
|
{referrerSet && <RewardLink button reward_type={reward.reward_type} />}
|
|
|
|
<Button
|
|
|
|
button={referrerSet ? 'link' : 'primary'}
|
|
|
|
onClick={openSetReferrerModal}
|
|
|
|
label={referrerSet ? __('Change Inviter') : __('Set Inviter')}
|
|
|
|
/>
|
|
|
|
</>
|
2020-01-06 17:53:27 -05:00
|
|
|
)}
|
2020-01-16 21:14:07 -05:00
|
|
|
{!customActionsRewards.some(i => i === reward.reward_type) &&
|
2019-09-26 12:07:11 -04:00
|
|
|
(claimed ? (
|
|
|
|
<span>
|
|
|
|
<Icon icon={ICONS.COMPLETED} /> {__('Reward claimed.')}
|
|
|
|
</span>
|
|
|
|
) : (
|
2020-03-26 15:14:22 -04:00
|
|
|
<RewardLink button claim_code={reward.claim_code} />
|
2019-09-26 12:07:11 -04:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2017-08-18 23:08:01 -04:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RewardTile;
|