Skip to content

Commit d6c9aaf

Browse files
committed
fix: dataroom index
1 parent cb1ebed commit d6c9aaf

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

components/datarooms/actions/rebuild-index-button.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PlanEnum } from "@/ee/stripe/constants";
44
import { ListOrderedIcon } from "lucide-react";
55
import { toast } from "sonner";
66

7+
import { useFeatureFlags } from "@/lib/hooks/use-feature-flags";
78
import { usePlan } from "@/lib/swr/use-billing";
89

910
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
@@ -30,17 +31,28 @@ export default function RebuildIndexButton({
3031
dataroomId,
3132
disabled = false,
3233
}: RebuildIndexButtonProps) {
34+
const { isFeatureEnabled } = useFeatureFlags();
3335
const { isDatarooms, isDataroomsPlus, isTrial } = usePlan();
3436
const [isLoading, setIsLoading] = useState(false);
3537
const [isOpen, setIsOpen] = useState(false);
3638

37-
// INFO: Don't render if user doesn't have a datarooms plan
38-
if (!isDatarooms && !isDataroomsPlus && !isTrial) {
39+
const isDataroomIndexEnabled = isFeatureEnabled("dataroomIndex");
40+
const hasDataroomsPlan = isDatarooms || isDataroomsPlus || isTrial;
41+
const hasDataroomsPlusPlan = isDataroomsPlus;
42+
43+
// Show button if: feature flag is enabled OR user has datarooms plan or higher
44+
const shouldShowButton = isDataroomIndexEnabled || hasDataroomsPlan;
45+
46+
// Allow usage if: feature flag is enabled OR user has datarooms-plus plan
47+
const canUseFeature = isDataroomIndexEnabled || hasDataroomsPlusPlan;
48+
49+
// Don't render if conditions aren't met
50+
if (!shouldShowButton) {
3951
return null;
4052
}
4153

4254
const handleRebuildIndex = async () => {
43-
if (!isDataroomsPlus) {
55+
if (!canUseFeature) {
4456
toast.error("Upgrade to Data Rooms Plus plan to use this feature.");
4557
return;
4658
}
@@ -127,7 +139,7 @@ export default function RebuildIndexButton({
127139
</div>
128140

129141
<DialogFooter>
130-
{isDataroomsPlus ? (
142+
{canUseFeature ? (
131143
<>
132144
<Button variant="outline" onClick={() => setIsOpen(false)}>
133145
Cancel

pages/api/teams/[teamId]/datarooms/[id]/calculate-indexes.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ export default async function handler(
4040
}
4141

4242
try {
43-
// Check if dataroomIndex feature flag is enabled
44-
const featureFlags = await getFeatureFlags({ teamId });
45-
if (!featureFlags.dataroomIndex) {
46-
return res.status(403).json({ message: "Feature not enabled" });
47-
}
48-
49-
// Verify user has access to this dataroom
43+
// Verify user has access to this dataroom and get team plan
5044
const dataroom = await prisma.dataroom.findUnique({
5145
where: {
5246
id: dataroomId,
@@ -62,13 +56,30 @@ export default async function handler(
6256
select: {
6357
id: true,
6458
name: true,
59+
team: {
60+
select: {
61+
plan: true,
62+
},
63+
},
6564
},
6665
});
6766

6867
if (!dataroom) {
6968
return res.status(404).json({ message: "Dataroom not found" });
7069
}
7170

71+
// Check if user has access: feature flag enabled OR datarooms-plus plan
72+
const featureFlags = await getFeatureFlags({ teamId });
73+
const hasDataroomsPlusPlan =
74+
dataroom.team.plan === "datarooms-plus" ||
75+
dataroom.team.plan === "datarooms-plus+old";
76+
77+
if (!featureFlags.dataroomIndex && !hasDataroomsPlusPlan) {
78+
return res.status(403).json({
79+
message: "This feature requires a Data Rooms Plus plan",
80+
});
81+
}
82+
7283
// Calculate and update hierarchical indexes
7384
const result = await calculateAndUpdateHierarchicalIndexes(dataroomId);
7485

0 commit comments

Comments
 (0)