chore: clean up unused variables and improve error handling across codebase

This commit focuses on removing unused variables, adding placeholder error handling, and generally tidying up various files across the Dokploy application. Changes include:

- Removing unused imports and variables
- Adding placeholder error handling in catch blocks
- Cleaning up commented-out code
- Removing deprecated utility files
- Improving type safety and code consistency
This commit is contained in:
Mauricio Siu
2025-02-22 20:35:21 -06:00
parent 1a415b96c9
commit 8ab6d6b282
132 changed files with 375 additions and 471 deletions

View File

@@ -38,7 +38,7 @@ export const calculatePrice = (count: number, isAnnual = false) => {
return count * 3.5;
};
export const ShowBilling = () => {
const { data: servers } = api.server.all.useQuery(undefined);
const { data: servers } = api.server.count.useQuery();
const { data: admin } = api.user.get.useQuery();
const { data, isLoading } = api.stripe.getProducts.useQuery();
const { mutateAsync: createCheckoutSession } =
@@ -71,7 +71,7 @@ export const ShowBilling = () => {
});
const maxServers = admin?.user.serversQuantity ?? 1;
const percentage = ((servers?.length ?? 0) / maxServers) * 100;
const percentage = ((servers ?? 0) / maxServers) * 100;
const safePercentage = Math.min(percentage, 100);
return (
@@ -102,13 +102,13 @@ export const ShowBilling = () => {
<div className="space-y-2 flex flex-col">
<h3 className="text-lg font-medium">Servers Plan</h3>
<p className="text-sm text-muted-foreground">
You have {servers?.length} server on your plan of{" "}
You have {servers} server on your plan of{" "}
{admin?.user.serversQuantity} servers
</p>
<div>
<Progress value={safePercentage} className="max-w-lg" />
</div>
{admin && admin.user.serversQuantity! <= servers?.length! && (
{admin && admin.user.serversQuantity! <= (servers ?? 0) && (
<div className="flex flex-row gap-4 p-2 bg-yellow-50 dark:bg-yellow-950 rounded-lg items-center">
<AlertTriangle className="text-yellow-600 dark:text-yellow-400" />
<span className="text-sm text-yellow-600 dark:text-yellow-400">

View File

@@ -41,8 +41,7 @@ export const ShowNodes = () => {
const { data, isLoading, refetch } = api.cluster.getNodes.useQuery();
const { data: registry } = api.registry.all.useQuery();
const { mutateAsync: deleteNode, isLoading: isRemoving } =
api.cluster.removeWorker.useMutation();
const { mutateAsync: deleteNode } = api.cluster.removeWorker.useMutation();
const haveAtLeastOneRegistry = !!(registry && registry?.length > 0);
return (

View File

@@ -131,7 +131,7 @@ export const HandleRegistry = ({ registryId }: Props) => {
serverId: data.serverId,
registryId: registryId || "",
})
.then(async (data) => {
.then(async (_data) => {
await utils.registry.all.invalidate();
toast.success(registryId ? "Registry updated" : "Registry added");
setIsOpen(false);

View File

@@ -47,10 +47,10 @@ type Schema = z.infer<typeof Schema>;
export const AddBitbucketProvider = () => {
const utils = api.useUtils();
const [isOpen, setIsOpen] = useState(false);
const url = useUrl();
const _url = useUrl();
const { mutateAsync, error, isError } = api.bitbucket.create.useMutation();
const { data: auth } = api.user.get.useQuery();
const router = useRouter();
const _router = useRouter();
const form = useForm<Schema>({
defaultValues: {
username: "",

View File

@@ -102,7 +102,7 @@ export const ShowGitProviders = () => {
</div>
<div className="flex flex-col gap-4 rounded-lg ">
{data?.map((gitProvider, index) => {
{data?.map((gitProvider, _index) => {
const isGithub = gitProvider.providerType === "github";
const isGitlab = gitProvider.providerType === "gitlab";
const isBitbucket =

View File

@@ -136,7 +136,7 @@ export const HandleNotifications = ({ notificationId }: Props) => {
const [visible, setVisible] = useState(false);
const { data: isCloud } = api.settings.isCloud.useQuery();
const { data: notification, refetch } = api.notification.one.useQuery(
const { data: notification } = api.notification.one.useQuery(
{
notificationId: notificationId || "",
},
@@ -1038,7 +1038,7 @@ export const HandleNotifications = ({ notificationId }: Props) => {
});
}
toast.success("Connection Success");
} catch (err) {
} catch (_err) {
toast.error("Error testing the provider");
}
}}

View File

@@ -56,7 +56,7 @@ export const ShowNotifications = () => {
) : (
<div className="flex flex-col gap-4 min-h-[25vh]">
<div className="flex flex-col gap-4 rounded-lg ">
{data?.map((notification, index) => (
{data?.map((notification, _index) => (
<div
key={notification.notificationId}
className="flex items-center justify-between bg-sidebar p-1 w-full rounded-lg"

View File

@@ -63,7 +63,7 @@ export const Disable2FA = () => {
toast.success("2FA disabled successfully");
utils.auth.get.invalidate();
setIsOpen(false);
} catch (error) {
} catch (_error) {
form.setError("password", {
message: "Connection error. Please try again.",
});

View File

@@ -47,20 +47,8 @@ const PinSchema = z.object({
type PasswordForm = z.infer<typeof PasswordSchema>;
type PinForm = z.infer<typeof PinSchema>;
type TwoFactorEnableResponse = {
totpURI: string;
backupCodes: string[];
};
type TwoFactorSetupData = {
qrCodeUrl: string;
secret: string;
totpURI: string;
};
export const Enable2FA = () => {
const utils = api.useUtils();
const { data: session } = authClient.useSession();
const [data, setData] = useState<TwoFactorSetupData | null>(null);
const [backupCodes, setBackupCodes] = useState<string[]>([]);
const [isDialogOpen, setIsDialogOpen] = useState(false);

View File

@@ -54,9 +54,7 @@ const randomImages = [
];
export const ProfileForm = () => {
const utils = api.useUtils();
const { mutateAsync: disable2FA, isLoading: isDisabling } =
api.auth.disable2FA.useMutation();
const _utils = api.useUtils();
const { data, refetch, isLoading } = api.user.get.useQuery();
const {
mutateAsync,

View File

@@ -26,7 +26,7 @@ export const ShowStorageActions = ({ serverId }: Props) => {
isLoading: cleanDockerBuilderIsLoading,
} = api.settings.cleanDockerBuilder.useMutation();
const { mutateAsync: cleanMonitoring, isLoading: cleanMonitoringIsLoading } =
const { mutateAsync: cleanMonitoring } =
api.settings.cleanMonitoring.useMutation();
const {
mutateAsync: cleanUnusedImages,

View File

@@ -36,7 +36,7 @@ export const ToggleDockerCleanup = ({ serverId }: Props) => {
await refetch();
}
toast.success("Docker Cleanup updated");
} catch (error) {
} catch (_error) {
toast.error("Docker Cleanup Error");
}
};

View File

@@ -82,7 +82,7 @@ export const EditScript = ({ serverId }: Props) => {
command: formData.command || "",
serverId,
})
.then((data) => {
.then((_data) => {
toast.success("Script modified successfully");
})
.catch(() => {

View File

@@ -56,7 +56,7 @@ export function GPUSupport({ serverId }: GPUSupportProps) {
try {
await utils.settings.checkGPUStatus.invalidate({ serverId });
await refetch();
} catch (error) {
} catch (_error) {
toast.error("Failed to refresh GPU status");
} finally {
setIsRefreshing(false);
@@ -74,7 +74,7 @@ export function GPUSupport({ serverId }: GPUSupportProps) {
try {
await setupGPU.mutateAsync({ serverId });
} catch (error) {
} catch (_error) {
// Error handling is done in mutation's onError
}
};

View File

@@ -118,7 +118,7 @@ export const HandleServers = ({ serverId }: Props) => {
sshKeyId: data.sshKeyId || "",
serverId: serverId || "",
})
.then(async (data) => {
.then(async (_data) => {
await utils.server.all.invalidate();
refetchServer();
toast.success(serverId ? "Server Updated" : "Server Created");

View File

@@ -25,7 +25,7 @@ export const SecurityAudit = ({ serverId }: Props) => {
enabled: !!serverId,
},
);
const utils = api.useUtils();
const _utils = api.useUtils();
return (
<CardContent className="p-0">
<div className="flex flex-col gap-4">

View File

@@ -80,7 +80,7 @@ const Schema = z.object({
type Schema = z.infer<typeof Schema>;
export const SetupMonitoring = ({ serverId }: Props) => {
const { data, isLoading } = serverId
const { data } = serverId
? api.server.one.useQuery(
{
serverId: serverId || "",

View File

@@ -25,7 +25,7 @@ export const ValidateServer = ({ serverId }: Props) => {
enabled: !!serverId,
},
);
const utils = api.useUtils();
const _utils = api.useUtils();
return (
<CardContent className="p-0">
<div className="flex flex-col gap-4">

View File

@@ -52,10 +52,10 @@ interface Props {
export const CreateServer = ({ stepper }: Props) => {
const { data: sshKeys } = api.sshKey.all.useQuery();
const [isOpen, setIsOpen] = useState(false);
const [isOpen, _setIsOpen] = useState(false);
const { data: canCreateMoreServers, refetch } =
api.stripe.canCreateMoreServers.useQuery();
const { mutateAsync, error, isError } = api.server.create.useMutation();
const { mutateAsync } = api.server.create.useMutation();
const cloudSSHKey = sshKeys?.find(
(sshKey) => sshKey.name === "dokploy-cloud-ssh-key",
);
@@ -96,7 +96,7 @@ export const CreateServer = ({ stepper }: Props) => {
username: data.username || "root",
sshKeyId: data.sshKeyId || "",
})
.then(async (data) => {
.then(async (_data) => {
toast.success("Server Created");
stepper.next();
})

View File

@@ -37,15 +37,6 @@ export const Verify = () => {
);
const [isRefreshing, setIsRefreshing] = useState(false);
const { data: server } = api.server.one.useQuery(
{
serverId,
},
{
enabled: !!serverId,
},
);
return (
<CardContent className="p-0">
<div className="flex flex-col gap-4">

View File

@@ -143,7 +143,7 @@ export const ShowInvitations = () => {
{invitation.status === "pending" && (
<DropdownMenuItem
className="w-full cursor-pointer"
onSelect={(e) => {
onSelect={(_e) => {
copy(
`${origin}/invitation?token=${invitation.id}`,
);
@@ -159,7 +159,7 @@ export const ShowInvitations = () => {
{invitation.status === "pending" && (
<DropdownMenuItem
className="w-full cursor-pointer"
onSelect={async (e) => {
onSelect={async (_e) => {
const result =
await authClient.organization.cancelInvitation(
{

View File

@@ -35,7 +35,7 @@ import { AddUserPermissions } from "./add-permissions";
export const ShowUsers = () => {
const { data: isCloud } = api.settings.isCloud.useQuery();
const { data, isLoading, refetch } = api.user.all.useQuery();
const { mutateAsync, isLoading: isRemoving } = api.user.remove.useMutation();
const { mutateAsync } = api.user.remove.useMutation();
return (
<div className="w-full">

View File

@@ -14,10 +14,7 @@ import { ShowTraefikActions } from "./servers/actions/show-traefik-actions";
import { ToggleDockerCleanup } from "./servers/actions/toggle-docker-cleanup";
import { UpdateServer } from "./web-server/update-server";
interface Props {
className?: string;
}
export const WebServer = ({ className }: Props) => {
export const WebServer = () => {
const { t } = useTranslation("settings");
const { data } = api.user.get.useQuery();

View File

@@ -99,7 +99,7 @@ export const ManageTraefikPorts = ({ children, serverId }: Props) => {
});
toast.success(t("settings.server.webServer.traefik.portsUpdated"));
setOpen(false);
} catch (error) {
} catch (_error) {
toast.error(t("settings.server.webServer.traefik.portsUpdateError"));
}
};

View File

@@ -43,7 +43,7 @@ interface Props {
serverId?: string;
}
export const UpdateServerIp = ({ children, serverId }: Props) => {
export const UpdateServerIp = ({ children }: Props) => {
const [isOpen, setIsOpen] = useState(false);
const { data } = api.user.get.useQuery();