💄 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

@ -1,4 +1,8 @@
import { trpc } from "@rallly/backend";
import { Badge } from "@rallly/ui/badge";
import React from "react";
import { Trans } from "@/components/trans";
export const usePlan = () => {
const { data } = trpc.user.subscription.useQuery();
@ -7,3 +11,32 @@ export const usePlan = () => {
return isPaid ? "paid" : "free";
};
export const IfSubscribed = ({ children }: React.PropsWithChildren) => {
const plan = usePlan();
return plan === "paid" ? <>{children}</> : null;
};
export const IfFreeUser = ({ children }: React.PropsWithChildren) => {
const plan = usePlan();
return plan === "free" ? <>{children}</> : null;
};
export const Plan = () => {
const plan = usePlan();
if (plan === "paid") {
return (
<Badge>
<Trans i18nKey="planPro" defaults="Pro" />
</Badge>
);
}
return (
<Badge variant="secondary">
<Trans i18nKey="planFree" defaults="Free" />
</Badge>
);
};