"use client"; import { Trans } from "next-i18next"; import { useState } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Badge, ConfirmationDialogContent, Dialog, DropdownActions, showToast, Table } from "@calcom/ui"; import { subdomainSuffix } from "../../../../organizations/lib/orgDomains"; const { Body, Cell, ColumnTitle, Header, Row } = Table; export function AdminOrgTable() { const { t } = useLocale(); const utils = trpc.useUtils(); const [data] = trpc.viewer.organizations.adminGetAll.useSuspenseQuery(); const updateMutation = trpc.viewer.organizations.adminUpdate.useMutation({ onSuccess: async (_data, variables) => { showToast(t("org_has_been_processed"), "success"); await invalidateQueries(utils, { orgId: variables.id, }); }, onError: (err) => { showToast(err.message, "error"); }, }); const deleteMutation = trpc.viewer.organizations.adminDelete.useMutation({ onSuccess: async (res, variables) => { showToast(res.message, "success"); await invalidateQueries(utils, variables); }, onError: (err) => { console.error(err.message); showToast(t("org_error_processing"), "error"); }, }); const publishOrg = async (org: (typeof data)[number]) => { if (!org.metadata?.requestedSlug) { showToast(t("org_publish_error"), "error"); console.error("metadata.requestedSlug isn't set", org.metadata?.requestedSlug); return; } updateMutation.mutate({ id: org.id, slug: org.metadata.requestedSlug, }); }; const [orgToDelete, setOrgToDelete] = useState<(typeof data)[number] | null>(null); return (
{t("organization")} {t("owner")} {t("reviewed")} {t("dns_configured")} {t("published")} {t("admin_api")} {t("edit")}
{data.map((org) => (
{org.name}
{org.slug}.{subdomainSuffix()}
{org.members.length ? org.members[0].user.email : "No members"}
{!org.organizationSettings?.isAdminReviewed ? ( {t("unreviewed")} ) : ( {t("reviewed")} )}
{org.organizationSettings?.isOrganizationConfigured ? ( {t("dns_configured")} ) : ( {t("dns_missing")} )}
{!org.slug ? ( {t("unpublished")} ) : ( {t("published")} )}
{!org.organizationSettings?.isAdminAPIEnabled ? ( {t("disabled")} ) : ( {t("enabled")} )}
{ updateMutation.mutate({ id: org.id, organizationSettings: { isAdminReviewed: true, }, }); }, icon: "check" as const, }, ] : []), ...(!org.organizationSettings?.isOrganizationConfigured ? [ { id: "dns", label: t("mark_dns_configured"), onClick: () => { updateMutation.mutate({ id: org.id, organizationSettings: { isOrganizationConfigured: true, }, }); }, icon: "check-check" as const, }, ] : []), { id: "edit", label: t("edit"), href: `/settings/admin/organizations/${org.id}/edit`, icon: "pencil" as const, }, ...(!org.slug ? [ { id: "publish", label: t("publish"), onClick: () => { publishOrg(org); }, icon: "book-open-check" as const, }, ] : []), { id: "api", label: org.organizationSettings?.isAdminAPIEnabled ? t("revoke_admin_api") : t("grant_admin_api"), onClick: () => { updateMutation.mutate({ id: org.id, organizationSettings: { isAdminAPIEnabled: !org.organizationSettings?.isAdminAPIEnabled, }, }); }, icon: "terminal" as const, }, { id: "delete", label: t("delete"), onClick: () => { setOrgToDelete(org); }, icon: "trash" as const, }, ]} />
))}
setOrgToDelete(null)} onConfirm={() => { if (!orgToDelete) return; deleteMutation.mutate({ orgId: orgToDelete.id, }); }} />
); } export default AdminOrgTable; const DeleteOrgDialog = ({ org, onConfirm, onClose, }: { org: { id: number; name: string; } | null; onConfirm: () => void; onClose: () => void; }) => { const { t } = useLocale(); if (!org) { return null; } return ( // eslint-disable-next-line @typescript-eslint/no-empty-function -- noop (open ? () => {} : onClose())}> , ul:
    }}>
    • Teams that are member of this organization will also be deleted along with their event-types
    • Users that were part of the organization will not be deleted and their event-types will also remain intact.
    • Usernames would be changed to allow them to exist outside the organization
); }; async function invalidateQueries(utils: ReturnType, data: { orgId: number }) { await utils.viewer.organizations.adminGetAll.invalidate(); await utils.viewer.organizations.adminGet.invalidate({ id: data.orgId, }); // Due to some super weird reason, just invalidate doesn't work, so do refetch as well. await utils.viewer.organizations.adminGet.refetch({ id: data.orgId, }); }