Skip to content

Commit 025c7fe

Browse files
authored
Merge pull request #3272 from codecrafters-io/fix-rename-affiliate-username-avatar
fix: rename affiliate username and avatar fields across UI and model
2 parents e3e959d + 98346f7 commit 025c7fe

File tree

11 files changed

+35
-34
lines changed

11 files changed

+35
-34
lines changed

app/components/affiliate-link-page/accept-referral-button.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{else if this.currentUserIsReferrer}}
1818
<EmberTooltip @text="You can't accept your own referral offer." />
1919
{{else if this.currentUserHasActiveDiscountFromAffiliateReferral}}
20-
<EmberTooltip @text="You've already accepted {{this.currentUser.currentAffiliateReferral.affiliateLink.usernameForDisplay}}'s referral offer." />
20+
<EmberTooltip @text="You've already accepted {{this.currentUser.currentAffiliateReferral.affiliateLink.affiliateName}}'s referral offer." />
2121
{{else if this.currentUserCanAccessMembershipBenefits}}
2222
<EmberTooltip @text="As a CodeCrafters member, you already have full access." />
2323
{{/if}}

app/components/affiliate-link-page/accept-referral-container.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<div
22
class="flex flex-col items-center gap-y-6 bg-teal-50/25 dark:bg-teal-800/40 border-teal-500 dark:border-teal-600 px-4
33
{{if (eq @verticalSize 'tall') 'py-12' 'py-8'}}
4-
border rounded-md shadow-xl"
4+
border rounded-md shadow-xl group"
55
...attributes
66
>
77
<div class="flex items-center justify-center">
8-
{{#if @affiliateLink.overriddenAffiliateAvatarUrl}}
9-
{{! No border for overridden avatars, we'll expect them to include a border in the image itself if needed }}
10-
<img alt="avatar" src={{@affiliateLink.overriddenAffiliateAvatarUrl}} class="w-16 h-16 mr-2" />
11-
{{else}}
12-
<AvatarImage
13-
@user={{@affiliateLink.user}}
14-
class="w-16 h-16 border border-gray-300 shadow-xs group-hover:shadow-sm mr-2 transition-shadow rounded-md"
8+
{{#if @affiliateLink.avatarIsGitHubAvatar}}
9+
<img
10+
alt="avatar"
11+
src={{@affiliateLink.affiliateAvatarUrl}}
12+
class="w-16 h-16 mr-2 rounded-md border border-gray-300 shadow-xs group-hover:shadow-sm transition-shadow"
1513
/>
14+
{{else}}
15+
<img alt="avatar" src={{@affiliateLink.affiliateAvatarUrl}} class="w-16 h-16 mr-2" />
1616
{{/if}}
1717

1818
{{svg-jar "plus" class="w-10 h-10 text-gray-600 dark:text-gray-400 mr-2 opacity-90 group-hover:opacity-100 transition-all"}}
@@ -21,7 +21,7 @@
2121
</div>
2222

2323
<div class="prose dark:prose-invert text-center max-w-sm">
24-
<b class="dark:text-gray-50">@{{@affiliateLink.usernameForDisplay}}</b>
24+
<b class="dark:text-gray-50">@{{@affiliateLink.affiliateName}}</b>
2525
wants you to try CodeCrafters. Signing up is free.
2626
<b class="dark:text-gray-50">40% off</b>
2727
if you upgrade.

app/components/pay-page/choose-membership-plan-modal/plan-card.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
5959
{{#if @promotionalDiscount.isFromAffiliateReferral}}<span
6060
class="text-nowrap"
61-
>{{@promotionalDiscount.affiliateReferral.affiliateLink.usernameForDisplay}}'s</span>
61+
>{{@promotionalDiscount.affiliateReferral.affiliateLink.affiliateName}}'s</span>
6262
referral offer{{else if @promotionalDiscount.isFromStage2Completion}}Stage 2 completion discount{{else if
6363
@promotionalDiscount.isFromSignup
6464
}}Signup discount{{/if}}, expires in

app/components/pay-page/referral-discount-notice.hbs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
</div>
99

1010
<div class="bg-repeating-gradient-to-b from-yellow-100 to-amber-500 text-transparent bg-clip-text leading-7 inline-block mt-0.5">
11-
{{#if @discount.affiliateReferral.affiliateLink.overriddenAffiliateAvatarUrl}}
11+
{{#if @discount.affiliateReferral.affiliateLink.avatarIsGitHubAvatar}}
1212
<img
1313
alt="avatar"
14-
src={{@discount.affiliateReferral.affiliateLink.overriddenAffiliateAvatarUrl}}
15-
class="inline-block mb-0 w-6 h-6 transform -translate-y-px"
14+
src={{@discount.affiliateReferral.affiliateLink.affiliateAvatarUrl}}
15+
class="inline-block w-6 h-6 border border-gray-100 rounded-full transform -translate-y-px"
1616
/>
1717
{{else}}
18-
<AvatarImage
19-
@user={{@discount.affiliateReferral.referrer}}
20-
class="inline-block mb-0 w-6 h-6 border border-gray-100 rounded-full transform -translate-y-px"
21-
/>
18+
<img alt="avatar" src={{@discount.affiliateReferral.affiliateLink.affiliateAvatarUrl}} class="inline-block w-6 h-6" />
2219
{{/if}}
2320

24-
<b>{{@discount.affiliateReferral.affiliateLink.usernameForDisplay}}</b>'s referral offer: Subscribe in
21+
<b>{{@discount.affiliateReferral.affiliateLink.affiliateName}}</b>'s referral offer: Subscribe in
2522
<span class="font-bold percy-timestamp font-mono text-lg border-b border-yellow-500 border-dashed">{{this.timeLeftText}}</span>
2623
to get
2724
<span class="font-bold">40% off</span>

app/models/affiliate-link.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,19 @@ export default class AffiliateLinkModel extends Model {
99

1010
@hasMany('affiliate-referral', { async: false, inverse: 'affiliateLink' }) declare referrals: AffiliateReferralModel[];
1111

12+
@attr('string') declare affiliateName: string;
13+
@attr('string') declare affiliateAvatarUrl: string;
1214
@attr('string') declare slug: string;
1315
@attr('string') declare url: string;
14-
@attr('string') declare overriddenAffiliateUsername: string | null;
15-
@attr('string') declare overriddenAffiliateAvatarUrl: string | null;
1616

17-
get avatarUrlForDisplay() {
18-
return this.overriddenAffiliateAvatarUrl || this.user.avatarUrl;
17+
get avatarIsGitHubAvatar(): boolean {
18+
return this.affiliateAvatarUrl.includes('avatars.githubusercontent.com');
1919
}
2020

2121
get totalEarningsAmountInCents() {
2222
return this.referrals.reduce((sum, referral) => sum + referral.totalEarningsAmountInCents, 0);
2323
}
2424

25-
get usernameForDisplay() {
26-
return this.overriddenAffiliateUsername || this.user.username;
27-
}
28-
2925
get visibleReferrals(): AffiliateReferralModel[] {
3026
const referralsGroupedByCustomer = this.referrals.reduce(
3127
groupByFieldReducer((referral) => referral.customer.id),

app/templates/join-course.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{page-title (concat "Join " this.model.affiliateLink.usernameForDisplay " on CodeCrafters") replace=true}}
1+
{{page-title (concat "Join " this.model.affiliateLink.affiliateName " on CodeCrafters") replace=true}}
22

33
{{! Note: This is very similar to the course overview page atm so it re-uses a lot of the same components. }}
44
<div class="container mx-auto lg:max-w-(--breakpoint-lg) pt-6 md:pt-10 pb-10 px-3 md:px-6">

app/templates/join-track.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{page-title (concat "Join " this.model.affiliateLink.usernameForDisplay " on CodeCrafters") replace=true}}
1+
{{page-title (concat "Join " this.model.affiliateLink.affiliateName " on CodeCrafters") replace=true}}
22

33
{{! Note: This is very similar to the track page atm so it re-uses a lot of the same components. }}
44
<div class="container mx-auto lg:max-w-(--breakpoint-lg) px-3 md:px-6 py-6 md:py-10">

app/templates/join.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{page-title (concat "Join " this.model.affiliateLink.usernameForDisplay " on CodeCrafters") replace=true}}
1+
{{page-title (concat "Join " this.model.affiliateLink.affiliateName " on CodeCrafters") replace=true}}
22

33
<div class="bg-white bg-github-green-dot-wall">
44
<div class="container mx-auto lg:max-w-(--breakpoint-xl) pt-8 sm:pt-16 pb-48 px-3 md:px-6">
@@ -41,7 +41,7 @@
4141

4242
<div class="flex flex-col gap-4 justify-center items-center mt-16">
4343
<AffiliateLinkPage::AcceptReferralButton @affiliateLink={{this.model.affiliateLink}} />
44-
<div class="text-xs text-slate-700 text-center">Get access to 40% off via @{{@model.affiliateLink.usernameForDisplay}}</div>
44+
<div class="text-xs text-slate-700 text-center">Get access to 40% off via @{{this.model.affiliateLink.affiliateName}}</div>
4545
</div>
4646

4747
<h2 class="text-2xl font-bold text-gray-900 md:text-3xl text-center mt-16">
@@ -56,7 +56,7 @@
5656

5757
<div class="flex flex-col gap-4 justify-center items-center mt-16">
5858
<AffiliateLinkPage::AcceptReferralButton @affiliateLink={{this.model.affiliateLink}} />
59-
<div class="text-xs text-slate-700 text-center">Get access to 40% off via @{{@model.affiliateLink.usernameForDisplay}}</div>
59+
<div class="text-xs text-slate-700 text-center">Get access to 40% off via @{{this.model.affiliateLink.affiliateName}}</div>
6060
</div>
6161
</div>
6262
</div>

mirage/factories/affiliate-link.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Factory } from 'miragejs';
22

33
export default Factory.extend({
4+
affiliateName: () => 'test',
5+
affiliateAvatarUrl: () => 'https://avatars.githubusercontent.com/u/1234567890?v=4',
46
url: () => `https://app.codecrafters.io/join?via=test`,
57
});

tests/acceptance/affiliate-link-page/accept-referral-offer-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ module('Acceptance | affiliate-link-page | accept-referral-offer', function (hoo
3434
signIn(this.owner, this.server);
3535

3636
const referrer = this.server.create('user', {
37-
avatarUrl: 'https://github.com/sarupbanskota.png',
37+
avatarUrl: 'https://avatars.githubusercontent.com/u/1234567890?v=4',
3838
createdAt: new Date(),
3939
githubUsername: 'sarupbanskota',
4040
username: 'sarupbanskota',
4141
});
4242

43-
this.server.create('affiliate-link', { user: referrer });
43+
this.server.create('affiliate-link', {
44+
user: referrer,
45+
affiliateName: 'sarupbanskota',
46+
affiliateAvatarUrl: 'https://avatars.githubusercontent.com/u/1234567890?v=4',
47+
});
4448

4549
await affiliateLinkPage.visit({ via: 'referral1' });
4650
await affiliateLinkPage.acceptReferralButtons[0].click();

0 commit comments

Comments
 (0)