diff --git a/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx b/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx index e3f48c5b3..ca51d2845 100644 --- a/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx +++ b/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityAddToProjectModal.tsx @@ -4,7 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { createNotification } from "@app/components/notifications"; -import { Button, FormControl, Modal, ModalContent,Select, SelectItem } from "@app/components/v2"; +import { Button, FormControl, Modal, ModalContent, Select, SelectItem } from "@app/components/v2"; import { useWorkspace } from "@app/context"; import { useAddIdentityToWorkspace, @@ -54,7 +54,7 @@ export const IdentityAddToProjectModal = ({ identityId, popUp, handlePopUpToggle const filteredWorkspaces = useMemo(() => { const wsWorkspaceIds = new Map(); - projectMemberships?.forEach((projectMembership: any) => { + projectMemberships?.forEach((projectMembership) => { wsWorkspaceIds.set(projectMembership.project.id, true); }); diff --git a/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityProjectRow.tsx b/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityProjectRow.tsx index 2c4c1148f..bf428f453 100644 --- a/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityProjectRow.tsx +++ b/frontend/src/views/Org/IdentityPage/components/IdentityProjectsSection/IdentityProjectRow.tsx @@ -1,9 +1,12 @@ +import { useMemo } from "react"; import { useRouter } from "next/router"; import { faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { format } from "date-fns"; +import { createNotification } from "@app/components/notifications"; import { IconButton, Td, Tooltip, Tr } from "@app/components/v2"; +import { useWorkspace } from "@app/context"; import { IdentityMembership } from "@app/hooks/api/identities/types"; import { ProjectMembershipRole } from "@app/hooks/api/roles/types"; import { UsePopUpState } from "@app/hooks/usePopUp"; @@ -21,7 +24,7 @@ const formatRoleName = (role: string, customRoleName?: string) => { if (role === ProjectMembershipRole.Admin) return "Admin"; if (role === ProjectMembershipRole.Member) return "Developer"; if (role === ProjectMembershipRole.Viewer) return "Viewer"; - if (role === ProjectMembershipRole.NoAccess) return "No access"; + if (role === ProjectMembershipRole.NoAccess) return "No Access"; return role; }; @@ -29,12 +32,34 @@ export const IdentityProjectRow = ({ membership: { id, createdAt, identity, project, roles }, handlePopUpOpen }: Props) => { + const { workspaces } = useWorkspace(); const router = useRouter(); + + const isAccessible = useMemo(() => { + const workspaceIds = new Map(); + + workspaces?.forEach((workspace) => { + workspaceIds.set(workspace.id, true); + }); + + return workspaceIds.has(project.id); + }, [workspaces, project]); + return ( router.push(`/project/${project.id}/members`)} + onClick={() => { + if (isAccessible) { + router.push(`/project/${project.id}/members`); + return; + } + + createNotification({ + text: "Unable to access project", + type: "error" + }); + }} > {project.name} {`${formatRoleName(roles[0].role, roles[0].customRoleName)}${ @@ -42,26 +67,28 @@ export const IdentityProjectRow = ({ }`} {format(new Date(createdAt), "yyyy-MM-dd")} -
- - { - e.stopPropagation(); - handlePopUpOpen("removeIdentityFromProject", { - identityId: identity.id, - identityName: identity.name, - projectId: project.id, - projectName: project.name - }); - }} - > - - - -
+ {isAccessible && ( +
+ + { + e.stopPropagation(); + handlePopUpOpen("removeIdentityFromProject", { + identityId: identity.id, + identityName: identity.name, + projectId: project.id, + projectName: project.name + }); + }} + > + + + +
+ )} ); diff --git a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx index 5cb615ebb..f08196df6 100644 --- a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx +++ b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx @@ -108,7 +108,7 @@ export const IdentitySection = withPermission( )} - + {/* { +type Props = { + handlePopUpOpen: ( + popUpName: keyof UsePopUpState<["deleteIdentity"]>, + data?: { + identityId: string; + name: string; + } + ) => void; +}; + +export const IdentityTable = ({ handlePopUpOpen }: Props) => { const router = useRouter(); const { currentOrg } = useOrganization(); const orgId = currentOrg?.id || ""; @@ -76,9 +90,7 @@ export const IdentityTable = () => { key={`identity-${id}`} onClick={() => router.push(`/org/${orgId}/identities/${id}`)} > - - {name} - + {name} { -
- router.push(`/org/${orgId}/identities/${id}`)} - > - - -
+ + +
+ +
+
+ + + {(isAllowed) => ( + { + e.stopPropagation(); + router.push(`/org/${orgId}/identities/${id}`); + }} + disabled={!isAllowed} + > + Edit Identity + + )} + + + {(isAllowed) => ( + { + e.stopPropagation(); + handlePopUpOpen("deleteIdentity", { + identityId: id, + name + }); + }} + disabled={!isAllowed} + > + Delete Identity + + )} + + +
);