From b6aedb830b3b975246267642b8856c9430d0150f Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Mon, 7 Apr 2025 13:35:53 +0530 Subject: [PATCH] Require confirmation on toggling delegation credential (#20576) --- apps/web/public/static/locales/en/common.json | 4 ++ .../pages/settings/delegationCredential.tsx | 62 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 79b253c140..a9d7bacbdf 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -3072,5 +3072,9 @@ "most_cancelled_bookings": "Most Cancelled Bookings", "name_or_email": "Name or Email", "salesforce_round_robin_skip_fallback_to_lead_owner": "If no contact is found, fallback to lead owner if it exists", + "enable_delegation_credential": "Enable Delegation Credential", + "enable_delegation_credential_description": "Grant Cal.com automatic access to the calendars of all organization members by enabling delegation credential.", + "disable_delegation_credential": "Disable Delegation Credential", + "disable_delegation_credential_description": "Once delegation credential is disabled, organization members who haven’t connected their calendars will need to do so manually.", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" } diff --git a/packages/features/ee/organizations/pages/settings/delegationCredential.tsx b/packages/features/ee/organizations/pages/settings/delegationCredential.tsx index 7c6b09beb4..fa33b2bb9e 100644 --- a/packages/features/ee/organizations/pages/settings/delegationCredential.tsx +++ b/packages/features/ee/organizations/pages/settings/delegationCredential.tsx @@ -11,7 +11,7 @@ import { trpc } from "@calcom/trpc/react"; import { Badge } from "@calcom/ui/components/badge"; import { InfoBadge } from "@calcom/ui/components/badge"; import { Button } from "@calcom/ui/components/button"; -import { DialogContent, DialogFooter } from "@calcom/ui/components/dialog"; +import { DialogContent, DialogFooter, ConfirmationDialogContent } from "@calcom/ui/components/dialog"; import { EmptyScreen } from "@calcom/ui/components/empty-screen"; import { Form } from "@calcom/ui/components/form"; import { TextAreaField } from "@calcom/ui/components/form"; @@ -323,12 +323,21 @@ function DelegationCredentialList() { deleteMutation.mutate({ id }); }; + const [delegationToToggle, setDelegationToToggle] = useState( + null + ); + const toggleDelegation = (delegation: DelegationItemProps["delegation"]) => { - if (delegation) { + setDelegationToToggle(delegation); + }; + + const handleToggleConfirm = () => { + if (delegationToToggle) { toggleEnabledMutation.mutate({ - id: delegation.id, - enabled: !delegation.enabled, + id: delegationToToggle.id, + enabled: !delegationToToggle.enabled, }); + setDelegationToToggle(null); } }; @@ -410,7 +419,8 @@ function DelegationCredentialList() { ) )} - + {/* Disable till we thoroughly test multiple delegation credentials support */} + {/* */} ) : ( )} + + setDelegationToToggle(null)} + onConfirm={handleToggleConfirm} + /> ); } +const ToggleDelegationDialog = ({ + delegation, + onConfirm, + onClose, +}: { + delegation: DelegationItemProps["delegation"] | null; + onConfirm: () => void; + onClose: () => void; +}) => { + const { t } = useLocale(); + if (!delegation) { + return null; + } + return ( + (!open ? onClose() : undefined)}> + +

+ {t( + delegation.enabled + ? "disable_delegation_credential_description" + : "enable_delegation_credential_description" + )} +

+
+
+ ); +}; + export default function DelegationCredentialListPage() { return ; }