-
Notifications
You must be signed in to change notification settings - Fork 18
Add a billing tab to the settings #2811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Arpan-206
wants to merge
31
commits into
main
Choose a base branch
from
arpan/cc-1703-revamp-membership-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
f0cd0b9
Add a billing tab to the settings
Arpan-206 22a50d9
ofc I forgot about the linter
Arpan-206 fdf9480
most tests are working
Arpan-206 7646797
tests are working and are extensive
Arpan-206 ef59d5a
making the linter a little less upset
Arpan-206 d2a4e06
[percy] Let's check what this means
Arpan-206 a744efb
Remove /membership (test, templates etc), also redirect to billing
Arpan-206 b8e5abe
Rabbit suggestion + Linter
Arpan-206 4586692
Minor fix to the test
Arpan-206 492ea65
Bring back the pay thing
Arpan-206 28c49d4
maintain consistancy
Arpan-206 80fd584
Move the Container inwards and input user as a whole
Arpan-206 54847e9
Pauls' changes
Arpan-206 fc9bfe3
[percy] forgot this
Arpan-206 ff65f50
[percy] linter?
Arpan-206 a23e813
Switch back to convention
Arpan-206 5e42545
remove .settled calls which are unnecessary
Arpan-206 e44227a
addressed comments except VIP
Arpan-206 2324df5
Show VIP + Active
Arpan-206 f387a3b
[percy] forgot this
Arpan-206 31426ec
[percy] linter too
Arpan-206 c370b91
Added Dark Methods
Arpan-206 0fb27af
linter ffs
Arpan-206 5fa3c1a
Duplicate selectors again
Arpan-206 96700ab
Added test for email client
Arpan-206 324665f
[percy] addressed comments
Arpan-206 bd80766
[percy] Update the dot to be just a dot
Arpan-206 ac350c2
Update app/components/settings/billing-page/payment-history-section.ts
Arpan-206 bc73fba
Addressed Paul's Comments
Arpan-206 547b45b
[percy] linter + other minor changes
Arpan-206 263cab5
[percy] removed active plan one
Arpan-206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/components/settings/billing-page/membership-section.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{{#if @user.isVip}} | ||
<div | ||
class="inline-flex items-center gap-2 rounded-full bg-teal-50 px-2 py-1 border border-teal-500 has-active-plan has-vip-access" | ||
data-test-membership-section | ||
> | ||
<StaticDot @color="green" @size="large" /> | ||
<div class="text-teal-500 font-semibold uppercase text-sm"> | ||
VIP Access | ||
</div> | ||
</div> | ||
|
||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-2"> | ||
<p> | ||
{{#if @user.vipStatusExpiresAt}} | ||
🎉 You have VIP access to all CodeCrafters content, valid until | ||
<b class="font-semibold">{{date-format @user.vipStatusExpiresAt format="PPPp"}}</b>. | ||
{{else}} | ||
🎉 You have VIP access to all CodeCrafters content. | ||
{{/if}} | ||
</p> | ||
</div> | ||
{{else if @user.hasActiveSubscription}} | ||
<div class="inline-flex items-center gap-2 rounded-full bg-teal-50 px-2 py-1 border border-teal-500 has-active-plan" data-test-membership-section> | ||
<StaticDot @color="green" @size="large" /> | ||
<div class="text-teal-500 font-semibold uppercase text-sm"> | ||
Membership active | ||
</div> | ||
</div> | ||
|
||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-2"> | ||
{{#if @user.activeSubscription.cancelAt}} | ||
<p class="mb-3"> | ||
Your CodeCrafters membership is valid until | ||
<b class="font-semibold">{{date-format @user.activeSubscription.cancelAt format="PPPp"}}</b>. | ||
</p> | ||
<p>Your membership doesn't renew automatically. To restart your membership, make a new one-time payment.</p> | ||
{{else}} | ||
<p> | ||
You are currently subscribed to the | ||
<b class="font-semibold">{{@user.activeSubscription.pricingPlanName}}</b> | ||
plan. | ||
</p> | ||
{{/if}} | ||
</div> | ||
{{else if @user.expiredSubscription}} | ||
<div class="inline-flex items-center gap-2 rounded-full bg-red-50 px-2 py-1 border border-red-500" data-test-membership-section> | ||
<StaticDot @color="red" @size="large" /> | ||
<div class="text-red-500 font-semibold uppercase text-sm"> | ||
Membership inactive | ||
</div> | ||
</div> | ||
|
||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-2"> | ||
<p> | ||
Your CodeCrafters membership is | ||
<b class="text-red-600 font-semibold">currently inactive</b>. | ||
</p> | ||
<p> | ||
Start a new membership to get access to | ||
<a href="https://docs.codecrafters.io/membership" target="_blank" rel="noopener noreferrer">membership benefits</a>. | ||
</p> | ||
</div> | ||
<PrimaryLinkButton @size="small" @route="pay" class="mt-3"> | ||
Start membership → | ||
</PrimaryLinkButton> | ||
{{else}} | ||
<div class="inline-flex items-center gap-2 rounded-full bg-yellow-50 px-2 py-1 border border-yellow-500" data-test-membership-section> | ||
<StaticDot @color="yellow" @size="large" /> | ||
<div class="text-yellow-500 font-semibold uppercase text-sm"> | ||
No membership found | ||
</div> | ||
</div> | ||
|
||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-2"> | ||
<p> | ||
You don't have a CodeCrafters membership. Start one to get access to | ||
<a href="https://docs.codecrafters.io/membership" target="_blank" rel="noopener noreferrer">membership benefits</a>. | ||
</p> | ||
</div> | ||
<PrimaryLinkButton @size="small" @route="pay" class="mt-3"> | ||
Start membership → | ||
</PrimaryLinkButton> | ||
{{/if}} |
18 changes: 18 additions & 0 deletions
18
app/components/settings/billing-page/membership-section.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Component from '@glimmer/component'; | ||
import type UserModel from 'codecrafters-frontend/models/user'; | ||
|
||
interface Signature { | ||
Element: HTMLDivElement; | ||
|
||
Args: { | ||
user: UserModel; | ||
}; | ||
} | ||
|
||
export default class MembershipSectionComponent extends Component<Signature> {} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
'Settings::BillingPage::MembershipSection': typeof MembershipSectionComponent; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/components/settings/billing-page/payment-history-section.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{#if (gt @charges.length 0)}} | ||
<div class="grid grid-cols-3 gap-y-3" data-test-payment-history-section> | ||
|
||
<div class="border-b pb-2 text-gray-500 text-sm">Date</div> | ||
<div class="border-b pb-2 text-gray-500 text-sm text-right">Amount</div> | ||
<div class="border-b pb-2"></div> | ||
|
||
{{#each @charges as |charge|}} | ||
<div class="text-gray-600 text-sm"> | ||
{{date-format charge.createdAt format="PPP"}} | ||
</div> | ||
<div class="{{if charge.statusIsFailed 'text-red-600' 'text-gray-600'}} text-sm text-right" data-test-payment-history-item> | ||
<span class="font-semibold" data-test-amount>{{charge.displayString}}</span> | ||
{{#if (gt charge.amountRefunded 0)}} | ||
{{#if charge.isFullyRefunded}} | ||
<span class="text-red-600" data-test-refund-text>(refunded)</span> | ||
{{else}} | ||
<span class="text-red-600" data-test-refund-text>(<span class="font-semibold">{{charge.refundedAmountDisplayString}}</span> | ||
refunded)</span> | ||
{{/if}} | ||
{{/if}} | ||
</div> | ||
<div class="flex items-center justify-end"> | ||
{{#if (and charge.invoiceId charge.statusIsSucceeded)}} | ||
<a | ||
href={{charge.invoiceDownloadUrl}} | ||
target="_blank" | ||
class="text-teal-500 hover:text-teal-600 font-semibold text-sm" | ||
data-test-status | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data-test-download-invoice-link | ||
rel="noopener noreferrer" | ||
> | ||
Download Invoice | ||
</a> | ||
{{else if charge.statusIsFailed}} | ||
<span class="text-gray-600 text-sm" data-test-status>Payment failed</span> | ||
{{/if}} | ||
</div> | ||
{{/each}} | ||
</div> | ||
{{else}} | ||
<div class="text-gray-700 is-empty" data-test-payment-history-section data-test-empty-state> | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
No payment history found. | ||
</div> | ||
{{/if}} |
18 changes: 18 additions & 0 deletions
18
app/components/settings/billing-page/payment-history-section.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Component from '@glimmer/component'; | ||
import type ChargeModel from 'codecrafters-frontend/models/charge'; | ||
|
||
interface Signature { | ||
Element: HTMLDivElement; | ||
|
||
Args: { | ||
charges: ChargeModel[]; | ||
}; | ||
} | ||
|
||
export default class PaymentHistorySectionComponent extends Component<Signature> {} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
'Settings::BillingPage::PaymentHistorySection': typeof PaymentHistorySectionComponent; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="inline-flex items-center gap-2 rounded-full bg-gray-50 px-2 py-1 border border-gray-300"> | ||
<StaticDot @color="gray" @size="large" /> | ||
<div class="text-gray-400 font-semibold uppercase text-sm"> | ||
Auto-renew disabled | ||
</div> | ||
</div> | ||
|
||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-2"> | ||
Your membership does not renew automatically. Once your membership expires, you'll be able to make a new one-time payment. | ||
</div> | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface Signature { | ||
Element: HTMLDivElement; | ||
} | ||
|
||
export default class RenewalSectionComponent extends Component<Signature> {} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
'Settings::BillingPage::RenewalSection': typeof RenewalSectionComponent; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<a href="mailto:hello@codecrafters.io?subject=Billing help (account: {{@username}})" class="inline-block rounded" data-test-support-section> | ||
<PrimaryButton @size="small" data-test-support-contact-button> | ||
Get help | ||
</PrimaryButton> | ||
</a> | ||
<div class="text-gray-500 dark:text-gray-400 text-xs mt-3"> | ||
<p> | ||
Questions? Click the button above or write to us at | ||
<a href="mailto:hello@codecrafters.io" class="underline text-blue-500 dark:text-blue-400">hello@codecrafters.io</a> | ||
and we'll help sort things out. | ||
</p> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface Signature { | ||
Element: HTMLDivElement; | ||
|
||
Args: { | ||
username: string; | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
|
||
export default class SupportSectionComponent extends Component<Signature> {} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
'Settings::BillingPage::SupportSection': typeof SupportSectionComponent; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Controller from '@ember/controller'; | ||
import type ChargeModel from 'codecrafters-frontend/models/charge'; | ||
import type { ModelType as SettingsModelType } from 'codecrafters-frontend/routes/settings'; | ||
|
||
interface BillingModelType extends SettingsModelType { | ||
charges: ChargeModel[]; | ||
} | ||
|
||
export default class BillingController extends Controller { | ||
declare model: BillingModelType; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Route from '@ember/routing/route'; | ||
import type ChargeModel from 'codecrafters-frontend/models/charge'; | ||
import { inject as service } from '@ember/service'; | ||
import type Store from '@ember-data/store'; | ||
import type { ModelType as SettingsModelType } from 'codecrafters-frontend/routes/settings'; | ||
|
||
interface BillingModelType extends SettingsModelType { | ||
charges: ChargeModel[]; | ||
} | ||
|
||
export default class BillingRoute extends Route { | ||
@service declare store: Store; | ||
|
||
async model(): Promise<BillingModelType> { | ||
const user = this.modelFor('settings') as SettingsModelType; | ||
let charges; | ||
|
||
try { | ||
charges = await this.store.query('charge', { | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filter: { user_id: user.user.id }, | ||
}); | ||
} catch (error) { | ||
console.error('Failed to fetch charges:', error); | ||
charges = []; | ||
} | ||
|
||
return { | ||
user: user.user, | ||
charges: charges.toArray(), | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{! template-lint-disable no-implicit-this }} | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Settings::FormSection @title="Membership" @description="Your CodeCrafters membership details"> | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Settings::BillingPage::MembershipSection @user={{this.model.user}} /> | ||
</Settings::FormSection> | ||
|
||
<Settings::FormDivider /> | ||
|
||
<Settings::FormSection @title="Renewal" @description="Details of your upcoming payment"> | ||
<Settings::BillingPage::RenewalSection /> | ||
</Settings::FormSection> | ||
Arpan-206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<Settings::FormDivider /> | ||
|
||
<Settings::FormSection @title="Support" @description="How to get help with billing"> | ||
<Settings::BillingPage::SupportSection @username={{this.model.user.username}} /> | ||
</Settings::FormSection> | ||
|
||
<Settings::FormDivider /> | ||
|
||
<Settings::FormSection @title="Payment history" @description="Details of your previous payments"> | ||
{{#let this.model.charges as |charges|}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arpan-206 this is something we haven't used before, why is the |
||
<Settings::BillingPage::PaymentHistorySection @charges={{charges}} /> | ||
{{/let}} | ||
</Settings::FormSection> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arpan-206 make sure to review and remove unrelated changes from a PR - we usually do keep empty lines between blocks where indentation changes for readability