Skip to content

Commit

Permalink
refactor: simplify file structure and add conifg file
Browse files Browse the repository at this point in the history
  • Loading branch information
xn1cklas committed Sep 8, 2024
1 parent fa5f19e commit b967d3a
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/app/actions/checkout.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
"use server";

import { polar } from "@/utils/polar-client";
import { polar } from "@/lib/polar/polar-client";
import { redirect } from "next/navigation";
import { productConfig } from "@/lib/config";

export async function checkout({
productPriceId,
successUrl,
}: {
productPriceId: string | undefined;
successUrl: string;
}) {
"use server";

if (!productPriceId) {
redirect(successUrl);
redirect(productConfig.successUrl);
}

const result = await polar.checkouts.create({
productPriceId: productPriceId,
successUrl: successUrl,
successUrl: productConfig.successUrl,
});

if (result.url) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchProducts } from "@/components/fetch-products";
import { fetchProducts } from "@/lib/fetch-products";
import { Pricing } from "@/components/Pricing";

export default async function Page() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrandingMenu } from "@/components/BrandingMenu";
import { BrandingMenu } from "@/components/Brand/BrandingMenu";
import Link from "next/link";

export const Header = () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/Pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ function ProductCard({
action={() =>
checkout({
productPriceId: priceId,
successUrl: "localhost:3000",
})
}
>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const productConfig = {
successUrl: "localhost:3000",
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { polar } from "@/utils/polar-client";
import { polar } from "@/lib/polar/polar-client";
import { ProductOutput } from "@polar-sh/sdk/models/components";

export async function fetchProducts(): Promise<ProductOutput[]> {
Expand Down
File renamed without changes.

0 comments on commit b967d3a

Please sign in to comment.