Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("Host rule format regression tests", () => {
host: "example.com",
port: 8080,
https: false,
enabled: true,
uniqueConfigKey: 1,
customCertResolver: null,
certificateType: "none",
Expand Down
1 change: 1 addition & 0 deletions apps/dokploy/__test__/compose/domain/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("createDomainLabels", () => {
port: 8080,
customEntrypoint: null,
https: false,
enabled: true,
uniqueConfigKey: 1,
customCertResolver: null,
certificateType: "none",
Expand Down
1 change: 1 addition & 0 deletions apps/dokploy/__test__/traefik/traefik.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const baseDomain: Domain = {
domainId: "",
host: "",
https: false,
enabled: true,
path: null,
port: null,
customEntrypoint: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type { RouterOutputs } from "@/utils/api";
import { DnsHelperModal } from "./dns-helper-modal";
import { AddDomain } from "./handle-domain";
import type { ValidationStates } from "./show-domains";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";

export type Domain =
| RouterOutputs["domain"]["byApplicationId"][0]
Expand All @@ -39,6 +41,7 @@ interface ColumnsProps {
serverIp?: string;
canCreateDomain: boolean;
canDeleteDomain: boolean;
handleToggleDomain: (domainId: string, enabled: boolean) => Promise<void>;
}

export const createColumns = ({
Expand All @@ -47,6 +50,7 @@ export const createColumns = ({
validationStates,
handleValidateDomain,
handleDeleteDomain,
handleToggleDomain,
isDeleting,
serverIp,
canCreateDomain,
Expand Down Expand Up @@ -225,6 +229,24 @@ export const createColumns = ({
);
},
},
{
accessorKey: "enabled",
header: "Enabled",
cell: ({ row }) => {
const domain = row.original;
return (
<Switch
checked={domain.enabled}
onCheckedChange={async (checked) => {
await handleToggleDomain(domain.domainId, checked);
}}
className={cn("bg-white", {
"bg-muted-foreground": !domain.enabled,
})}
/>
);
},
},
{
accessorKey: "createdAt",
header: ({ column }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
XCircle,
} from "lucide-react";
import Link from "next/link";
import { useState } from "react";
import { useMemo, useState } from "react";
import { toast } from "sonner";
import { DialogAction } from "@/components/shared/dialog-action";
import { Badge } from "@/components/ui/badge";
Expand Down Expand Up @@ -62,6 +62,8 @@ import { api } from "@/utils/api";
import { createColumns } from "./columns";
import { DnsHelperModal } from "./dns-helper-modal";
import { AddDomain } from "./handle-domain";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";

export type ValidationState = {
isLoading: boolean;
Expand All @@ -80,6 +82,7 @@ interface Props {
}

export const ShowDomains = ({ id, type }: Props) => {

const { data: permissions } = api.user.getPermissions.useQuery();
const canCreateDomain = permissions?.domain.create ?? false;
const canDeleteDomain = permissions?.domain.delete ?? false;
Expand Down Expand Up @@ -145,6 +148,18 @@ export const ShowDomains = ({ id, type }: Props) => {
api.domain.validateDomain.useMutation();
const { mutateAsync: deleteDomain, isPending: isRemoving } =
api.domain.delete.useMutation();
const { mutateAsync: updateDomain } =
api.domain.update.useMutation();

const handleToggleDomain = async (domainId: string, enabled: boolean) => {
try {
await updateDomain({ domainId, enabled });
refetch();
toast.success(`Domain ${enabled ? "enabled" : "disabled"} successfully`);
} catch {
toast.error(`Error ${enabled ? "enabling" : "disabling"} domain`);
}
};

const handleDeleteDomain = async (domainId: string) => {
try {
Expand Down Expand Up @@ -193,17 +208,30 @@ export const ShowDomains = ({ id, type }: Props) => {
}
};

const columns = createColumns({
const columns = useMemo(() => createColumns({
id,
type,
validationStates,
handleValidateDomain,
handleDeleteDomain,
handleToggleDomain,
isDeleting: isRemoving,
serverIp: application?.server?.ipAddress?.toString() || ip?.toString(),
canCreateDomain,
canDeleteDomain,
});
}), [
id,
type,
validationStates,
handleValidateDomain,
handleDeleteDomain,
handleToggleDomain,
isRemoving,
application?.server?.ipAddress,
ip,
canCreateDomain,
canDeleteDomain,
]);

const table = useReactTable({
data: data ?? [],
Expand Down Expand Up @@ -424,7 +452,7 @@ export const ShowDomains = ({ id, type }: Props) => {
{item.serviceName}
</Badge>
)}
<div className="flex gap-2 flex-wrap">
<div className="flex gap-2 flex-wrap items-center">
{!item.host.includes("sslip.io") && (
<DnsHelperModal
domain={{
Expand All @@ -438,6 +466,26 @@ export const ShowDomains = ({ id, type }: Props) => {
}
/>
)}

<TooltipProvider>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Switch
checked={item.enabled}
onCheckedChange={async (checked) => {
await handleToggleDomain(item.domainId, checked);
}}
className={cn("bg-white", {
"bg-muted-foreground": !item.enabled,
})}
/>
</TooltipTrigger>
<TooltipContent>
<p>Enable or disable the domain.</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>

{canCreateDomain && (
<AddDomain
id={id}
Expand Down
1 change: 1 addition & 0 deletions apps/dokploy/drizzle/0167_same_junta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "domain" ADD COLUMN "enabled" boolean DEFAULT true NOT NULL;
Loading