Require confirmation on toggling delegation credential (#20576)
This commit is contained in:
1 parent
46c7afade6
commit
b6aedb830b
2 files changed
+61
-5
No files matched your search
@@ -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<DelegationItemProps["delegation"] | null>(
|
||||
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() {
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
<AddDwDButton />
|
||||
{/* Disable till we thoroughly test multiple delegation credentials support */}
|
||||
{/* <AddDwDButton /> */}
|
||||
</>
|
||||
) : (
|
||||
<EmptyScreen
|
||||
@@ -438,10 +448,52 @@ function DelegationCredentialList() {
|
||||
handleCreate={handleCreate}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ToggleDelegationDialog
|
||||
delegation={delegationToToggle}
|
||||
onClose={() => setDelegationToToggle(null)}
|
||||
onConfirm={handleToggleConfirm}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ToggleDelegationDialog = ({
|
||||
delegation,
|
||||
onConfirm,
|
||||
onClose,
|
||||
}: {
|
||||
delegation: DelegationItemProps["delegation"] | null;
|
||||
onConfirm: () => void;
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
if (!delegation) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Dialog
|
||||
name="toggle-delegation"
|
||||
open={!!delegation}
|
||||
onOpenChange={(open) => (!open ? onClose() : undefined)}>
|
||||
<ConfirmationDialogContent
|
||||
title={t(delegation.enabled ? "disable_delegation_credential" : "enable_delegation_credential")}
|
||||
confirmBtnText={t(delegation.enabled ? "disable" : "enable")}
|
||||
cancelBtnText={t("cancel")}
|
||||
variety={delegation.enabled ? "danger" : "success"}
|
||||
onConfirm={onConfirm}>
|
||||
<p className="mt-5">
|
||||
{t(
|
||||
delegation.enabled
|
||||
? "disable_delegation_credential_description"
|
||||
: "enable_delegation_credential_description"
|
||||
)}
|
||||
</p>
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default function DelegationCredentialListPage() {
|
||||
return <DelegationCredentialList />;
|
||||
}
|
||||
Reference in new issue
Block a user