💄 Update billing page and refine ui components (#830)

This commit is contained in:
Luke Vella 2023-08-29 17:29:26 +01:00 committed by GitHub
parent 1b100481a0
commit d261ef0d59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 321 additions and 238 deletions

View file

@ -20,16 +20,18 @@ export const user = router({
},
});
}),
subscription: possiblyPublicProcedure.query(async ({ ctx }) => {
if (ctx.user.isGuest) {
// guest user can't have an active subscription
return {
active: false,
};
}
subscription: possiblyPublicProcedure.query(
async ({ ctx }): Promise<{ legacy?: boolean; active: boolean }> => {
if (ctx.user.isGuest) {
// guest user can't have an active subscription
return {
active: false,
};
}
return await getSubscriptionStatus(ctx.user.id);
}),
return await getSubscriptionStatus(ctx.user.id);
},
),
changeName: privateProcedure
.input(
z.object({

View file

@ -9,6 +9,7 @@ export const getSubscriptionStatus = async (userId: string) => {
subscription: {
select: {
active: true,
periodEnd: true,
},
},
},
@ -17,6 +18,7 @@ export const getSubscriptionStatus = async (userId: string) => {
if (user?.subscription?.active === true) {
return {
active: true,
expiresAt: user.subscription.periodEnd,
};
}
@ -27,6 +29,9 @@ export const getSubscriptionStatus = async (userId: string) => {
gt: new Date(),
},
},
select: {
endDate: true,
},
});
if (
@ -36,6 +41,7 @@ export const getSubscriptionStatus = async (userId: string) => {
return {
active: true,
legacy: true,
expiresAt: userPaymentData.endDate,
};
}