feat: team ooo read-only for non-admin (#19700)
* feat team ooo read-only for non-admin * Update apps/web/playwright/out-of-office.e2e.ts Co-authored-by: Younes Henni <[email protected]> * updated error msgs with t * nit * nit --------- Co-authored-by: Younes Henni <[email protected]> Co-authored-by: Tushar Bhatt <[email protected]>
This commit is contained in:
9 files changed
+147
-29
No files matched your search
@@ -1,13 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
|
||||
import type { ButtonProps } from "@calcom/ui";
|
||||
import { Button } from "@calcom/ui";
|
||||
|
||||
import { CreateOrEditOutOfOfficeEntryModal } from "./CreateOrEditOutOfOfficeModal";
|
||||
import { OutOfOfficeTab } from "./OutOfOfficeToggleGroup";
|
||||
|
||||
const CreateNewOutOfOfficeEntry = ({
|
||||
size,
|
||||
@@ -17,8 +21,13 @@ const CreateNewOutOfOfficeEntry = ({
|
||||
"data-testid"?: string;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const me = useMeQuery();
|
||||
const { data: orgData } = trpc.viewer.organizations.listCurrent.useQuery();
|
||||
const isOrgAdminOrOwner =
|
||||
orgData && (orgData.user.role === MembershipRole.OWNER || orgData.user.role === MembershipRole.ADMIN);
|
||||
const hasTeamOOOAdminAccess = isOrgAdminOrOwner || me?.data?.isTeamAdminOrOwner;
|
||||
|
||||
const params = useSearchParams();
|
||||
const params = useCompatSearchParams();
|
||||
const openModalOnStart = !!params?.get("om");
|
||||
useEffect(() => {
|
||||
if (openModalOnStart) {
|
||||
@@ -27,6 +36,7 @@ const CreateNewOutOfOfficeEntry = ({
|
||||
}, [openModalOnStart]);
|
||||
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const selectedTab = params?.get("type") ?? OutOfOfficeTab.MINE;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -36,7 +46,8 @@ const CreateNewOutOfOfficeEntry = ({
|
||||
className="flex items-center justify-between px-4"
|
||||
StartIcon="plus"
|
||||
onClick={() => setOpenModal(true)}
|
||||
data-testid={rest["data-testid"]}>
|
||||
data-testid={rest["data-testid"]}
|
||||
disabled={selectedTab === OutOfOfficeTab.TEAM && !hasTeamOOOAdminAccess}>
|
||||
{t("add")}
|
||||
</Button>
|
||||
{openModal && (
|
||||
|
||||
@@ -62,9 +62,9 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
|
||||
const [searchMember, setSearchMember] = useState("");
|
||||
const debouncedSearchMember = useDebounce(searchMember, 500);
|
||||
const oooForMembers = trpc.viewer.teams.legacyListMembers.useInfiniteQuery(
|
||||
{ limit: 10, searchText: debouncedSearchMember },
|
||||
{ limit: 10, searchText: debouncedSearchMember, adminOrOwnedTeamsOnly: true },
|
||||
{
|
||||
enabled: true,
|
||||
enabled: oooType === OutOfOfficeTab.TEAM,
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
}
|
||||
);
|
||||
@@ -97,7 +97,11 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
|
||||
const [searchRedirectMember, setSearchRedirectMember] = useState("");
|
||||
const debouncedSearchRedirect = useDebounce(searchRedirectMember, 500);
|
||||
const redirectMembers = trpc.viewer.teams.legacyListMembers.useInfiniteQuery(
|
||||
{ limit: 10, searchText: debouncedSearchRedirect },
|
||||
{
|
||||
limit: 10,
|
||||
searchText: debouncedSearchRedirect,
|
||||
adminOrOwnedTeamsOnly: oooType === OutOfOfficeTab.TEAM,
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
@@ -218,7 +222,7 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
|
||||
/>
|
||||
|
||||
{/* In case of Team, Select Member for whom OOO is created */}
|
||||
{oooType === "team" && (
|
||||
{oooType === OutOfOfficeTab.TEAM && (
|
||||
<>
|
||||
<div className="mb-4">
|
||||
<Label className="text-emphasis mt-6">{t("select_team_member")}</Label>
|
||||
|
||||
@@ -37,6 +37,7 @@ interface OutOfOfficeEntry {
|
||||
} | null;
|
||||
notes: string | null;
|
||||
user: { id: number; avatarUrl: string; username: string; email: string; name: string } | null;
|
||||
canEditAndDelete: boolean;
|
||||
}
|
||||
|
||||
export const OutOfOfficeEntriesList = () => {
|
||||
@@ -220,7 +221,7 @@ export const OutOfOfficeEntriesList = () => {
|
||||
};
|
||||
editOutOfOfficeEntry(outOfOfficeEntryData);
|
||||
}}
|
||||
disabled={isPending || isFetching}
|
||||
disabled={isPending || isFetching || !item.canEditAndDelete}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("delete")}>
|
||||
@@ -229,7 +230,12 @@ export const OutOfOfficeEntriesList = () => {
|
||||
type="button"
|
||||
color="destructive"
|
||||
variant="icon"
|
||||
disabled={deleteOutOfOfficeEntryMutation.isPending || isPending || isFetching}
|
||||
disabled={
|
||||
deleteOutOfOfficeEntryMutation.isPending ||
|
||||
isPending ||
|
||||
isFetching ||
|
||||
!item.canEditAndDelete
|
||||
}
|
||||
StartIcon="trash-2"
|
||||
data-testid={`ooo-delete-${item.toUser?.username || "n-a"}`}
|
||||
onClick={() => {
|
||||
|
||||
@@ -5,8 +5,6 @@ import { useCallback } from "react";
|
||||
|
||||
import { useCompatSearchParams } from "@calcom/embed-core/src/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { ToggleGroup } from "@calcom/ui";
|
||||
|
||||
export enum OutOfOfficeTab {
|
||||
@@ -32,15 +30,10 @@ export const OutOfOfficeToggleGroup = () => {
|
||||
|
||||
const selectedTab = searchParams?.get("type") ?? OutOfOfficeTab.MINE;
|
||||
|
||||
const { data: user } = trpc.viewer.me.useQuery();
|
||||
const { data } = trpc.viewer.organizations.listCurrent.useQuery();
|
||||
const isOrgAdminOrOwner =
|
||||
data && (data.user.role === MembershipRole.OWNER || data.user.role === MembershipRole.ADMIN);
|
||||
const toggleGroupOptions = [{ value: OutOfOfficeTab.MINE, label: t("my_ooo") }];
|
||||
const hasTeamOOOAccess = isOrgAdminOrOwner || user?.isTeamAdminOrOwner;
|
||||
if (hasTeamOOOAccess) {
|
||||
toggleGroupOptions.push({ value: OutOfOfficeTab.TEAM, label: t("team_ooo") });
|
||||
}
|
||||
const toggleGroupOptions = [
|
||||
{ value: OutOfOfficeTab.MINE, label: t("my_ooo") },
|
||||
{ value: OutOfOfficeTab.TEAM, label: t("team_ooo") },
|
||||
];
|
||||
|
||||
return (
|
||||
<ToggleGroup
|
||||
@@ -52,7 +45,6 @@ export const OutOfOfficeToggleGroup = () => {
|
||||
router.push(`${pathname}?${newQuery}`);
|
||||
}}
|
||||
options={toggleGroupOptions}
|
||||
disabled={!hasTeamOOOAccess}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user