From 2be0ddaca10e91f533c485be7e8d39553c32e5e1 Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Thu, 25 Apr 2024 18:17:13 +0530 Subject: [PATCH] fix billing info preview --- src/components/Profile.jsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/Profile.jsx b/src/components/Profile.jsx index ce92ec3..f14dd72 100644 --- a/src/components/Profile.jsx +++ b/src/components/Profile.jsx @@ -52,13 +52,23 @@ export function Profile({ user, logoutBtnHandler }) { window.db.getUserSubscriptionEvents(user.uid).then(events => { setIsFetchingSubscription(false); - const creationEvent = events + let creationEvent = events .filter( event => event.type === 'subscription_created' || event.type === 'order_created' ) - .sort((a, b) => b.timestamp.seconds - a.timestamp.seconds)[0]; + .sort((a, b) => b.timestamp.seconds - a.timestamp.seconds) + // remove order_created events which correspond to subscriptions (non lifetime orders) + .filter( + event => + !( + event.type === 'order_created' && + !event.data.data.attributes.first_order_item?.variant_name?.match( + /lifetime/ + ) + ) + )[0]; if (creationEvent) { console.log(creationEvent); creationEvent.attributes = creationEvent.data.data.attributes; @@ -82,7 +92,9 @@ export function Profile({ user, logoutBtnHandler }) { {' '} Web Maker PRO ( - {currentSubscription.attributes.first_order_item.variant_name} + {currentSubscription.attributes.variant_name || + currentSubscription.attributes.first_order_item + ?.variant_name} ) @@ -102,7 +114,7 @@ export function Profile({ user, logoutBtnHandler }) { ? 'Never ever' : getHumanReadableDate( currentSubscription.attributes.renews_at - )} + )}