fix(useBillingAndUsageData): fix invalid date

This commit is contained in:
Ali BARIN
2023-03-27 08:22:14 +00:00
parent 7066f7ea76
commit fd24dbee21

View File

@@ -7,7 +7,8 @@ import { GET_BILLING_AND_USAGE } from 'graphql/queries/get-billing-and-usage.ee'
function transform(billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn>) { function transform(billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn>) {
const nextBillDate = billingAndUsageData.subscription.nextBillDate; const nextBillDate = billingAndUsageData.subscription.nextBillDate;
const nextBillDateTitle = nextBillDate.title; const nextBillDateTitle = nextBillDate.title;
const relativeNextBillDateTitle = nextBillDateTitle ? DateTime.fromMillis(Number(nextBillDateTitle)).toFormat('LLL dd, yyyy') as string : ''; const nextBillDateTitleDateObject = DateTime.fromMillis(Number(nextBillDateTitle));
const formattedNextBillDateTitle = nextBillDateTitleDateObject.isValid ? nextBillDateTitleDateObject.toFormat('LLL dd, yyyy') : nextBillDateTitle;
return { return {
...billingAndUsageData, ...billingAndUsageData,
@@ -15,7 +16,7 @@ function transform(billingAndUsageData: NonNullable<UseBillingAndUsageDataReturn
...billingAndUsageData.subscription, ...billingAndUsageData.subscription,
nextBillDate: { nextBillDate: {
...billingAndUsageData.subscription.nextBillDate, ...billingAndUsageData.subscription.nextBillDate,
title: relativeNextBillDateTitle, title: formattedNextBillDateTitle,
} }
} }
}; };