import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { useNavigate, useParams } from "@tanstack/react-router"; import { twMerge } from "tailwind-merge"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, PageHeader, Spinner, Tooltip } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { OrgPermissionGroupActions, OrgPermissionSubjects } from "@app/context"; import { useDeleteGroup } from "@app/hooks/api"; import { useGetGroupById } from "@app/hooks/api/groups/queries"; import { usePopUp } from "@app/hooks/usePopUp"; import { GroupCreateUpdateModal } from "./components/GroupCreateUpdateModal"; import { GroupDetailsSection } from "./components/GroupDetailsSection"; import { GroupMembersSection } from "./components/GroupMembersSection"; export enum TabSections { Member = "members", Groups = "groups", Roles = "roles", Identities = "identities" } const Page = () => { const navigate = useNavigate(); const params = useParams({ from: ROUTE_PATHS.Organization.GroupDetailsByIDPage.id }); const groupId = params.groupId as string; const { data, isPending } = useGetGroupById(groupId); const { mutateAsync: deleteMutateAsync } = useDeleteGroup(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "groupCreateUpdate", "deleteGroup", "upgradePlan" ] as const); const onDeleteGroupSubmit = async ({ name, id }: { name: string; id: string }) => { try { await deleteMutateAsync({ id }); createNotification({ text: `Successfully deleted the ${name} group`, type: "success" }); navigate({ to: "/organization/access-management" as const, search: { selectedTab: TabSections.Groups } }); } catch (err) { console.error(err); createNotification({ text: `Failed to delete the ${name} group`, type: "error" }); } handlePopUpClose("deleteGroup"); }; if (isPending) return ; return (
{data && (
{(isAllowed) => ( { handlePopUpOpen("groupCreateUpdate", { groupId, name: data.group.name, slug: data.group.slug, role: data.group.role }); }} disabled={!isAllowed} > Edit Group )} {(isAllowed) => ( { handlePopUpOpen("deleteGroup", { id: groupId, name: data.group.name }); }} disabled={!isAllowed} > Delete Group )}
)} handlePopUpToggle("deleteGroup", isOpen)} deleteKey="confirm" onDeleteApproved={() => onDeleteGroupSubmit(popUp?.deleteGroup?.data as { name: string; id: string }) } /> handlePopUpToggle("upgradePlan", isOpen)} text={(popUp.upgradePlan?.data as { description: string })?.description} />
); }; export const GroupDetailsByIDPage = () => { const { t } = useTranslation(); return ( <> {t("common.head-title", { title: t("settings.org.title") })} ); };