mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 07:35:09 +00:00
Continue removing unused frontend components/logic, improve querying in select pages
This commit is contained in:
@@ -8,18 +8,16 @@ const incidentContactKeys = {
|
||||
getAllContact: (orgId: string) => ["org-incident-contacts", { orgId }] as const
|
||||
};
|
||||
|
||||
const fetchOrgIncidentContacts = async (orgId: string) => {
|
||||
const { data } = await apiRequest.get<{ incidentContactsOrg: IncidentContact[] }>(
|
||||
`/api/v1/organization/${orgId}/incidentContactOrg`
|
||||
);
|
||||
|
||||
return data.incidentContactsOrg;
|
||||
};
|
||||
|
||||
export const useGetOrgIncidentContact = (orgId: string) =>
|
||||
useQuery({
|
||||
queryKey: incidentContactKeys.getAllContact(orgId),
|
||||
queryFn: () => fetchOrgIncidentContacts(orgId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ incidentContactsOrg: IncidentContact[] }>(
|
||||
`/api/v1/organization/${orgId}/incidentContactOrg`
|
||||
);
|
||||
|
||||
return data.incidentContactsOrg;
|
||||
},
|
||||
enabled: Boolean(orgId)
|
||||
});
|
||||
|
||||
|
||||
@@ -32,4 +32,4 @@ export const useDeleteIntegration = () => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIntegrations(workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -41,8 +41,10 @@ export const useRenameOrg = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, RenameOrgDTO>({
|
||||
mutationFn: ({ newOrgName, orgId }) =>
|
||||
apiRequest.patch(`/api/v1/organization/${orgId}/name`, { name: newOrgName }),
|
||||
mutationFn: ({ newOrgName, orgId }) => {
|
||||
console.log("useRenameOrg");
|
||||
return apiRequest.patch(`/api/v1/organization/${orgId}/name`, { name: newOrgName });
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(organizationKeys.getUserOrganizations);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
UserWsTags
|
||||
} from "./types";
|
||||
|
||||
|
||||
const workspaceTags = {
|
||||
getWsTags: (workspaceID: string) => ["workspace-tags", { workspaceID }] as const
|
||||
};
|
||||
@@ -23,12 +22,13 @@ const fetchWsTag = async (workspaceID: string) => {
|
||||
return data.workspaceTags;
|
||||
};
|
||||
|
||||
export const useGetWsTags = (workspaceID: string) =>
|
||||
useQuery({
|
||||
export const useGetWsTags = (workspaceID: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceTags.getWsTags(workspaceID),
|
||||
queryFn: () => fetchWsTag(workspaceID),
|
||||
enabled: Boolean(workspaceID)
|
||||
});
|
||||
}
|
||||
|
||||
export const useCreateWsTag = () => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -59,4 +59,4 @@ export const useDeleteWsTag = () => {
|
||||
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -3,10 +3,8 @@ export {
|
||||
useAddUserToOrg,
|
||||
useAddUserToWs,
|
||||
useCreateAPIKey,
|
||||
useCreateMyAction,
|
||||
useDeleteAPIKey,
|
||||
useDeleteOrgMembership,
|
||||
useGetMyActions,
|
||||
useGetMyAPIKeys,
|
||||
useGetMyIp,
|
||||
useGetMySessions,
|
||||
|
||||
@@ -158,8 +158,9 @@ export const useDeleteOrgMembership = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, DeletOrgMembershipDTO>({
|
||||
mutationFn: ({ membershipId, orgId }) =>
|
||||
apiRequest.delete(`/api/v2/organizations/${orgId}/memberships/${membershipId}`),
|
||||
mutationFn: ({ membershipId, orgId }) => {
|
||||
return apiRequest.delete(`/api/v2/organizations/${orgId}/memberships/${membershipId}`)
|
||||
},
|
||||
onSuccess: (_, { orgId }) => {
|
||||
queryClient.invalidateQueries(userKeys.getOrgUsers(orgId));
|
||||
}
|
||||
@@ -170,10 +171,11 @@ export const useUpdateOrgUserRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, UpdateOrgUserRoleDTO>({
|
||||
mutationFn: ({ organizationId, membershipId, role }) =>
|
||||
apiRequest.patch(`/api/v2/organizations/${organizationId}/memberships/${membershipId}`, {
|
||||
mutationFn: ({ organizationId, membershipId, role }) => {
|
||||
return apiRequest.patch(`/api/v2/organizations/${organizationId}/memberships/${membershipId}`, {
|
||||
role
|
||||
}),
|
||||
});
|
||||
},
|
||||
onSuccess: (_, { organizationId }) => {
|
||||
queryClient.invalidateQueries(userKeys.getOrgUsers(organizationId));
|
||||
},
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export {
|
||||
useAddUserToWorkspace,
|
||||
useCreateWorkspace,
|
||||
useCreateWsEnvironment,
|
||||
useDeleteUserFromWorkspace,
|
||||
useDeleteWorkspace,
|
||||
useDeleteWsEnvironment,
|
||||
useGetUserWorkspaceMemberships,
|
||||
@@ -11,8 +13,9 @@ export {
|
||||
useGetWorkspaceIndexStatus,
|
||||
useGetWorkspaceIntegrations,
|
||||
useGetWorkspaceSecrets,
|
||||
useGetWorkspaceUsers,
|
||||
useNameWorkspaceSecrets,
|
||||
useRenameWorkspace,
|
||||
useToggleAutoCapitalization,
|
||||
useUpdateWsEnvironment
|
||||
} from "./queries";
|
||||
useUpdateUserWorkspaceRole,
|
||||
useUpdateWsEnvironment} from "./queries";
|
||||
|
||||
@@ -29,7 +29,8 @@ export const workspaceKeys = {
|
||||
getWorkspaceIntegrations: (workspaceId: string) => [{ workspaceId }, "workspace-integrations"],
|
||||
getAllUserWorkspace: ["workspaces"] as const,
|
||||
getUserWsEnvironments: (workspaceId: string) => ["workspace-env", { workspaceId }] as const,
|
||||
getWorkspaceAuditLogs: (workspaceId: string) => [{ workspaceId }] as const
|
||||
getWorkspaceAuditLogs: (workspaceId: string) => [{ workspaceId }] as const,
|
||||
getWorkspaceUsers: (workspaceId: string) => [{ workspaceId }] as const
|
||||
};
|
||||
|
||||
const fetchWorkspaceById = async (workspaceId: string) => {
|
||||
@@ -218,7 +219,9 @@ export const useDeleteWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, DeleteWorkspaceDTO>({
|
||||
mutationFn: ({ workspaceID }) => apiRequest.delete(`/api/v1/workspace/${workspaceID}`),
|
||||
mutationFn: ({ workspaceID }) => {
|
||||
return apiRequest.delete(`/api/v1/workspace/${workspaceID}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getAllUserWorkspace);
|
||||
}
|
||||
@@ -273,3 +276,74 @@ export const useDeleteWsEnvironment = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetWorkspaceUsers = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceUsers(workspaceId),
|
||||
queryFn: async () => {
|
||||
const { data: { users } } = await apiRequest.get(
|
||||
`/api/v1/workspace/${workspaceId}/users`
|
||||
);
|
||||
return users;
|
||||
},
|
||||
enabled: true
|
||||
});
|
||||
}
|
||||
|
||||
export const useAddUserToWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
email,
|
||||
workspaceId
|
||||
}: {
|
||||
email: string;
|
||||
workspaceId: string;
|
||||
}) => {
|
||||
const { data: { invitee, latestKey } } = await apiRequest.post(`/api/v1/workspace/${workspaceId}/invite-signup`, { email });
|
||||
|
||||
return ({
|
||||
invitee,
|
||||
latestKey
|
||||
});
|
||||
},
|
||||
onSuccess: (_, dto) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(dto.workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteUserFromWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (membershipId: string) => {
|
||||
const { data: { deletedMembership } } = await apiRequest.delete(`/api/v1/membership/${membershipId}`);
|
||||
return deletedMembership;
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(res.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateUserWorkspaceRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
membershipId,
|
||||
role
|
||||
}: {
|
||||
membershipId: string;
|
||||
role: string;
|
||||
}) => {
|
||||
const { data: { membership } } = await apiRequest.post(`/api/v1/membership/${membershipId}/change-role`, {
|
||||
role
|
||||
});
|
||||
return membership;
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceUsers(res.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user