mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-29 22:58:49 +00:00
refactor: update volume backup and environment description handling to use undefined instead of null for improved consistency; enhance error handling in AI component
This commit is contained in:
+1
-1
@@ -207,7 +207,7 @@ export const HandleVolumeBackups = ({
|
|||||||
|
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
...values,
|
...values,
|
||||||
keepLatestCount: preparedKeepLatestCount,
|
keepLatestCount: preparedKeepLatestCount ?? undefined,
|
||||||
destinationId: values.destinationId,
|
destinationId: values.destinationId,
|
||||||
volumeBackupId: volumeBackupId || "",
|
volumeBackupId: volumeBackupId || "",
|
||||||
serviceType: volumeBackupType,
|
serviceType: volumeBackupType,
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export const AdvancedEnvironmentSelector = ({
|
|||||||
await createEnvironment.mutateAsync({
|
await createEnvironment.mutateAsync({
|
||||||
projectId,
|
projectId,
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
description: description.trim() || null,
|
description: description.trim() || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success("Environment created successfully");
|
toast.success("Environment created successfully");
|
||||||
@@ -115,7 +115,7 @@ export const AdvancedEnvironmentSelector = ({
|
|||||||
await updateEnvironment.mutateAsync({
|
await updateEnvironment.mutateAsync({
|
||||||
environmentId: selectedEnvironment.environmentId,
|
environmentId: selectedEnvironment.environmentId,
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
description: description.trim() || null,
|
description: description.trim() || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success("Environment updated successfully");
|
toast.success("Environment updated successfully");
|
||||||
@@ -168,7 +168,7 @@ export const AdvancedEnvironmentSelector = ({
|
|||||||
const result = await duplicateEnvironment.mutateAsync({
|
const result = await duplicateEnvironment.mutateAsync({
|
||||||
environmentId: environment.environmentId,
|
environmentId: environment.environmentId,
|
||||||
name: `${environment.name}-copy`,
|
name: `${environment.name}-copy`,
|
||||||
description: environment.description,
|
description: environment.description || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success("Environment duplicated successfully");
|
toast.success("Environment duplicated successfully");
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ interface Props {
|
|||||||
|
|
||||||
export const HandleAi = ({ aiId }: Props) => {
|
export const HandleAi = ({ aiId }: Props) => {
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [modelPopoverOpen, setModelPopoverOpen] = useState(false);
|
const [modelPopoverOpen, setModelPopoverOpen] = useState(false);
|
||||||
const [modelSearch, setModelSearch] = useState("");
|
const [modelSearch, setModelSearch] = useState("");
|
||||||
@@ -102,19 +101,19 @@ export const HandleAi = ({ aiId }: Props) => {
|
|||||||
const apiKey = form.watch("apiKey");
|
const apiKey = form.watch("apiKey");
|
||||||
|
|
||||||
const isOllama = apiUrl.includes(":11434") || apiUrl.includes("ollama");
|
const isOllama = apiUrl.includes(":11434") || apiUrl.includes("ollama");
|
||||||
const { data: models, isPending: isLoadingServerModels } =
|
const {
|
||||||
api.ai.getModels.useQuery(
|
data: models,
|
||||||
{
|
isPending: isLoadingServerModels,
|
||||||
apiUrl: apiUrl ?? "",
|
error: modelsError,
|
||||||
apiKey: apiKey ?? "",
|
} = api.ai.getModels.useQuery(
|
||||||
},
|
{
|
||||||
{
|
apiUrl: apiUrl ?? "",
|
||||||
enabled: !!apiUrl && (isOllama || !!apiKey),
|
apiKey: apiKey ?? "",
|
||||||
onError: (error) => {
|
},
|
||||||
setError(`Failed to fetch models: ${error.message}`);
|
{
|
||||||
},
|
enabled: !!apiUrl && (isOllama || !!apiKey),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const onSubmit = async (data: Schema) => {
|
const onSubmit = async (data: Schema) => {
|
||||||
try {
|
try {
|
||||||
@@ -169,7 +168,9 @@ export const HandleAi = ({ aiId }: Props) => {
|
|||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
{error && <AlertBlock type="error">{error}</AlertBlock>}
|
{modelsError && (
|
||||||
|
<AlertBlock type="error">{modelsError.message}</AlertBlock>
|
||||||
|
)}
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2">
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
text,
|
text,
|
||||||
timestamp,
|
timestamp,
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { account, apikey, organization } from "./account";
|
import { account, apikey, organization } from "./account";
|
||||||
@@ -80,41 +81,76 @@ export const usersRelations = relations(user, ({ one, many }) => ({
|
|||||||
schedules: many(schedules),
|
schedules: many(schedules),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const apiCreateUserInvitation = z.object({
|
const createSchema = createInsertSchema(user, {
|
||||||
|
id: z.string().min(1),
|
||||||
|
isRegistered: z.boolean().optional(),
|
||||||
|
}).omit({
|
||||||
|
role: true,
|
||||||
|
trustedOrigins: true,
|
||||||
|
isValidEnterpriseLicense: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const apiCreateUserInvitation = createSchema.pick({}).extend({
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiRemoveUser = z.object({
|
export const apiRemoveUser = createSchema
|
||||||
id: z.string().min(1),
|
.pick({
|
||||||
});
|
id: true,
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export const apiFindOneToken = z.object({
|
export const apiFindOneToken = createSchema
|
||||||
token: z.string().min(1),
|
.pick({})
|
||||||
});
|
.required()
|
||||||
|
.extend({
|
||||||
|
token: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
export const apiAssignPermissions = z.object({
|
export const apiAssignPermissions = createSchema
|
||||||
id: z.string().min(1),
|
.pick({
|
||||||
accessedProjects: z.array(z.string()).optional(),
|
id: true,
|
||||||
accessedEnvironments: z.array(z.string()).optional(),
|
// canCreateProjects: true,
|
||||||
accessedServices: z.array(z.string()).optional(),
|
// canCreateServices: true,
|
||||||
canCreateProjects: z.boolean().optional(),
|
// canDeleteProjects: true,
|
||||||
canCreateServices: z.boolean().optional(),
|
// canDeleteServices: true,
|
||||||
canDeleteProjects: z.boolean().optional(),
|
// accessedProjects: true,
|
||||||
canDeleteServices: z.boolean().optional(),
|
// accessedServices: true,
|
||||||
canAccessToDocker: z.boolean().optional(),
|
// canAccessToTraefikFiles: true,
|
||||||
canAccessToTraefikFiles: z.boolean().optional(),
|
// canAccessToDocker: true,
|
||||||
canAccessToAPI: z.boolean().optional(),
|
// canAccessToAPI: true,
|
||||||
canAccessToSSHKeys: z.boolean().optional(),
|
// canAccessToSSHKeys: true,
|
||||||
canAccessToGitProviders: z.boolean().optional(),
|
// canAccessToGitProviders: true,
|
||||||
canDeleteEnvironments: z.boolean().optional(),
|
})
|
||||||
canCreateEnvironments: z.boolean().optional(),
|
.extend({
|
||||||
});
|
accessedProjects: z.array(z.string()).optional(),
|
||||||
|
accessedEnvironments: z.array(z.string()).optional(),
|
||||||
|
accessedServices: z.array(z.string()).optional(),
|
||||||
|
canCreateProjects: z.boolean().optional(),
|
||||||
|
canCreateServices: z.boolean().optional(),
|
||||||
|
canDeleteProjects: z.boolean().optional(),
|
||||||
|
canDeleteServices: z.boolean().optional(),
|
||||||
|
canAccessToDocker: z.boolean().optional(),
|
||||||
|
canAccessToTraefikFiles: z.boolean().optional(),
|
||||||
|
canAccessToAPI: z.boolean().optional(),
|
||||||
|
canAccessToSSHKeys: z.boolean().optional(),
|
||||||
|
canAccessToGitProviders: z.boolean().optional(),
|
||||||
|
canDeleteEnvironments: z.boolean().optional(),
|
||||||
|
canCreateEnvironments: z.boolean().optional(),
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export const apiFindOneUser = z.object({
|
export const apiFindOneUser = createSchema
|
||||||
id: z.string().min(1),
|
.pick({
|
||||||
});
|
id: true,
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export const apiFindOneUserByAuth = z.object({});
|
export const apiFindOneUserByAuth = createSchema
|
||||||
|
.pick({
|
||||||
|
// authId: true,
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export const apiTraefikConfig = z.object({
|
export const apiTraefikConfig = z.object({
|
||||||
traefikConfig: z.string().min(1),
|
traefikConfig: z.string().min(1),
|
||||||
@@ -183,7 +219,7 @@ export const apiReadStatsLogs = z.object({
|
|||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiUpdateUser = z.object({
|
export const apiUpdateUser = createSchema.partial().extend({
|
||||||
email: z
|
email: z
|
||||||
.string()
|
.string()
|
||||||
.email("Please enter a valid email address")
|
.email("Please enter a valid email address")
|
||||||
|
|||||||
Reference in New Issue
Block a user