feat: adding add models lock according to prcing plan
This commit is contained in:
parent
fbb7b18273
commit
cb01c896a0
@ -2,6 +2,7 @@ import { AccessType } from "../../../lib/AccessType";
|
|||||||
import { MachineList } from "@/components/MachineList";
|
import { MachineList } from "@/components/MachineList";
|
||||||
import { db } from "@/db/db";
|
import { db } from "@/db/db";
|
||||||
import { machinesTable } from "@/db/schema";
|
import { machinesTable } from "@/db/schema";
|
||||||
|
import { getCurrentPlanWithAuth } from "@/server/getCurrentPlan";
|
||||||
import { auth } from "@clerk/nextjs";
|
import { auth } from "@clerk/nextjs";
|
||||||
import { clerkClient } from "@clerk/nextjs/server";
|
import { clerkClient } from "@clerk/nextjs/server";
|
||||||
import { desc, eq, isNull, and } from "drizzle-orm";
|
import { desc, eq, isNull, and } from "drizzle-orm";
|
||||||
@ -19,6 +20,8 @@ async function MachineListServer() {
|
|||||||
|
|
||||||
const user = await clerkClient.users.getUser(userId);
|
const user = await clerkClient.users.getUser(userId);
|
||||||
|
|
||||||
|
const sub = await getCurrentPlanWithAuth();
|
||||||
|
|
||||||
const machines = await db.query.machinesTable.findMany({
|
const machines = await db.query.machinesTable.findMany({
|
||||||
orderBy: desc(machinesTable.updated_at),
|
orderBy: desc(machinesTable.updated_at),
|
||||||
where:
|
where:
|
||||||
@ -31,6 +34,7 @@ async function MachineListServer() {
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
{/* <div>Machines</div> */}
|
{/* <div>Machines</div> */}
|
||||||
<MachineList
|
<MachineList
|
||||||
|
sub={sub}
|
||||||
data={machines}
|
data={machines}
|
||||||
userMetadata={AccessType.parse(user.privateMetadata ?? {})}
|
userMetadata={AccessType.parse(user.privateMetadata ?? {})}
|
||||||
/>
|
/>
|
||||||
|
@ -26,11 +26,11 @@ import type { UnknownKeysParam, ZodObject, ZodRawShape, z } from "zod";
|
|||||||
export function InsertModal<
|
export function InsertModal<
|
||||||
K extends ZodRawShape,
|
K extends ZodRawShape,
|
||||||
Y extends UnknownKeysParam,
|
Y extends UnknownKeysParam,
|
||||||
Z extends ZodObject<K, Y>
|
Z extends ZodObject<K, Y>,
|
||||||
>(props: {
|
>(props: {
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
title: string;
|
title: React.ReactNode;
|
||||||
description: string;
|
description: string;
|
||||||
dialogClassName?: string;
|
dialogClassName?: string;
|
||||||
serverAction: (data: z.infer<Z>) => Promise<unknown>;
|
serverAction: (data: z.infer<Z>) => Promise<unknown>;
|
||||||
@ -105,7 +105,7 @@ export function InsertModal<
|
|||||||
export function UpdateModal<
|
export function UpdateModal<
|
||||||
K extends ZodRawShape,
|
K extends ZodRawShape,
|
||||||
Y extends UnknownKeysParam,
|
Y extends UnknownKeysParam,
|
||||||
Z extends ZodObject<K, Y>
|
Z extends ZodObject<K, Y>,
|
||||||
>(props: {
|
>(props: {
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
setOpen?: (open: boolean) => void;
|
setOpen?: (open: boolean) => void;
|
||||||
@ -118,7 +118,7 @@ export function UpdateModal<
|
|||||||
serverAction: (
|
serverAction: (
|
||||||
data: z.infer<Z> & {
|
data: z.infer<Z> & {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
},
|
||||||
) => Promise<unknown>;
|
) => Promise<unknown>;
|
||||||
formSchema: Z;
|
formSchema: Z;
|
||||||
fieldConfig?: FieldConfig<z.infer<Z>>;
|
fieldConfig?: FieldConfig<z.infer<Z>>;
|
||||||
@ -165,7 +165,7 @@ export function UpdateModal<
|
|||||||
props.serverAction({
|
props.serverAction({
|
||||||
...data,
|
...data,
|
||||||
id: props.data.id,
|
id: props.data.id,
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
@ -41,6 +41,7 @@ import {
|
|||||||
updateMachine,
|
updateMachine,
|
||||||
} from "@/server/curdMachine";
|
} from "@/server/curdMachine";
|
||||||
import { editWorkflowOnMachine } from "@/server/editWorkflowOnMachine";
|
import { editWorkflowOnMachine } from "@/server/editWorkflowOnMachine";
|
||||||
|
import { getCurrentPlanWithAuth } from "@/server/getCurrentPlan";
|
||||||
import type {
|
import type {
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
ColumnFiltersState,
|
ColumnFiltersState,
|
||||||
@ -55,7 +56,7 @@ import {
|
|||||||
getSortedRowModel,
|
getSortedRowModel,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
import { ArrowUpDown, Lock, MoreHorizontal, Plus } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@ -321,9 +322,11 @@ export const columns: ColumnDef<Machine>[] = [
|
|||||||
export function MachineList({
|
export function MachineList({
|
||||||
data,
|
data,
|
||||||
userMetadata,
|
userMetadata,
|
||||||
|
sub,
|
||||||
}: {
|
}: {
|
||||||
data: Machine[];
|
data: Machine[];
|
||||||
userMetadata: z.infer<typeof AccessType>;
|
userMetadata: z.infer<typeof AccessType>;
|
||||||
|
sub: Awaited<ReturnType<typeof getCurrentPlanWithAuth>>;
|
||||||
}) {
|
}) {
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||||
@ -352,6 +355,21 @@ export function MachineList({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let machineMaxCount = 2;
|
||||||
|
|
||||||
|
// Temp fixes for machine count
|
||||||
|
if (userMetadata.betaFeaturesAccess) machineMaxCount = 5;
|
||||||
|
|
||||||
|
if (sub?.plan == "pro") {
|
||||||
|
machineMaxCount = 10;
|
||||||
|
} else if (sub?.plan == "enterprise") {
|
||||||
|
machineMaxCount = 99;
|
||||||
|
}
|
||||||
|
|
||||||
|
const locked =
|
||||||
|
data.some((machine) => machine.type === "modal-serverless") &&
|
||||||
|
data.length >= machineMaxCount;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-center py-4">
|
<div className="flex items-center py-4">
|
||||||
@ -366,17 +384,17 @@ export function MachineList({
|
|||||||
<div className="ml-auto flex gap-2">
|
<div className="ml-auto flex gap-2">
|
||||||
<InsertModal
|
<InsertModal
|
||||||
dialogClassName="sm:max-w-[600px]"
|
dialogClassName="sm:max-w-[600px]"
|
||||||
disabled={
|
disabled={locked}
|
||||||
data.some(
|
|
||||||
(machine) => machine.type === "comfy-deploy-serverless",
|
|
||||||
) && !userMetadata.betaFeaturesAccess
|
|
||||||
}
|
|
||||||
tooltip={
|
tooltip={
|
||||||
data.some((machine) => machine.type === "comfy-deploy-serverless")
|
locked
|
||||||
? "Only one hosted machine at preview stage"
|
? `Max ${machineMaxCount} ComfyUI machine for your account, upgrade to unlock more cnfiguration.`
|
||||||
: undefined
|
: `Max ${machineMaxCount} ComfyUI machine for your account`
|
||||||
|
}
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
New Machine {locked ? <Lock size={14} /> : <Plus size={14} />}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
title="New Machine"
|
|
||||||
description="Add custom ComfyUI machines to your account."
|
description="Add custom ComfyUI machines to your account."
|
||||||
serverAction={addCustomMachine}
|
serverAction={addCustomMachine}
|
||||||
formSchema={addCustomMachineSchema}
|
formSchema={addCustomMachineSchema}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user