mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-30 07:08:47 +00: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() {
|
export function LicenseKeySettings() {
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const { data, isLoading } = api.organization.getEnterpriseSettings.useQuery();
|
const { data, isLoading } = api.licenseKey.getEnterpriseSettings.useQuery();
|
||||||
const { mutateAsync: updateEnterpriseSettings, isLoading: isSaving } =
|
const { mutateAsync: updateEnterpriseSettings, isLoading: isSaving } =
|
||||||
api.organization.updateEnterpriseSettings.useMutation();
|
api.licenseKey.updateEnterpriseSettings.useMutation();
|
||||||
|
|
||||||
const [licenseKey, setLicenseKey] = useState("");
|
const [licenseKey, setLicenseKey] = useState("");
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export function LicenseKeySettings() {
|
|||||||
await updateEnterpriseSettings({
|
await updateEnterpriseSettings({
|
||||||
enableEnterpriseFeatures: next,
|
enableEnterpriseFeatures: next,
|
||||||
});
|
});
|
||||||
await utils.organization.getEnterpriseSettings.invalidate();
|
await utils.licenseKey.getEnterpriseSettings.invalidate();
|
||||||
toast.success("Enterprise features updated");
|
toast.success("Enterprise features updated");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -57,7 +57,8 @@ export function LicenseKeySettings() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-sm text-muted-foreground">
|
<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
|
<Link
|
||||||
href="http://localhost:3001/contact"
|
href="http://localhost:3001/contact"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -90,7 +91,7 @@ export function LicenseKeySettings() {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
await updateEnterpriseSettings({ licenseKey });
|
await updateEnterpriseSettings({ licenseKey });
|
||||||
await utils.organization.getEnterpriseSettings.invalidate();
|
await utils.licenseKey.getEnterpriseSettings.invalidate();
|
||||||
toast.success("License key saved");
|
toast.success("License key saved");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -4,51 +4,9 @@ import { and, desc, eq, exists } from "drizzle-orm";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@/server/db";
|
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";
|
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
export const organizationRouter = createTRPCRouter({
|
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
|
create: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user