🧑‍💻 Use static pricing data (#1275)

This commit is contained in:
Luke Vella 2024-08-25 13:00:03 +01:00 committed by GitHub
parent 2474888b14
commit 08d6d00e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 30 additions and 42 deletions

View file

@ -65,8 +65,6 @@ jobs:
- name: Create production build - name: Create production build
run: yarn turbo build:test --filter=@rallly/web run: yarn turbo build:test --filter=@rallly/web
env:
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
- name: Start services - name: Start services
run: yarn docker:up run: yarn docker:up

View file

@ -1,5 +1,4 @@
import type { PricingData } from "@rallly/billing"; import { pricingData } from "@rallly/billing/pricing";
import { getProPricing } from "@rallly/billing";
import { Badge } from "@rallly/ui/badge"; import { Badge } from "@rallly/ui/badge";
import { import {
BillingPlan, BillingPlan,
@ -49,7 +48,20 @@ export const UpgradeButton = ({
); );
}; };
const PriceTables = ({ pricingData }: { pricingData: PricingData }) => { const PriceTables = ({
pricingData,
}: {
pricingData: {
monthly: {
amount: number;
currency: string;
};
yearly: {
amount: number;
currency: string;
};
};
}) => {
const [tab, setTab] = React.useState("yearly"); const [tab, setTab] = React.useState("yearly");
return ( return (
<Tabs value={tab} onValueChange={setTab}> <Tabs value={tab} onValueChange={setTab}>
@ -278,9 +290,7 @@ const FAQ = () => {
); );
}; };
const Page: NextPageWithLayout<{ pricingData: PricingData }> = ({ const Page: NextPageWithLayout = () => {
pricingData,
}) => {
const { t } = useTranslation(["pricing"]); const { t } = useTranslation(["pricing"]);
return ( return (
<div className="mx-auto max-w-3xl"> <div className="mx-auto max-w-3xl">
@ -332,13 +342,11 @@ Page.getLayout = getPageLayout;
export default Page; export default Page;
export const getStaticProps: GetStaticProps = async (ctx) => { export const getStaticProps: GetStaticProps = async (ctx) => {
const pricingData = await getProPricing();
const res = await getStaticTranslations(["pricing"])(ctx); const res = await getStaticTranslations(["pricing"])(ctx);
if ("props" in res) { if ("props" in res) {
return { return {
props: { props: {
...res.props, ...res.props,
pricingData,
}, },
}; };
} }

View file

@ -19,12 +19,10 @@ import { UpgradeButton } from "@/components/upgrade-button";
export type PricingData = { export type PricingData = {
monthly: { monthly: {
id: string;
amount: number; amount: number;
currency: string; currency: string;
}; };
yearly: { yearly: {
id: string;
amount: number; amount: number;
currency: string; currency: string;
}; };

View file

@ -1,5 +1,4 @@
import { getProPricing } from "@rallly/billing"; import { pricingData } from "@rallly/billing/pricing";
import { unstable_cache } from "next/cache";
import { notFound } from "next/navigation"; import { notFound } from "next/navigation";
import { BillingPage } from "@/app/[locale]/(admin)/settings/billing/billing-page"; import { BillingPage } from "@/app/[locale]/(admin)/settings/billing/billing-page";
@ -7,14 +6,11 @@ import { Params } from "@/app/[locale]/types";
import { getTranslation } from "@/app/i18n"; import { getTranslation } from "@/app/i18n";
import { env } from "@/env"; import { env } from "@/env";
const getCachedProPricing = unstable_cache(getProPricing, ["pricing-data"]);
export default async function Page() { export default async function Page() {
if (env.NEXT_PUBLIC_SELF_HOSTED === "true") { if (env.NEXT_PUBLIC_SELF_HOSTED === "true") {
notFound(); notFound();
} }
const prices = await getCachedProPricing(); return <BillingPage pricingData={pricingData} />;
return <BillingPage pricingData={prices} />;
} }
export async function generateMetadata({ params }: { params: Params }) { export async function generateMetadata({ params }: { params: Params }) {

View file

@ -5,7 +5,8 @@
"exports": { "exports": {
"./server/*": "./src/server/*.tsx", "./server/*": "./src/server/*.tsx",
"./next": "./src/next/index.ts", "./next": "./src/next/index.ts",
".": "./src/index.ts" ".": "./src/index.ts",
"./*": "./src/*.ts"
}, },
"scripts": { "scripts": {
"normalize-subscription-metadata": "dotenv -e ../../.env -- tsx ./src/scripts/normalize-metadata.ts" "normalize-subscription-metadata": "dotenv -e ../../.env -- tsx ./src/scripts/normalize-metadata.ts"

View file

@ -1,23 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
import { getPricing } from "../lib/get-pricing";
export async function GET(
request: NextRequest,
{
params,
}: {
params: {
method: string;
};
},
) {
switch (params.method) {
case "pricing":
const data = await getPricing();
return NextResponse.json(data);
default:
return NextResponse.json({ message: "Method not found" });
}
}
export const handlers = { GET };

View file

@ -0,0 +1,10 @@
export const pricingData = {
monthly: {
amount: 700,
currency: "usd",
},
yearly: {
amount: 5600,
currency: "usd",
},
};