mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 18:56:39 +00:00
♻️refactor
This commit is contained in:
@@ -17,6 +17,7 @@ import { GetOrgTierResponse } from "@server/routers/billing/types";
|
|||||||
import { getCachedSubscription } from "@app/lib/api/getCachedSubscription";
|
import { getCachedSubscription } from "@app/lib/api/getCachedSubscription";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { TierId } from "@server/lib/billing/tiers";
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
|
import { isSubscribed } from "@app/lib/api/getSubscriptionStatus";
|
||||||
|
|
||||||
type GeneralSettingsProps = {
|
type GeneralSettingsProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -51,16 +52,6 @@ export default async function GeneralSettingsPage({
|
|||||||
redirect(`/${orgId}`);
|
redirect(`/${orgId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let subscriptionStatus: GetOrgTierResponse | null = null;
|
|
||||||
try {
|
|
||||||
const subRes = await getCachedSubscription(orgId);
|
|
||||||
subscriptionStatus = subRes.data.data;
|
|
||||||
} catch {}
|
|
||||||
const subscribed =
|
|
||||||
build === "enterprise"
|
|
||||||
? true
|
|
||||||
: subscriptionStatus?.tier === TierId.STANDARD;
|
|
||||||
|
|
||||||
const t = await getTranslations();
|
const t = await getTranslations();
|
||||||
|
|
||||||
const navItems: TabItem[] = [
|
const navItems: TabItem[] = [
|
||||||
@@ -70,7 +61,7 @@ export default async function GeneralSettingsPage({
|
|||||||
exact: true
|
exact: true
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
if (subscribed) {
|
if (build === "saas") {
|
||||||
navItems.push({
|
navItems.push({
|
||||||
title: t("authPage"),
|
title: t("authPage"),
|
||||||
href: `/{orgId}/settings/general/auth-page`
|
href: `/{orgId}/settings/general/auth-page`
|
||||||
|
|||||||
20
src/lib/api/getSubscriptionStatus.ts
Normal file
20
src/lib/api/getSubscriptionStatus.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { build } from "@server/build";
|
||||||
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
|
import { cache } from "react";
|
||||||
|
import { getCachedSubscription } from "./getCachedSubscription";
|
||||||
|
import type { GetOrgTierResponse } from "@server/routers/billing/types";
|
||||||
|
|
||||||
|
export const isSubscribed = cache(async (orgId: string) => {
|
||||||
|
let subscriptionStatus: GetOrgTierResponse | null = null;
|
||||||
|
try {
|
||||||
|
const subRes = await getCachedSubscription(orgId);
|
||||||
|
subscriptionStatus = subRes.data.data;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
const subscribed =
|
||||||
|
build === "enterprise"
|
||||||
|
? true
|
||||||
|
: subscriptionStatus?.tier === TierId.STANDARD;
|
||||||
|
|
||||||
|
return subscribed;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user