Skip to content

Commit cb23d72

Browse files
feat(databases): add copy button to User and Database Name fields (Dokploy#4735)
* feat(databases): add copy button to User and Database Name fields Adds an enableCopyButton prop to the Input component and uses it on the User, Database Name, and Internal Host fields across Postgres, MySQL, MariaDB, MongoDB, Redis, and Libsql credential views. Closes Dokploy#4495 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent aa93897 commit cb23d72

8 files changed

Lines changed: 79 additions & 54 deletions

File tree

‎apps/dokploy/components/dashboard/libsql/general/show-internal-libsql-credentials.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ShowInternalLibsqlCredentials = ({ libsqlId }: Props) => {
2828
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2929
<div className="flex flex-col gap-2">
3030
<Label>User</Label>
31-
<Input disabled value={data?.databaseUser} />
31+
<Input enableCopyButton disabled value={data?.databaseUser} />
3232
</div>
3333
<div className="flex flex-col gap-2">
3434
<Label>Sqld Node</Label>
@@ -71,7 +71,7 @@ export const ShowInternalLibsqlCredentials = ({ libsqlId }: Props) => {
7171
</div>
7272
<div className="flex flex-col gap-2">
7373
<Label>Internal Host</Label>
74-
<Input disabled value={data?.appName} />
74+
<Input enableCopyButton disabled value={data?.appName} />
7575
</div>
7676
<div className="flex flex-col gap-2">
7777
<Label>Enable Namespaces</Label>

‎apps/dokploy/components/dashboard/mariadb/general/show-internal-mariadb-credentials.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export const ShowInternalMariadbCredentials = ({ mariadbId }: Props) => {
2525
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2626
<div className="flex flex-col gap-2">
2727
<Label>User</Label>
28-
<Input disabled value={data?.databaseUser} />
28+
<Input enableCopyButton disabled value={data?.databaseUser} />
2929
</div>
3030
<div className="flex flex-col gap-2">
3131
<Label>Database Name</Label>
32-
<Input disabled value={data?.databaseName} />
32+
<Input enableCopyButton disabled value={data?.databaseName} />
3333
</div>
3434
<div className="flex flex-col gap-2">
3535
<Label>Password</Label>
@@ -79,7 +79,7 @@ export const ShowInternalMariadbCredentials = ({ mariadbId }: Props) => {
7979

8080
<div className="flex flex-col gap-2">
8181
<Label>Internal Host</Label>
82-
<Input disabled value={data?.appName} />
82+
<Input enableCopyButton disabled value={data?.appName} />
8383
</div>
8484

8585
<div className="flex flex-col gap-2 md:col-span-2">

‎apps/dokploy/components/dashboard/mongo/general/show-internal-mongo-credentials.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ShowInternalMongoCredentials = ({ mongoId }: Props) => {
2525
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2626
<div className="flex flex-col gap-2">
2727
<Label>User</Label>
28-
<Input disabled value={data?.databaseUser} />
28+
<Input enableCopyButton disabled value={data?.databaseUser} />
2929
</div>
3030

3131
<div className="flex flex-col gap-2">
@@ -55,7 +55,7 @@ export const ShowInternalMongoCredentials = ({ mongoId }: Props) => {
5555

5656
<div className="flex flex-col gap-2">
5757
<Label>Internal Host</Label>
58-
<Input disabled value={data?.appName} />
58+
<Input enableCopyButton disabled value={data?.appName} />
5959
</div>
6060

6161
<div className="flex flex-col gap-2 md:col-span-2">

‎apps/dokploy/components/dashboard/mysql/general/show-internal-mysql-credentials.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export const ShowInternalMysqlCredentials = ({ mysqlId }: Props) => {
2525
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2626
<div className="flex flex-col gap-2">
2727
<Label>User</Label>
28-
<Input disabled value={data?.databaseUser} />
28+
<Input enableCopyButton disabled value={data?.databaseUser} />
2929
</div>
3030
<div className="flex flex-col gap-2">
3131
<Label>Database Name</Label>
32-
<Input disabled value={data?.databaseName} />
32+
<Input enableCopyButton disabled value={data?.databaseName} />
3333
</div>
3434
<div className="flex flex-col gap-2">
3535
<Label>Password</Label>
@@ -79,7 +79,7 @@ export const ShowInternalMysqlCredentials = ({ mysqlId }: Props) => {
7979

8080
<div className="flex flex-col gap-2">
8181
<Label>Internal Host</Label>
82-
<Input disabled value={data?.appName} />
82+
<Input enableCopyButton disabled value={data?.appName} />
8383
</div>
8484

8585
<div className="flex flex-col gap-2 md:col-span-2">

‎apps/dokploy/components/dashboard/postgres/general/show-internal-postgres-credentials.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export const ShowInternalPostgresCredentials = ({ postgresId }: Props) => {
2525
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2626
<div className="flex flex-col gap-2">
2727
<Label>User</Label>
28-
<Input disabled value={data?.databaseUser} />
28+
<Input enableCopyButton disabled value={data?.databaseUser} />
2929
</div>
3030
<div className="flex flex-col gap-2">
3131
<Label>Database Name</Label>
32-
<Input disabled value={data?.databaseName} />
32+
<Input enableCopyButton disabled value={data?.databaseName} />
3333
</div>
3434
<div className="flex flex-col gap-2">
3535
<Label>Password</Label>
@@ -57,7 +57,7 @@ export const ShowInternalPostgresCredentials = ({ postgresId }: Props) => {
5757

5858
<div className="flex flex-col gap-2">
5959
<Label>Internal Host</Label>
60-
<Input disabled value={data?.appName} />
60+
<Input enableCopyButton disabled value={data?.appName} />
6161
</div>
6262

6363
<div className="flex flex-col gap-2">

‎apps/dokploy/components/dashboard/redis/general/show-internal-redis-credentials.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ShowInternalRedisCredentials = ({ redisId }: Props) => {
2525
<div className="grid w-full md:grid-cols-2 gap-4 md:gap-8">
2626
<div className="flex flex-col gap-2">
2727
<Label>User</Label>
28-
<Input disabled value="default" />
28+
<Input enableCopyButton disabled value="default" />
2929
</div>
3030
<div className="flex flex-col gap-2">
3131
<Label>Password</Label>
@@ -53,7 +53,7 @@ export const ShowInternalRedisCredentials = ({ redisId }: Props) => {
5353

5454
<div className="flex flex-col gap-2">
5555
<Label>Internal Host</Label>
56-
<Input disabled value={data?.appName} />
56+
<Input enableCopyButton disabled value={data?.appName} />
5757
</div>
5858

5959
<div className="flex flex-col gap-2 md:col-span-2">

‎apps/dokploy/components/ui/input.tsx‎

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { EyeIcon, EyeOffIcon, RefreshCcw } from "lucide-react";
1+
import copy from "copy-to-clipboard";
2+
import { Clipboard, EyeIcon, EyeOffIcon, RefreshCcw } from "lucide-react";
23
import * as React from "react";
4+
import { toast } from "sonner";
35

46
import { generateRandomPassword } from "@/lib/password-utils";
57
import { cn } from "@/lib/utils";
8+
import { Button } from "./button";
69

710
export interface InputProps extends React.ComponentProps<"input"> {
811
errorMessage?: string;
912
enablePasswordGenerator?: boolean;
1013
passwordGeneratorLength?: number;
14+
enableCopyButton?: boolean;
1115
}
1216

1317
function Input({
@@ -16,6 +20,7 @@ function Input({
1620
errorMessage,
1721
enablePasswordGenerator = false,
1822
passwordGeneratorLength,
23+
enableCopyButton = false,
1924
ref,
2025
...props
2126
}: InputProps) {
@@ -65,49 +70,67 @@ function Input({
6570
input.dispatchEvent(new Event("input", { bubbles: true }));
6671
};
6772

68-
return (
69-
<>
70-
<div className="relative w-full">
71-
<input
72-
type={inputType}
73-
data-slot="input"
74-
className={cn(
75-
"h-10 w-full min-w-0 rounded-lg border border-input bg-transparent px-3 py-2 text-sm transition-colors outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
76-
isPassword && (shouldShowGenerator ? "pr-16" : "pr-10"),
77-
className,
78-
)}
79-
ref={setRefs}
80-
{...props}
81-
/>
82-
{isPassword && (
83-
<div className="absolute inset-y-0 right-0 flex items-center gap-1 pr-3 text-muted-foreground">
84-
{shouldShowGenerator && (
85-
<button
86-
type="button"
87-
className="hover:text-foreground focus:outline-none"
88-
onClick={handleGeneratePassword}
89-
aria-label="Generate password"
90-
title="Generate password"
91-
tabIndex={-1}
92-
>
93-
<RefreshCcw className="h-4 w-4" />
94-
</button>
95-
)}
73+
const handleCopy = () => {
74+
copy(inputRef.current?.value || "");
75+
toast.success("Value is copied to clipboard");
76+
};
77+
78+
const inputElement = (
79+
<div className="relative w-full">
80+
<input
81+
type={inputType}
82+
data-slot="input"
83+
className={cn(
84+
"h-10 w-full min-w-0 rounded-lg border border-input bg-transparent px-3 py-2 text-sm transition-colors outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
85+
isPassword && (shouldShowGenerator ? "pr-16" : "pr-10"),
86+
className,
87+
)}
88+
ref={setRefs}
89+
{...props}
90+
/>
91+
{isPassword && (
92+
<div className="absolute inset-y-0 right-0 flex items-center gap-1 pr-3 text-muted-foreground">
93+
{shouldShowGenerator && (
9694
<button
9795
type="button"
9896
className="hover:text-foreground focus:outline-none"
99-
onClick={() => setShowPassword(!showPassword)}
97+
onClick={handleGeneratePassword}
98+
aria-label="Generate password"
99+
title="Generate password"
100100
tabIndex={-1}
101101
>
102-
{showPassword ? (
103-
<EyeOffIcon className="h-4 w-4" />
104-
) : (
105-
<EyeIcon className="h-4 w-4" />
106-
)}
102+
<RefreshCcw className="h-4 w-4" />
107103
</button>
108-
</div>
109-
)}
110-
</div>
104+
)}
105+
<button
106+
type="button"
107+
className="hover:text-foreground focus:outline-none"
108+
onClick={() => setShowPassword(!showPassword)}
109+
tabIndex={-1}
110+
>
111+
{showPassword ? (
112+
<EyeOffIcon className="h-4 w-4" />
113+
) : (
114+
<EyeIcon className="h-4 w-4" />
115+
)}
116+
</button>
117+
</div>
118+
)}
119+
</div>
120+
);
121+
122+
return (
123+
<>
124+
{enableCopyButton ? (
125+
<div className="flex w-full items-center space-x-2">
126+
{inputElement}
127+
<Button type="button" variant={"secondary"} onClick={handleCopy}>
128+
<Clipboard className="size-4 text-muted-foreground" />
129+
</Button>
130+
</div>
131+
) : (
132+
inputElement
133+
)}
111134
{errorMessage && (
112135
<span className="text-sm text-red-600 text-secondary-foreground">
113136
{errorMessage}

‎apps/dokploy/server/api/routers/deployment.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export const deploymentRouter = createTRPCRouter({
136136
});
137137
} else if (schedule.serverId) {
138138
const targetServer = await findServerById(schedule.serverId);
139-
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
139+
if (
140+
targetServer.organizationId !== ctx.session.activeOrganizationId
141+
) {
140142
throw new TRPCError({
141143
code: "UNAUTHORIZED",
142144
message: "You don't have access to this schedule.",

0 commit comments

Comments
 (0)