Skip to content

Commit 245012a

Browse files
committed
refactor: simplify affiliate referral status display logic
1 parent e6be4ee commit 245012a

File tree

2 files changed

+36
-48
lines changed

2 files changed

+36
-48
lines changed

app/components/affiliate-page/affiliate-referred-user-item.hbs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,44 @@
2222
</div>
2323
</div>
2424
</a>
25-
<div class="flex items-center flex-wrap gap-y-2">
25+
<div class="flex items-center flex-wrap gap-2">
2626
{{#if (gt @affiliateReferral.totalEarningsAmountInDollars 0)}}
27-
<div class="flex shrink-0">
28-
<span
29-
class="inline-flex border border-green-300 rounded-full bg-green-100 px-2 text-xs font-semibold leading-5 text-green-700 mr-2"
30-
>${{@affiliateReferral.spentAmountInDollars}} spent</span>
27+
<Pill @color="green" class="shrink-0">
28+
${{@affiliateReferral.spentAmountInDollars}}
29+
spent
30+
3131
<EmberTooltip @text="This is the amount {{@affiliateReferral.customer.username}} has spent so far." />
32-
</div>
32+
</Pill>
3333
{{/if}}
34+
3435
{{#if (gt @affiliateReferral.upcomingPaymentAmountInDollars 0)}}
35-
<div class="flex shrink-0">
36-
<span
37-
class="inline-flex border border-yellow-300 rounded-full bg-yellow-100 px-2 text-xs font-semibold leading-5 text-yellow-700 mr-2"
38-
>${{@affiliateReferral.upcomingPaymentAmountInDollars}} pending</span>
36+
<Pill @color="yellow" class="shrink-0">
37+
${{@affiliateReferral.upcomingPaymentAmountInDollars}}
38+
pending
39+
3940
<EmberTooltip @text="This is the value of {{@affiliateReferral.customer.username}}'s upcoming payment." />
40-
</div>
41+
</Pill>
4142
{{/if}}
42-
<div class="flex shrink-0">
43-
{{#if @affiliateReferral.statusIsTrialing}}
44-
<span
45-
class="inline-flex border border-yellow-300 rounded-full bg-yellow-100 px-2 text-xs font-semibold leading-5 text-yellow-700 mr-2"
46-
>Trialing</span>
47-
<EmberTooltip @text="This user has started a trial. We haven't received their first payment yet." />
48-
{{else if @affiliateReferral.statusIsPendingTrial}}
49-
<span class="inline-flex border border-gray-300 rounded-full bg-gray-100 px-2 text-xs font-semibold leading-5 text-gray-700 mr-2">Signed up</span>
50-
<EmberTooltip @text="This user has accepted your referral offer but hasn't started a trial yet." />
51-
{{else if @affiliateReferral.statusIsFirstChargeSuccessful}}
52-
<span
53-
class="inline-flex border border-green-300 rounded-full bg-green-100 px-2 text-xs font-semibold leading-5 text-green-700 mr-2"
54-
>Paid</span>
43+
44+
{{#if @affiliateReferral.statusIsAwaitingFirstCharge}}
45+
<Pill @color="gray" class="shrink-0">
46+
Signed up
47+
48+
<EmberTooltip @text="This user has accepted your referral offer but hasn't made a payment yet." />
49+
</Pill>
50+
{{else if @affiliateReferral.statusIsFirstChargeSuccessful}}
51+
<Pill @color="green" class="shrink-0">
52+
Paid
53+
5554
<EmberTooltip @text="This user has made at least one payment that is attributable to you." />
56-
{{else}}
57-
<span
58-
class="inline-flex border border-gray-300 rounded-full bg-gray-100 px-2 text-xs font-semibold leading-5 text-gray-700 mr-2"
59-
>Inactive</span>
60-
<EmberTooltip @text="This user either cancelled their trial, joined a paid team account or availed a separate discount." />
61-
{{/if}}
62-
</div>
55+
</Pill>
56+
{{else}}
57+
<Pill @color="gray" class="shrink-0">
58+
Inactive
59+
60+
<EmberTooltip @text="This user either joined a paid team account or availed a separate discount." />
61+
</Pill>
62+
{{/if}}
6363

6464
<span class="text-gray-400 text-xs hidden lg:block">{{date-from-now @affiliateReferral.activatedAt}}</span>
6565
</div>

app/models/affiliate-referral.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ export default class AffiliateReferralModel extends Model {
88
@belongsTo('affiliate-link', { async: false, inverse: 'referrals' }) declare affiliateLink: AffiliateLinkModel;
99

1010
@attr('date') declare activatedAt: Date;
11-
@attr('string') declare status: 'pending_trial' | 'trialing' | 'first_charge_successful' | 'trial_cancelled' | 'inactive';
11+
@attr('string') declare status: 'awaiting_first_charge' | 'first_charge_successful' | 'inactive';
1212
@attr('number') declare spentAmountInCents: number;
1313
@attr('number') declare upcomingPaymentAmountInCents: number;
1414
@attr('number') declare withdrawableEarningsAmountInCents: number;
1515
@attr('number') declare withheldEarningsAmountInCents: number;
1616

17-
get hasStartedTrial() {
18-
return this.statusIsTrialing || this.statusIsFirstChargeSuccessful || this.statusIsTrialCancelled;
19-
}
20-
2117
get spentAmountInDollars() {
2218
return this.spentAmountInCents / 100;
2319
}
2420

21+
get statusIsAwaitingFirstCharge() {
22+
return this.status === 'awaiting_first_charge';
23+
}
24+
2525
get statusIsFirstChargeSuccessful() {
2626
return this.status === 'first_charge_successful';
2727
}
@@ -30,18 +30,6 @@ export default class AffiliateReferralModel extends Model {
3030
return this.status === 'inactive';
3131
}
3232

33-
get statusIsPendingTrial() {
34-
return this.status === 'pending_trial';
35-
}
36-
37-
get statusIsTrialCancelled() {
38-
return this.status === 'trial_cancelled';
39-
}
40-
41-
get statusIsTrialing() {
42-
return this.status === 'trialing';
43-
}
44-
4533
get totalEarningsAmountInCents() {
4634
return this.withdrawableEarningsAmountInCents + this.withheldEarningsAmountInCents;
4735
}

0 commit comments

Comments
 (0)