mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 10:35:17 +00:00
misc: migrated groups API to use ids instead of slug
This commit is contained in:
@@ -38,17 +38,17 @@ export const useUpdateGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
currentSlug,
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
}: {
|
||||
currentSlug: string;
|
||||
id: string;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
role?: string;
|
||||
}) => {
|
||||
const { data: group } = await apiRequest.patch<TGroup>(`/api/v1/groups/${currentSlug}`, {
|
||||
const { data: group } = await apiRequest.patch<TGroup>(`/api/v1/groups/${id}`, {
|
||||
name,
|
||||
slug,
|
||||
role
|
||||
@@ -65,8 +65,8 @@ export const useUpdateGroup = () => {
|
||||
export const useDeleteGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug }: { slug: string }) => {
|
||||
const { data: group } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}`);
|
||||
mutationFn: async ({ id }: { id: string }) => {
|
||||
const { data: group } = await apiRequest.delete<TGroup>(`/api/v1/groups/${id}`);
|
||||
|
||||
return group;
|
||||
},
|
||||
@@ -79,8 +79,15 @@ export const useDeleteGroup = () => {
|
||||
export const useAddUserToGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||
const { data } = await apiRequest.post<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
mutationFn: async ({
|
||||
groupId,
|
||||
username
|
||||
}: {
|
||||
groupId: string;
|
||||
username: string;
|
||||
slug: string;
|
||||
}) => {
|
||||
const { data } = await apiRequest.post<TGroup>(`/api/v1/groups/${groupId}/users/${username}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
@@ -93,8 +100,17 @@ export const useAddUserToGroup = () => {
|
||||
export const useRemoveUserFromGroup = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ slug, username }: { slug: string; username: string }) => {
|
||||
const { data } = await apiRequest.delete<TGroup>(`/api/v1/groups/${slug}/users/${username}`);
|
||||
mutationFn: async ({
|
||||
username,
|
||||
groupId
|
||||
}: {
|
||||
slug: string;
|
||||
username: string;
|
||||
groupId: string;
|
||||
}) => {
|
||||
const { data } = await apiRequest.delete<TGroup>(
|
||||
`/api/v1/groups/${groupId}/users/${username}`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -4,7 +4,8 @@ import { apiRequest } from "@app/config/request";
|
||||
|
||||
export const groupKeys = {
|
||||
allGroupUserMemberships: () => ["group-user-memberships"] as const,
|
||||
forGroupUserMemberships: (slug: string) => [...groupKeys.allGroupUserMemberships(), slug] as const,
|
||||
forGroupUserMemberships: (slug: string) =>
|
||||
[...groupKeys.allGroupUserMemberships(), slug] as const,
|
||||
specificGroupUserMemberships: ({
|
||||
slug,
|
||||
offset,
|
||||
@@ -28,11 +29,13 @@ type TUser = {
|
||||
};
|
||||
|
||||
export const useListGroupUsers = ({
|
||||
id,
|
||||
groupSlug,
|
||||
offset = 0,
|
||||
limit = 10,
|
||||
username
|
||||
}: {
|
||||
id: string;
|
||||
groupSlug: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
@@ -52,14 +55,15 @@ export const useListGroupUsers = ({
|
||||
limit: String(limit),
|
||||
username
|
||||
});
|
||||
|
||||
const { data } = await apiRequest.get<{ users: TUser[]; totalCount: number; }>(
|
||||
`/api/v1/groups/${groupSlug}/users`, {
|
||||
|
||||
const { data } = await apiRequest.get<{ users: TUser[]; totalCount: number }>(
|
||||
`/api/v1/groups/${id}/users`,
|
||||
{
|
||||
params
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return data;
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
+4
@@ -35,10 +35,12 @@ export const OrgGroupMembersModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
const [searchMemberFilter, setSearchMemberFilter] = useState("");
|
||||
|
||||
const popUpData = popUp?.groupMembers?.data as {
|
||||
groupId: string;
|
||||
slug: string;
|
||||
};
|
||||
|
||||
const { data, isLoading } = useListGroupUsers({
|
||||
id: popUpData?.groupId,
|
||||
groupSlug: popUpData?.slug,
|
||||
offset: (page - 1) * perPage,
|
||||
limit: perPage,
|
||||
@@ -54,11 +56,13 @@ export const OrgGroupMembersModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
|
||||
if (assign) {
|
||||
await assignMutateAsync({
|
||||
groupId: popUpData.groupId,
|
||||
username,
|
||||
slug: popUpData.slug
|
||||
});
|
||||
} else {
|
||||
await unassignMutateAsync({
|
||||
groupId: popUpData.groupId,
|
||||
username,
|
||||
slug: popUpData.slug
|
||||
});
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
|
||||
|
||||
if (group) {
|
||||
await updateMutateAsync({
|
||||
currentSlug: group.slug,
|
||||
id: group.groupId,
|
||||
name,
|
||||
slug,
|
||||
role: role || undefined
|
||||
|
||||
+3
-3
@@ -34,10 +34,10 @@ export const OrgGroupsSection = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteGroupSubmit = async ({ name, slug }: { name: string; slug: string }) => {
|
||||
const onDeleteGroupSubmit = async ({ name, groupId }: { name: string; groupId: string }) => {
|
||||
try {
|
||||
await deleteMutateAsync({
|
||||
slug
|
||||
id: groupId
|
||||
});
|
||||
createNotification({
|
||||
text: `Successfully deleted the group named ${name}`,
|
||||
@@ -87,7 +87,7 @@ export const OrgGroupsSection = () => {
|
||||
onChange={(isOpen) => handlePopUpToggle("deleteGroup", isOpen)}
|
||||
deleteKey="confirm"
|
||||
onDeleteApproved={() =>
|
||||
onDeleteGroupSubmit(popUp?.deleteGroup?.data as { name: string; slug: string })
|
||||
onDeleteGroupSubmit(popUp?.deleteGroup?.data as { name: string; groupId: string })
|
||||
}
|
||||
/>
|
||||
<UpgradePlanModal
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { faEllipsis,faMagnifyingGlass, faUsers } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faEllipsis, faMagnifyingGlass, faUsers } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
@@ -52,10 +52,10 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
|
||||
|
||||
const { data: roles } = useGetOrgRoles(orgId);
|
||||
|
||||
const handleChangeRole = async ({ currentSlug, role }: { currentSlug: string; role: string }) => {
|
||||
const handleChangeRole = async ({ id, role }: { id: string; role: string }) => {
|
||||
try {
|
||||
await updateMutateAsync({
|
||||
currentSlug,
|
||||
id,
|
||||
role
|
||||
});
|
||||
|
||||
@@ -112,7 +112,7 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
|
||||
dropdownContainerClassName="border border-mineshaft-600 bg-mineshaft-800"
|
||||
onValueChange={(selectedRole) =>
|
||||
handleChangeRole({
|
||||
currentSlug: slug,
|
||||
id,
|
||||
role: selectedRole
|
||||
})
|
||||
}
|
||||
@@ -147,6 +147,7 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handlePopUpOpen("groupMembers", {
|
||||
groupId: id,
|
||||
slug
|
||||
});
|
||||
}}
|
||||
@@ -195,7 +196,7 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handlePopUpOpen("deleteGroup", {
|
||||
slug,
|
||||
groupId: id,
|
||||
name
|
||||
});
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user