feat: hide if team slider if org is private (#14201)
* feat: hide if org is private * fix: allow owners and admin to see page
This commit is contained in:
@@ -10,6 +10,7 @@ import { AvailabilitySliderTable } from "@calcom/features/timezone-buddy/compone
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
@@ -174,6 +175,7 @@ export default function AvailabilityPage() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const me = useMeQuery();
|
||||
const { data } = trpc.viewer.organizations.listCurrent.useQuery();
|
||||
|
||||
// Get a new searchParams string by merging the current
|
||||
// searchParams with a provided key/value pair
|
||||
@@ -186,6 +188,16 @@ export default function AvailabilityPage() {
|
||||
},
|
||||
[searchParams]
|
||||
);
|
||||
|
||||
const isOrgAdminOrOwner =
|
||||
data && (data.user.role === MembershipRole.OWNER || data.user.role === MembershipRole.ADMIN);
|
||||
const isOrgAndPrivate = data?.isOrganization && data.isPrivate;
|
||||
const toggleGroupOptions = [{ value: "mine", label: t("my_availability") }];
|
||||
|
||||
if (!isOrgAndPrivate || isOrgAdminOrOwner) {
|
||||
toggleGroupOptions.push({ value: "team", label: t("team_availability") });
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Shell
|
||||
@@ -204,15 +216,12 @@ export default function AvailabilityPage() {
|
||||
if (!value) return;
|
||||
router.push(`${pathname}?${createQueryString("type", value)}`);
|
||||
}}
|
||||
options={[
|
||||
{ value: "mine", label: t("my_availability") },
|
||||
{ value: "team", label: t("team_availability") },
|
||||
]}
|
||||
options={toggleGroupOptions}
|
||||
/>
|
||||
<NewScheduleButton />
|
||||
</div>
|
||||
}>
|
||||
{searchParams?.get("type") === "team" ? (
|
||||
{searchParams?.get("type") === "team" && (!isOrgAndPrivate || isOrgAdminOrOwner) ? (
|
||||
<AvailabilitySliderTable userTimeFormat={me?.data?.timeFormat ?? null} />
|
||||
) : (
|
||||
<AvailabilityListWithQuery />
|
||||
|
||||
Reference in New Issue
Block a user