chore: Adjust billing query to be more dynamic

This commit is contained in:
Faruk AYDIN
2023-03-26 18:22:49 +03:00
parent 4aadcb021e
commit 05505704e4
2 changed files with 81 additions and 20 deletions

View File

@@ -5,13 +5,26 @@ import ExecutionStep from '../../models/execution-step';
import Subscription from '../../models/subscription.ee'; import Subscription from '../../models/subscription.ee';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
type BillingCardAction = {
type: string;
text: string;
src?: string | null;
};
type ComputedSubscription = { type ComputedSubscription = {
monthlyQuota: string;
status: string; status: string;
nextBillDate: string; monthlyQuota: {
nextBillAmount: string; title: string;
updateUrl: string; action: BillingCardAction;
cancelUrl: string; };
nextBillDate: {
title: string;
action: BillingCardAction;
};
nextBillAmount: {
title: string;
action: BillingCardAction;
};
}; };
const getBillingAndUsage = async ( const getBillingAndUsage = async (
@@ -41,23 +54,52 @@ const paidSubscription = (subscription: Subscription): ComputedSubscription => {
); );
return { return {
monthlyQuota: currentPlan.limit,
status: subscription.status, status: subscription.status,
nextBillDate: subscription.nextBillDate, monthlyQuota: {
nextBillAmount: '€' + subscription.nextBillAmount, title: currentPlan.limit,
updateUrl: subscription.updateUrl, action: {
cancelUrl: subscription.cancelUrl, 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 => { const freeTrialSubscription = (): ComputedSubscription => {
return { return {
monthlyQuota: 'Free trial',
status: null, status: null,
nextBillDate: '---', monthlyQuota: {
nextBillAmount: '---', title: 'Free Trial',
updateUrl: null, action: {
cancelUrl: null, type: 'link',
text: 'Upgrade plan',
src: '/settings/billing/upgrade',
},
},
nextBillAmount: {
title: '---',
action: null,
},
nextBillDate: {
title: '---',
action: null,
},
}; };
}; };

View File

@@ -479,13 +479,32 @@ type GetBillingAndUsage {
usage: Usage 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 { type Subscription {
monthlyQuota: String
updateUrl: String
cancelUrl: String
status: String status: String
nextBillAmount: String monthlyQuota: MonthlyQuota
nextBillDate: String nextBillAmount: NextBillAmount
nextBillDate: NextBillDate
} }
type Usage { type Usage {