mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-26 17:45:49 +02:00
Refactor license key management: update API calls to use licenseKey router and clean up organization router by removing enterprise settings methods
This commit is contained in:
@@ -10,9 +10,9 @@ import { api } from "@/utils/api";
|
||||
|
||||
export function LicenseKeySettings() {
|
||||
const utils = api.useUtils();
|
||||
const { data, isLoading } = api.organization.getEnterpriseSettings.useQuery();
|
||||
const { data, isLoading } = api.licenseKey.getEnterpriseSettings.useQuery();
|
||||
const { mutateAsync: updateEnterpriseSettings, isLoading: isSaving } =
|
||||
api.organization.updateEnterpriseSettings.useMutation();
|
||||
api.licenseKey.updateEnterpriseSettings.useMutation();
|
||||
|
||||
const [licenseKey, setLicenseKey] = useState("");
|
||||
|
||||
@@ -45,7 +45,7 @@ export function LicenseKeySettings() {
|
||||
await updateEnterpriseSettings({
|
||||
enableEnterpriseFeatures: next,
|
||||
});
|
||||
await utils.organization.getEnterpriseSettings.invalidate();
|
||||
await utils.licenseKey.getEnterpriseSettings.invalidate();
|
||||
toast.success("Enterprise features updated");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -57,7 +57,8 @@ export function LicenseKeySettings() {
|
||||
</div>
|
||||
|
||||
<p className="text-sm text-muted-foreground">
|
||||
To unlock extra features you need an enterprise license key. Contact us{" "}
|
||||
To unlock extra features you need an enterprise license key. Contact
|
||||
us{" "}
|
||||
<Link
|
||||
href="http://localhost:3001/contact"
|
||||
target="_blank"
|
||||
@@ -90,7 +91,7 @@ export function LicenseKeySettings() {
|
||||
onClick={async () => {
|
||||
try {
|
||||
await updateEnterpriseSettings({ licenseKey });
|
||||
await utils.organization.getEnterpriseSettings.invalidate();
|
||||
await utils.licenseKey.getEnterpriseSettings.invalidate();
|
||||
toast.success("License key saved");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -4,51 +4,9 @@ import { and, desc, eq, exists } from "drizzle-orm";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { db } from "@/server/db";
|
||||
import { invitation, member, organization, user } from "@/server/db/schema";
|
||||
import { invitation, member, organization } from "@/server/db/schema";
|
||||
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
||||
export const organizationRouter = createTRPCRouter({
|
||||
getEnterpriseSettings: adminProcedure.query(async ({ ctx }) => {
|
||||
const currentUserId = ctx.user.id;
|
||||
const currentUser = await db.query.user.findFirst({
|
||||
where: eq(user.id, currentUserId),
|
||||
});
|
||||
|
||||
if (!currentUser) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "User not found",
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
enableEnterpriseFeatures: !!currentUser.enableEnterpriseFeatures,
|
||||
licenseKey: currentUser.licenseKey ?? "",
|
||||
};
|
||||
}),
|
||||
|
||||
updateEnterpriseSettings: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
enableEnterpriseFeatures: z.boolean().optional(),
|
||||
licenseKey: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const currentUserId = ctx.user.id;
|
||||
|
||||
await db
|
||||
.update(user)
|
||||
.set({
|
||||
...(input.enableEnterpriseFeatures === undefined
|
||||
? {}
|
||||
: { enableEnterpriseFeatures: input.enableEnterpriseFeatures }),
|
||||
...(input.licenseKey === undefined ? {} : { licenseKey: input.licenseKey }),
|
||||
})
|
||||
.where(eq(user.id, currentUserId));
|
||||
|
||||
return true;
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
|
||||
Reference in New Issue
Block a user