Skip to content

Commit 05bf1ac

Browse files
Filter polar products (#116)
* feat: filter polar products by id and sort by price amount * chore: remove commented code * Update src/lib/polar/productIds.ts Co-authored-by: hobbescodes <[email protected]> * refactor(products): update whitelisted product IDs * chore: remove spread operator for product list ids --------- Co-authored-by: hobbescodes <[email protected]>
1 parent c0112b1 commit 05bf1ac

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/app/pricing/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { redirect } from "next/navigation";
33
import { auth } from "auth";
44
import { PricingOverview } from "components/pricing";
55
import { app } from "lib/config";
6-
import { polar } from "lib/polar";
6+
import { BACKFEED_PRODUCT_IDS, polar } from "lib/polar";
77

88
export const dynamic = "force-dynamic";
99

@@ -23,9 +23,8 @@ const PricingPage = async () => {
2323
] = await Promise.all([
2424
auth(),
2525
polar.products.list({
26-
isArchived: false,
27-
// ! NB: important that the product name includes this query string (i.e. Backfeed)
28-
query: app.name,
26+
id: BACKFEED_PRODUCT_IDS,
27+
sorting: ["price_amount"],
2928
}),
3029
]);
3130

src/components/pricing/PricingOverview/PricingOverview.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { app } from "lib/config";
2020
import { useSearchParams } from "lib/hooks";
2121

2222
import type { Product } from "@polar-sh/sdk/models/components/product";
23-
import type { ProductPriceFixed } from "@polar-sh/sdk/models/components/productpricefixed";
2423

2524
interface Props {
2625
/** The products available for pricing tiers. */
@@ -35,14 +34,7 @@ const PricingOverview = ({ products }: Props) => {
3534

3635
const filteredProducts = useMemo(
3736
() =>
38-
products
39-
.filter((product) => product.recurringInterval === pricingModel)
40-
// ! NB: this sort function is limited. Prices must fall in the `fixed` price type. May need to adjust accordingly in the future.
41-
.sort(
42-
(a, b) =>
43-
(a.prices[0] as ProductPriceFixed).priceAmount -
44-
(b.prices[0] as ProductPriceFixed).priceAmount,
45-
),
37+
products.filter((product) => product.recurringInterval === pricingModel),
4638
[products, pricingModel],
4739
);
4840

src/lib/polar/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as polar } from "./polar";
2+
export { default as BACKFEED_PRODUCT_IDS } from "./productIds";

src/lib/polar/productIds.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const BACKFEED_PRODUCT_IDS: string[] = [
2+
"9fdf9d78-f4f7-4222-93ed-55ae60d996e4", // Backfeed Basic (Monthly) sandbox
3+
"9a135ea6-5e7c-448b-8070-a5534ae72d93", // Backfeed Basic (Yearly) sandbox
4+
"51eaf279-48b4-422a-939f-046cb299655d", // Backfeed Team (Monthly) sandbox
5+
"2479fd7f-03b3-4965-9887-e701e8e18e14", // Backfeed Team (Yearly) sandbox
6+
"3776b994-1c73-4869-afef-f34a2ca68181", // Backfeed Enterprise (Monthly) sandbox
7+
"48d27c97-50da-441b-ba44-d90b8c2d60b3", // Backfeed Enterprise (Yearly) sandbox
8+
"768e1aee-fc38-46fa-91d9-1c15b71375dd", // Backfeed Basic (Monthly) prod
9+
"a35183cc-5223-4e64-852c-a291a6f52222", // Backfeed Basic (Yearly) prod
10+
"b1f48ae5-0de4-416e-9b16-39b3f01372b6", // Backfeed Team (Monthly) prod
11+
"39e6bf3d-0aef-4fe0-abdb-243af14b010f", // Backfeed Team (Yearly) prod
12+
"7e2bd7d7-6a43-4c0d-8545-c59d2fabd598", // Backfeed Enterprise (Monthly) prod
13+
"51906ba1-b6a9-43c9-83ee-f2fe399a792f", // Backfeed Enterprise (Yearly) prod
14+
] as const;
15+
16+
export default BACKFEED_PRODUCT_IDS;

0 commit comments

Comments
 (0)