mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 12:04:03 +00:00
feat(ui): added api hooks and state hooks for dashboard
This commit is contained in:
@@ -7,16 +7,19 @@ import {
|
||||
CreateWorkspaceDTO,
|
||||
DeleteEnvironmentDTO,
|
||||
DeleteWorkspaceDTO,
|
||||
GetWsEnvironmentDTO,
|
||||
RenameWorkspaceDTO,
|
||||
ToggleAutoCapitalizationDTO,
|
||||
UpdateEnvironmentDTO,
|
||||
Workspace
|
||||
Workspace,
|
||||
WorkspaceEnv
|
||||
} from './types';
|
||||
|
||||
const workspaceKeys = {
|
||||
getWorkspaceById: (workspaceId: string) => [{ workspaceId }, 'workspace'] as const,
|
||||
getWorkspaceMemberships: (orgId: string) => [{ orgId }, 'workspace-memberships'],
|
||||
getAllUserWorkspace: ['workspaces'] as const
|
||||
getAllUserWorkspace: ['workspaces'] as const,
|
||||
getUserWsEnvironments: (workspaceId: string) => ['workspace-env', { workspaceId }] as const
|
||||
};
|
||||
|
||||
const fetchWorkspaceById = async (workspaceId: string) => {
|
||||
@@ -49,6 +52,21 @@ const fetchUserWorkspaceMemberships = async (orgId: string) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
const fetchUserWsEnvironments = async (workspaceId: string) => {
|
||||
const { data } = await apiRequest.get<{ accessibleEnvironments: WorkspaceEnv[] }>(
|
||||
`/api/v2/workspace/${workspaceId}/environments`
|
||||
);
|
||||
return data.accessibleEnvironments;
|
||||
};
|
||||
|
||||
export const useGetUserWsEnvironments = ({ workspaceId, onSuccess }: GetWsEnvironmentDTO) =>
|
||||
useQuery({
|
||||
enabled: Boolean(workspaceId),
|
||||
onSuccess,
|
||||
queryKey: workspaceKeys.getUserWsEnvironments(workspaceId),
|
||||
queryFn: () => fetchUserWsEnvironments(workspaceId)
|
||||
});
|
||||
|
||||
// to get all userids in an org with the workspace they are part of
|
||||
export const useGetUserWorkspaceMemberships = (orgId: string) =>
|
||||
useQuery({
|
||||
|
||||
Reference in New Issue
Block a user