mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-11-04 17:35:15 +00:00
API lib cleanup, 404 hosts WIP
This commit is contained in:
@@ -2,6 +2,7 @@ export * from "./useAccessLists";
|
||||
export * from "./useAuditLog";
|
||||
export * from "./useAuditLogs";
|
||||
export * from "./useCertificates";
|
||||
export * from "./useDeadHost";
|
||||
export * from "./useDeadHosts";
|
||||
export * from "./useHealth";
|
||||
export * from "./useHostReport";
|
||||
|
||||
57
frontend/src/hooks/useDeadHost.ts
Normal file
57
frontend/src/hooks/useDeadHost.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createDeadHost, type DeadHost, getDeadHost, updateDeadHost } from "src/api/backend";
|
||||
|
||||
const fetchDeadHost = (id: number | "new") => {
|
||||
if (id === "new") {
|
||||
return Promise.resolve({
|
||||
id: 0,
|
||||
createdOn: "",
|
||||
modifiedOn: "",
|
||||
ownerUserId: 0,
|
||||
domainNames: [],
|
||||
certificateId: 0,
|
||||
sslForced: false,
|
||||
advancedConfig: "",
|
||||
meta: {},
|
||||
http2Support: false,
|
||||
enabled: true,
|
||||
hstsEnabled: false,
|
||||
hstsSubdomains: false,
|
||||
} as DeadHost);
|
||||
}
|
||||
return getDeadHost(id, ["owner"]);
|
||||
};
|
||||
|
||||
const useDeadHost = (id: number | "new", options = {}) => {
|
||||
return useQuery<DeadHost, Error>({
|
||||
queryKey: ["dead-host", id],
|
||||
queryFn: () => fetchDeadHost(id),
|
||||
staleTime: 60 * 1000, // 1 minute
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
const useSetDeadHost = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (values: DeadHost) => (values.id ? updateDeadHost(values) : createDeadHost(values)),
|
||||
onMutate: (values: DeadHost) => {
|
||||
if (!values.id) {
|
||||
return;
|
||||
}
|
||||
const previousObject = queryClient.getQueryData(["dead-host", values.id]);
|
||||
queryClient.setQueryData(["dead-host", values.id], (old: DeadHost) => ({
|
||||
...old,
|
||||
...values,
|
||||
}));
|
||||
return () => queryClient.setQueryData(["dead-host", values.id], previousObject);
|
||||
},
|
||||
onError: (_, __, rollback: any) => rollback(),
|
||||
onSuccess: async ({ id }: DeadHost) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["dead-host", id] });
|
||||
queryClient.invalidateQueries({ queryKey: ["dead-hosts"] });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { useDeadHost, useSetDeadHost };
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { type DeadHost, type DeadHostExpansion, getDeadHosts } from "src/api/backend";
|
||||
import { type DeadHost, getDeadHosts, type HostExpansion } from "src/api/backend";
|
||||
|
||||
const fetchDeadHosts = (expand?: DeadHostExpansion[]) => {
|
||||
const fetchDeadHosts = (expand?: HostExpansion[]) => {
|
||||
return getDeadHosts(expand);
|
||||
};
|
||||
|
||||
const useDeadHosts = (expand?: DeadHostExpansion[], options = {}) => {
|
||||
const useDeadHosts = (expand?: HostExpansion[], options = {}) => {
|
||||
return useQuery<DeadHost[], Error>({
|
||||
queryKey: ["dead-hosts", { expand }],
|
||||
queryFn: () => fetchDeadHosts(expand),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getRedirectionHosts, type RedirectionHost, type RedirectionHostExpansion } from "src/api/backend";
|
||||
import { getRedirectionHosts, type HostExpansion, type RedirectionHost } from "src/api/backend";
|
||||
|
||||
const fetchRedirectionHosts = (expand?: RedirectionHostExpansion[]) => {
|
||||
const fetchRedirectionHosts = (expand?: HostExpansion[]) => {
|
||||
return getRedirectionHosts(expand);
|
||||
};
|
||||
|
||||
const useRedirectionHosts = (expand?: RedirectionHostExpansion[], options = {}) => {
|
||||
const useRedirectionHosts = (expand?: HostExpansion[], options = {}) => {
|
||||
return useQuery<RedirectionHost[], Error>({
|
||||
queryKey: ["redirection-hosts", { expand }],
|
||||
queryFn: () => fetchRedirectionHosts(expand),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getStreams, type Stream, type StreamExpansion } from "src/api/backend";
|
||||
import { getStreams, type HostExpansion, type Stream } from "src/api/backend";
|
||||
|
||||
const fetchStreams = (expand?: StreamExpansion[]) => {
|
||||
const fetchStreams = (expand?: HostExpansion[]) => {
|
||||
return getStreams(expand);
|
||||
};
|
||||
|
||||
const useStreams = (expand?: StreamExpansion[], options = {}) => {
|
||||
const useStreams = (expand?: HostExpansion[], options = {}) => {
|
||||
return useQuery<Stream[], Error>({
|
||||
queryKey: ["streams", { expand }],
|
||||
queryFn: () => fetchStreams(expand),
|
||||
|
||||
@@ -15,7 +15,7 @@ const fetchUser = (id: number | string) => {
|
||||
avatar: "",
|
||||
} as User);
|
||||
}
|
||||
return getUser(id, { expand: "permissions" });
|
||||
return getUser(id, ["permissions"]);
|
||||
};
|
||||
|
||||
const useUser = (id: string | number, options = {}) => {
|
||||
|
||||
Reference in New Issue
Block a user