feat: completed frontend

This commit is contained in:
=
2025-02-26 20:45:37 +05:30
parent 78718cd299
commit f34370cb9d
11 changed files with 316 additions and 18 deletions
@@ -54,6 +54,7 @@ export type TDynamicSecretProvider =
revocationStatement: string;
renewStatement?: string;
ca?: string | undefined;
gatewayId?: string;
};
}
| {
+1 -1
View File
@@ -1,2 +1,2 @@
export { useDeleteGateway } from "./mutation";
export { useDeleteGatewayById, useUpdateGatewayById } from "./mutation";
export { gatewaysQueryKeys } from "./queries";
+15 -2
View File
@@ -3,15 +3,28 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { gatewaysQueryKeys } from "./queries";
import { TUpdateGatewayDTO } from "./types";
export const useDeleteGateway = () => {
export const useDeleteGatewayById = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => {
return apiRequest.delete(`/api/v1/gateways/${id}`);
},
onSuccess: () => {
queryClient.invalidateQueries(gatewaysQueryKeys.list());
queryClient.invalidateQueries(gatewaysQueryKeys.list({}));
}
});
};
export const useUpdateGatewayById = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, name }: TUpdateGatewayDTO) => {
return apiRequest.patch(`/api/v1/gateways/${id}`, { name });
},
onSuccess: () => {
queryClient.invalidateQueries(gatewaysQueryKeys.list({}));
}
});
};
+11 -5
View File
@@ -2,16 +2,22 @@ import { queryOptions } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TGateway } from "./types";
import { TGateway, TListGatewayDTO } from "./types";
export const gatewaysQueryKeys = {
allKey: () => ["gateways"],
listKey: () => [...gatewaysQueryKeys.allKey(), "list"],
list: () =>
listKey: ({ projectId }: TListGatewayDTO) => [
...gatewaysQueryKeys.allKey(),
"list",
{ projectId }
],
list: ({ projectId }: TListGatewayDTO = {}) =>
queryOptions({
queryKey: gatewaysQueryKeys.listKey(),
queryKey: gatewaysQueryKeys.listKey({ projectId }),
queryFn: async () => {
const { data } = await apiRequest.get<{ gateways: TGateway[] }>("/api/v1/gateways");
const { data } = await apiRequest.get<{ gateways: TGateway[] }>("/api/v1/gateways", {
params: { projectId }
});
return data.gateways;
}
})
+9
View File
@@ -12,6 +12,15 @@ export type TGateway = {
};
};
export type TUpdateGatewayDTO = {
id: string;
name?: string;
};
export type TDeleteGatewayDTO = {
id: string;
};
export type TListGatewayDTO = {
projectId?: string;
};