mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-17 04:47:11 +00:00
Properly paywall the edit policy screen
This commit is contained in:
@@ -8,13 +8,14 @@ import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
|||||||
|
|
||||||
import { orgQueries } from "@app/lib/queries";
|
import { orgQueries } from "@app/lib/queries";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
import { TierFeature, tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { EditPolicyNameSectionForm } from "./EditPolicyNameSectionForm";
|
import { EditPolicyNameSectionForm } from "./EditPolicyNameSectionForm";
|
||||||
import { PolicyAuthStackSection } from "./PolicyAuthStackSection";
|
import { PolicyAuthStackSection } from "./PolicyAuthStackSection";
|
||||||
import { PolicyAccessRulesSection } from "./PolicyAccessRulesSection";
|
import { PolicyAccessRulesSection } from "./PolicyAccessRulesSection";
|
||||||
|
import { PaidFeaturesAlert } from "@app/components/PaidFeaturesAlert";
|
||||||
|
|
||||||
export type EditPolicyFormSection = "general" | "authentication" | "rules";
|
export type EditPolicyFormSection = "general" | "authentication" | "rules";
|
||||||
|
|
||||||
@@ -71,13 +72,17 @@ export function EditPolicyForm({
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const policyTiers = tierMatrix[TierFeature.ResourcePolicies];
|
||||||
|
const isDisabled = !isPaidUser(policyTiers);
|
||||||
|
const effectiveReadonly = readonly || isDisabled;
|
||||||
|
|
||||||
const authSection = (
|
const authSection = (
|
||||||
<PolicyAuthStackSection
|
<PolicyAuthStackSection
|
||||||
mode="edit"
|
mode="edit"
|
||||||
orgId={org.org.orgId}
|
orgId={org.org.orgId}
|
||||||
allIdps={allIdps}
|
allIdps={allIdps}
|
||||||
emailEnabled={env.email.emailEnabled}
|
emailEnabled={env.email.emailEnabled}
|
||||||
readonly={readonly}
|
readonly={effectiveReadonly}
|
||||||
resourceId={resourceId}
|
resourceId={resourceId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -87,32 +92,82 @@ export function EditPolicyForm({
|
|||||||
mode="edit"
|
mode="edit"
|
||||||
isMaxmindAvailable={isMaxmindAvailable}
|
isMaxmindAvailable={isMaxmindAvailable}
|
||||||
isMaxmindAsnAvailable={isMaxmindASNAvailable}
|
isMaxmindAsnAvailable={isMaxmindASNAvailable}
|
||||||
readonly={readonly}
|
readonly={effectiveReadonly}
|
||||||
resourceId={resourceId}
|
resourceId={resourceId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (section === "general") {
|
if (section === "general") {
|
||||||
return <EditPolicyNameSectionForm readonly={readonly} />;
|
return (
|
||||||
|
<>
|
||||||
|
<PaidFeaturesAlert tiers={policyTiers} />
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
isDisabled
|
||||||
|
? "pointer-events-none opacity-50"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<EditPolicyNameSectionForm readonly={effectiveReadonly} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section === "authentication") {
|
if (section === "authentication") {
|
||||||
return authSection;
|
return (
|
||||||
|
<>
|
||||||
|
<PaidFeaturesAlert tiers={policyTiers} />
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
isDisabled
|
||||||
|
? "pointer-events-none opacity-50"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{authSection}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section === "rules") {
|
if (section === "rules") {
|
||||||
return rulesSection;
|
return (
|
||||||
|
<>
|
||||||
|
<PaidFeaturesAlert tiers={policyTiers} />
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
isDisabled
|
||||||
|
? "pointer-events-none opacity-50"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{rulesSection}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsContainer>
|
<>
|
||||||
{!hidePolicyNameForm && !isOverlay && (
|
<PaidFeaturesAlert tiers={policyTiers} />
|
||||||
<EditPolicyNameSectionForm readonly={readonly} />
|
<div
|
||||||
)}
|
className={
|
||||||
|
isDisabled ? "pointer-events-none opacity-50" : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SettingsContainer>
|
||||||
|
{!hidePolicyNameForm && !isOverlay && (
|
||||||
|
<EditPolicyNameSectionForm
|
||||||
|
readonly={effectiveReadonly}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{authSection}
|
{authSection}
|
||||||
|
|
||||||
{rulesSection}
|
{rulesSection}
|
||||||
</SettingsContainer>
|
</SettingsContainer>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user