Skip to content

Commit f3c8262

Browse files
committed
fix: ts errors
1 parent 289119e commit f3c8262

2 files changed

Lines changed: 43 additions & 59 deletions

File tree

apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { zodResolver } from "@hookform/resolvers/zod";
1+
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
22
import { EyeIcon, EyeOffIcon } from "lucide-react";
33
import { type CSSProperties, useEffect, useState } from "react";
44
import { useForm } from "react-hook-form";
@@ -36,33 +36,37 @@ interface Props {
3636
}
3737

3838
export const ShowEnvironment = ({ id, type }: Props) => {
39+
const { data: permissions } = api.user.getPermissions.useQuery();
40+
const canWrite = permissions?.envVars.write ?? false;
3941
const queryMap = {
40-
postgres: () =>
41-
api.postgres.one.useQuery({ postgresId: id }, { enabled: !!id }),
42-
redis: () => api.redis.one.useQuery({ redisId: id }, { enabled: !!id }),
43-
mysql: () => api.mysql.one.useQuery({ mysqlId: id }, { enabled: !!id }),
42+
compose: () =>
43+
api.compose.one.useQuery({ composeId: id }, { enabled: !!id }),
44+
libsql: () => api.libsql.one.useQuery({ libsqlId: id }, { enabled: !!id }),
4445
mariadb: () =>
4546
api.mariadb.one.useQuery({ mariadbId: id }, { enabled: !!id }),
4647
mongo: () => api.mongo.one.useQuery({ mongoId: id }, { enabled: !!id }),
47-
compose: () =>
48-
api.compose.one.useQuery({ composeId: id }, { enabled: !!id }),
48+
mysql: () => api.mysql.one.useQuery({ mysqlId: id }, { enabled: !!id }),
49+
postgres: () =>
50+
api.postgres.one.useQuery({ postgresId: id }, { enabled: !!id }),
51+
redis: () => api.redis.one.useQuery({ redisId: id }, { enabled: !!id }),
4952
};
5053
const { data, refetch } = queryMap[type]
5154
? queryMap[type]()
5255
: api.mongo.one.useQuery({ mongoId: id }, { enabled: !!id });
5356
const [isEnvVisible, setIsEnvVisible] = useState(true);
5457

5558
const mutationMap = {
56-
postgres: () => api.postgres.update.useMutation(),
57-
redis: () => api.redis.update.useMutation(),
58-
mysql: () => api.mysql.update.useMutation(),
59-
mariadb: () => api.mariadb.update.useMutation(),
60-
mongo: () => api.mongo.update.useMutation(),
61-
compose: () => api.compose.update.useMutation(),
59+
compose: () => api.compose.saveEnvironment.useMutation(),
60+
libsql: () => api.libsql.saveEnvironment.useMutation(),
61+
mariadb: () => api.mariadb.saveEnvironment.useMutation(),
62+
mongo: () => api.mongo.saveEnvironment.useMutation(),
63+
mysql: () => api.mysql.saveEnvironment.useMutation(),
64+
postgres: () => api.postgres.saveEnvironment.useMutation(),
65+
redis: () => api.redis.saveEnvironment.useMutation(),
6266
};
63-
const { mutateAsync, isLoading } = mutationMap[type]
67+
const { mutateAsync, isPending } = mutationMap[type]
6468
? mutationMap[type]()
65-
: api.mongo.update.useMutation();
69+
: api.mongo.saveEnvironment.useMutation();
6670

6771
const form = useForm<EnvironmentSchema>({
6872
defaultValues: {
@@ -85,12 +89,13 @@ export const ShowEnvironment = ({ id, type }: Props) => {
8589

8690
const onSubmit = async (formData: EnvironmentSchema) => {
8791
mutateAsync({
92+
composeId: id || "",
93+
libsqlId: id || "",
94+
mariadbId: id || "",
8895
mongoId: id || "",
96+
mysqlId: id || "",
8997
postgresId: id || "",
9098
redisId: id || "",
91-
mysqlId: id || "",
92-
mariadbId: id || "",
93-
composeId: id || "",
9499
env: formData.environment,
95100
})
96101
.then(async () => {
@@ -111,7 +116,7 @@ export const ShowEnvironment = ({ id, type }: Props) => {
111116
// Add keyboard shortcut for Ctrl+S/Cmd+S
112117
useEffect(() => {
113118
const handleKeyDown = (e: KeyboardEvent) => {
114-
if ((e.ctrlKey || e.metaKey) && e.key === "s" && !isLoading) {
119+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyS" && !isPending) {
115120
e.preventDefault();
116121
form.handleSubmit(onSubmit)();
117122
}
@@ -121,7 +126,7 @@ export const ShowEnvironment = ({ id, type }: Props) => {
121126
return () => {
122127
document.removeEventListener("keydown", handleKeyDown);
123128
};
124-
}, [form, onSubmit, isLoading]);
129+
}, [form, onSubmit, isPending]);
125130

126131
return (
127132
<div className="flex w-full flex-col gap-5 ">
@@ -185,25 +190,27 @@ PORT=3000
185190
)}
186191
/>
187192

188-
<div className="flex flex-row justify-end gap-2">
189-
{hasChanges && (
193+
{canWrite && (
194+
<div className="flex flex-row justify-end gap-2">
195+
{hasChanges && (
196+
<Button
197+
type="button"
198+
variant="outline"
199+
onClick={handleCancel}
200+
>
201+
Cancel
202+
</Button>
203+
)}
190204
<Button
191-
type="button"
192-
variant="outline"
193-
onClick={handleCancel}
205+
isLoading={isPending}
206+
className="w-fit"
207+
type="submit"
208+
disabled={!hasChanges}
194209
>
195-
Cancel
210+
Save
196211
</Button>
197-
)}
198-
<Button
199-
isLoading={isLoading}
200-
className="w-fit"
201-
type="submit"
202-
disabled={!hasChanges}
203-
>
204-
Save
205-
</Button>
206-
</div>
212+
</div>
213+
)}
207214
</form>
208215
</Form>
209216
</CardContent>

apps/dokploy/utils/i18n.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)