feat: Billing page redesign plus credits (#23908)

* manage billing section

* wip billing credits

* WIP

* WIP

* Download expense log

* credit worth

* skeleton fixes

* add org tip

* add teams tip

* restore service

* type check

* type check

* fix types

* additional credits

* fix progress bar

* add dashed prop

* match new designs

* hide area with no monthly credits

* fix i18n

* show current balance label

* Update apps/web/modules/settings/billing/billing-view.tsx

Co-authored-by: Carina Wollendorfer <[email protected]>

* spacing + monthly credits not showing additional

* Remove additional credits from monthly calculations

* feat: replace add members redirect with invite modal in billing settings

- Replace Button href with onClick handler to open MemberInvitationModal
- Add MemberInvitationModalWithoutMembers import and state management
- Maintain existing team/org context support
- Follow established modal usage patterns from other components
- Fix lint error by using undefined instead of empty arrow function

Co-Authored-By: [email protected] <[email protected]>

* Remove redudant vars from method

* fix type check

---------

Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-09-19 16:18:42 +00:00
1 parent b407be933d
commit cfeb18de3f
7 files changed
+356 -191

No files matched your search

@@ -59,14 +59,16 @@ vi.mock("@calcom/lib/server/repository/membership");
vi.mock("@calcom/lib/server/repository/team");
vi.mock("@calcom/emails/email-manager");
vi.mock("../workflows/lib/reminders/reminderScheduler", () => ({
cancelScheduledMessagesAndScheduleEmails: vi.fn(),
cancelScheduledMessagesAndScheduleEmails: vi.fn().mockResolvedValue(undefined),
}));
const creditService = new CreditService();
vi.spyOn(creditService, "_getAllCreditsForTeam").mockResolvedValue({
totalMonthlyCredits: 10,
totalRemainingMonthlyCredits: 5,
additionalCredits: 0,
totalCreditsUsedThisMonth: 5,
});
vi.spyOn(creditService, "_getTeamWithAvailableCredits").mockResolvedValue({
@@ -233,6 +235,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 20,
additionalCredits: 60,
totalCreditsUsedThisMonth: 480,
});
await creditService.chargeCredits({
@@ -291,6 +294,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: -1,
additionalCredits: 0,
totalCreditsUsedThisMonth: 501,
});
await creditService.chargeCredits({
@@ -321,6 +325,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 100,
additionalCredits: 50,
totalCreditsUsedThisMonth: 400,
});
const result = await creditService.getUserOrTeamToCharge({
@@ -340,6 +345,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 0,
additionalCredits: 50,
totalCreditsUsedThisMonth: 500,
});
const result = await creditService.getUserOrTeamToCharge({
@@ -483,13 +489,18 @@ describe("CreditService", () => {
describe("getAllCreditsForTeam", () => {
it("should calculate total and remaining credits correctly", async () => {
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs).mockResolvedValue({
additionalCredits: 100,
expenseLogs: [
{ credits: 50, date: new Date() },
{ credits: 30, date: new Date() },
],
});
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs)
.mockResolvedValueOnce({
additionalCredits: 100,
expenseLogs: [
{ credits: 50, date: new Date() },
{ credits: 30, date: new Date() },
],
})
.mockResolvedValueOnce({
additionalCredits: 100,
expenseLogs: [{ credits: 80, date: new Date() }],
});
vi.spyOn(CreditService.prototype, "getMonthlyCredits").mockResolvedValue(500);
@@ -498,14 +509,20 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 420, // 500 - (50 + 30)
additionalCredits: 100,
totalCreditsUsedThisMonth: 80, // 50 + 30
});
});
it("should handle no expense logs", async () => {
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs).mockResolvedValue({
additionalCredits: 100,
expenseLogs: [],
});
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs)
.mockResolvedValueOnce({
additionalCredits: 100,
expenseLogs: [],
})
.mockResolvedValueOnce({
additionalCredits: 100,
expenseLogs: [],
});
vi.spyOn(CreditService.prototype, "getMonthlyCredits").mockResolvedValue(500);
@@ -514,6 +531,57 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 500,
additionalCredits: 100,
totalCreditsUsedThisMonth: 0, // no expenses
});
});
it("should calculate total credits including additional credits for the month", async () => {
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs)
.mockResolvedValueOnce({
additionalCredits: 150,
expenseLogs: [
{ credits: 80, date: new Date() },
{ credits: 40, date: new Date() },
],
})
.mockResolvedValueOnce({
additionalCredits: 150,
expenseLogs: [
{ credits: 25, date: new Date() },
{ credits: 15, date: new Date() },
],
});
vi.spyOn(CreditService.prototype, "getMonthlyCredits").mockResolvedValue(500);
const result = await creditService.getAllCreditsForTeam(1);
expect(result).toEqual({
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 380, // 500 - (80 + 40)
additionalCredits: 150,
totalCreditsUsedThisMonth: 120, // 80 + 40
});
});
it("should handle zero additional credits", async () => {
vi.mocked(CreditsRepository.findCreditBalanceWithExpenseLogs)
.mockResolvedValueOnce({
additionalCredits: 0,
expenseLogs: [{ credits: 100, date: new Date() }],
})
.mockResolvedValueOnce({
additionalCredits: 0,
expenseLogs: [],
});
vi.spyOn(CreditService.prototype, "getMonthlyCredits").mockResolvedValue(500);
const result = await creditService.getAllCreditsForTeam(1);
expect(result).toEqual({
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 400, // 500 - 100
additionalCredits: 0,
totalCreditsUsedThisMonth: 100,
});
});
});
@@ -704,6 +772,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 200,
additionalCredits: 100,
totalCreditsUsedThisMonth: 300,
});
const result = await creditService.getTeamWithAvailableCredits(1);
expect(result).toEqual({
@@ -827,6 +896,7 @@ describe("CreditService", () => {
totalMonthlyCredits: 500,
totalRemainingMonthlyCredits: 100,
additionalCredits: 100,
totalCreditsUsedThisMonth: 400,
});
await creditService.chargeCredits({
@@ -651,6 +651,7 @@ export class CreditService {
totalMonthlyCredits: 0,
totalRemainingMonthlyCredits: 0,
additionalCredits: creditBalance?.additionalCredits ?? 0,
totalCreditsUsedThisMonth: 0,
};
}
@@ -658,6 +659,7 @@ export class CreditService {
totalMonthlyCredits: 0,
totalRemainingMonthlyCredits: 0,
additionalCredits: 0,
totalCreditsUsedThisMonth: 0,
};
}
@@ -677,10 +679,14 @@ export class CreditService {
const totalMonthlyCreditsUsed =
creditBalance?.expenseLogs.reduce((sum, log) => sum + (log?.credits ?? 0), 0) || 0;
const additionalCredits = creditBalance?.additionalCredits ?? 0;
const totalCreditsUsedThisMonth = totalMonthlyCreditsUsed;
return {
totalMonthlyCredits,
totalRemainingMonthlyCredits: Math.max(totalMonthlyCredits - totalMonthlyCreditsUsed, 0),
additionalCredits: creditBalance?.additionalCredits ?? 0,
additionalCredits,
totalCreditsUsedThisMonth,
};
}
}