diff --git a/packages/backend/src/graphql/queries/get-billing-and-usage.ee.ts b/packages/backend/src/graphql/queries/get-billing-and-usage.ee.ts index c766e71d..5e4cbe2d 100644 --- a/packages/backend/src/graphql/queries/get-billing-and-usage.ee.ts +++ b/packages/backend/src/graphql/queries/get-billing-and-usage.ee.ts @@ -5,13 +5,26 @@ import ExecutionStep from '../../models/execution-step'; import Subscription from '../../models/subscription.ee'; import { DateTime } from 'luxon'; +type BillingCardAction = { + type: string; + text: string; + src?: string | null; +}; + type ComputedSubscription = { - monthlyQuota: string; status: string; - nextBillDate: string; - nextBillAmount: string; - updateUrl: string; - cancelUrl: string; + monthlyQuota: { + title: string; + action: BillingCardAction; + }; + nextBillDate: { + title: string; + action: BillingCardAction; + }; + nextBillAmount: { + title: string; + action: BillingCardAction; + }; }; const getBillingAndUsage = async ( @@ -41,23 +54,52 @@ const paidSubscription = (subscription: Subscription): ComputedSubscription => { ); return { - monthlyQuota: currentPlan.limit, status: subscription.status, - nextBillDate: subscription.nextBillDate, - nextBillAmount: '€' + subscription.nextBillAmount, - updateUrl: subscription.updateUrl, - cancelUrl: subscription.cancelUrl, + monthlyQuota: { + title: currentPlan.limit, + action: { + type: 'link', + text: 'Change plan', + src: '/settings/billing/change-plan', + }, + }, + nextBillAmount: { + title: '€' + subscription.nextBillAmount, + action: { + type: 'link', + text: 'Update payment method', + src: subscription.updateUrl, + }, + }, + nextBillDate: { + title: subscription.nextBillDate, + action: { + type: 'text', + text: '(monthly payment)', + }, + }, }; }; const freeTrialSubscription = (): ComputedSubscription => { return { - monthlyQuota: 'Free trial', status: null, - nextBillDate: '---', - nextBillAmount: '---', - updateUrl: null, - cancelUrl: null, + monthlyQuota: { + title: 'Free Trial', + action: { + type: 'link', + text: 'Upgrade plan', + src: '/settings/billing/upgrade', + }, + }, + nextBillAmount: { + title: '---', + action: null, + }, + nextBillDate: { + title: '---', + action: null, + }, }; }; diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 41d8cb1e..4dec2ecc 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -479,13 +479,32 @@ type GetBillingAndUsage { usage: Usage } +type MonthlyQuota { + title: String + action: BillingCardAction +} + +type NextBillAmount { + title: String + action: BillingCardAction +} + +type NextBillDate { + title: String + action: BillingCardAction +} + +type BillingCardAction { + type: String + text: String + src: String +} + type Subscription { - monthlyQuota: String - updateUrl: String - cancelUrl: String status: String - nextBillAmount: String - nextBillDate: String + monthlyQuota: MonthlyQuota + nextBillAmount: NextBillAmount + nextBillDate: NextBillDate } type Usage {