Skip to content

feat: update default limits parser #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/billing/add-seat-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function AddSeatModal({
}, [open]);

// Calculate the total number of seats after the update
const totalSeatsAfterUpdate = limits ? limits.users + quantity : quantity;
const totalSeatsAfterUpdate = limits ? limits.users! + quantity : quantity;

const handleDecrement = () => {
if (quantity > 1) {
Expand Down
15 changes: 10 additions & 5 deletions ee/limits/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const planLimitsMap: Record<string, TPlanLimits> = {
};

export const configSchema = z.object({
datarooms: z.number(),
datarooms: z.number().optional(),
links: z
.preprocess((v) => (v === null ? Infinity : Number(v)), z.number())
.optional()
Expand All @@ -35,10 +35,10 @@ export const configSchema = z.object({
.preprocess((v) => (v === null ? Infinity : Number(v)), z.number())
.optional()
.default(50),
users: z.number(),
domains: z.number(),
customDomainOnPro: z.boolean(),
customDomainInDataroom: z.boolean(),
users: z.number().optional(),
domains: z.number().optional(),
customDomainOnPro: z.boolean().optional(),
customDomainInDataroom: z.boolean().optional(),
advancedLinkControlsOnPro: z.boolean().nullish(),
watermarkOnBusiness: z.boolean().nullish(),
conversationsInDataroom: z.boolean().nullish(),
Expand Down Expand Up @@ -98,14 +98,19 @@ export async function getLimits({
try {
let parsedData = configSchema.parse(team.limits);

const basePlan = getBasePlan(team.plan);
const defaultLimits = planLimitsMap[basePlan];

// Adjust limits based on the plan if they're at the default value
if (isFreePlan(team.plan)) {
return {
...defaultLimits,
...parsedData,
usage: { documents: documentCount, links: linkCount, users: userCount },
};
} else {
return {
...defaultLimits,
...parsedData,
// if account is paid, but link and document limits are not set, then set them to Infinity
links: parsedData.links === 50 ? Infinity : parsedData.links,
Expand Down
18 changes: 9 additions & 9 deletions pages/settings/people.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { useSession } from "next-auth/react";
import { toast } from "sonner";
import { mutate } from "swr";

import { useAnalytics } from "@/lib/analytics";
import { usePlan } from "@/lib/swr/use-billing";
import { useInvitations } from "@/lib/swr/use-invitations";
import useLimits from "@/lib/swr/use-limits";
import { useGetTeam } from "@/lib/swr/use-team";
import { useTeams } from "@/lib/swr/use-teams";
import { CustomUser } from "@/lib/types";

import { AddSeatModal } from "@/components/billing/add-seat-modal";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import AppLayout from "@/components/layouts/app";
Expand All @@ -27,14 +35,6 @@ import {
} from "@/components/ui/dropdown-menu";
import { Skeleton } from "@/components/ui/skeleton";

import { useAnalytics } from "@/lib/analytics";
import { usePlan } from "@/lib/swr/use-billing";
import { useInvitations } from "@/lib/swr/use-invitations";
import useLimits from "@/lib/swr/use-limits";
import { useGetTeam } from "@/lib/swr/use-team";
import { useTeams } from "@/lib/swr/use-teams";
import { CustomUser } from "@/lib/types";

export default function Billing() {
const [isTeamMemberInviteModalOpen, setTeamMemberInviteModalOpen] =
useState<boolean>(false);
Expand Down Expand Up @@ -239,7 +239,7 @@ export default function Billing() {
</Button>
</UpgradePlanModal>
) : limits === null ||
(limits && limits.users > numUsers + numInvitations) ? (
(limits && limits.users! > numUsers + numInvitations) ? (
<AddTeamMembers
open={isTeamMemberInviteModalOpen}
setOpen={setTeamMemberInviteModalOpen}
Expand Down