From aaf630f01f6a97a422f0a0862caede0ee328f17c Mon Sep 17 00:00:00 2001 From: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:03:19 +0530 Subject: [PATCH] feat: Delete attribute modal (#17557) * feat: Delete attribute modal * move Modal file --------- Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> --- apps/web/public/static/locales/en/common.json | 3 ++ .../attributes/DeleteAttributeModal.tsx | 47 +++++++++++++++++++ .../attributes/attributes-list-view.tsx | 42 +++++++++-------- 3 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 packages/features/ee/organizations/pages/settings/attributes/DeleteAttributeModal.tsx diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index a39f1b9421..3ef6d6ba67 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -705,6 +705,9 @@ "no_teams": "You don't have any teams yet.", "no_teams_description": "Teams allow others to book events shared between your coworkers.", "submit": "Submit", + "confirm_remove_attribute": "Yes, remove attribute", + "remove_attribute": "Remove attribute", + "remove_attribute_confirmation_message": "Are you sure you want to remove the attribute '{{name}}'? All users currently assigned to it will be unassigned.", "delete": "Delete", "update": "Update", "save": "Save", diff --git a/packages/features/ee/organizations/pages/settings/attributes/DeleteAttributeModal.tsx b/packages/features/ee/organizations/pages/settings/attributes/DeleteAttributeModal.tsx new file mode 100644 index 0000000000..086b2ce01a --- /dev/null +++ b/packages/features/ee/organizations/pages/settings/attributes/DeleteAttributeModal.tsx @@ -0,0 +1,47 @@ +import type { Dispatch, SetStateAction } from "react"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import type { RouterOutputs } from "@calcom/trpc/react"; +import { trpc } from "@calcom/trpc/react"; +import { Dialog, ConfirmationDialogContent, showToast } from "@calcom/ui"; + +type AttributeItemProps = RouterOutputs["viewer"]["attributes"]["list"][number]; + +export function DeleteAttributeModal({ + attributeToDelete, + setAttributeToDelete, +}: { + attributeToDelete: AttributeItemProps; + setAttributeToDelete: Dispatch>; +}) { + const { t } = useLocale(); + const utils = trpc.useUtils(); + + const deleteMutation = trpc.viewer.attributes.delete.useMutation({ + onSuccess: () => { + showToast(t("attribute_deleted_successfully"), "success"); + utils.viewer.attributes.list.invalidate(); + }, + onError: (err) => { + showToast(err.message, "error"); + }, + }); + + return ( + setAttributeToDelete(undefined)}> + { + deleteMutation.mutate({ + id: attributeToDelete.id, + }); + }}> + {t("remove_attribute_confirmation_message", { + name: attributeToDelete.name, + })} + + + ); +} diff --git a/packages/features/ee/organizations/pages/settings/attributes/attributes-list-view.tsx b/packages/features/ee/organizations/pages/settings/attributes/attributes-list-view.tsx index 9a33952a86..41fe88b0aa 100644 --- a/packages/features/ee/organizations/pages/settings/attributes/attributes-list-view.tsx +++ b/packages/features/ee/organizations/pages/settings/attributes/attributes-list-view.tsx @@ -1,5 +1,6 @@ "use client"; +import type { Dispatch, SetStateAction } from "react"; import { useState } from "react"; import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired"; @@ -20,6 +21,7 @@ import { useMeta, } from "@calcom/ui"; +import { DeleteAttributeModal } from "./DeleteAttributeModal"; import { ListSkeleton } from "./ListSkeleton"; type AttributeItemProps = RouterOutputs["viewer"]["attributes"]["list"][number]; @@ -31,8 +33,13 @@ const TypeToLabelMap = { MULTI_SELECT: "Multi-select", }; -function AttributeItem({ attribute }: { attribute: AttributeItemProps }) { - const utils = trpc.useUtils(); +function AttributeItem({ + attribute, + setAttributeToDelete, +}: { + attribute: AttributeItemProps; + setAttributeToDelete: Dispatch>; +}) { const { t } = useLocale(); const [isEnabled, setIsEnabled] = useState(attribute.enabled); const mutation = trpc.viewer.attributes.toggleActive.useMutation({ @@ -44,16 +51,6 @@ function AttributeItem({ attribute }: { attribute: AttributeItemProps }) { }, }); - const deleteMutation = trpc.viewer.attributes.delete.useMutation({ - onSuccess: () => { - showToast(t("attribute_deleted_successfully"), "success"); - utils.viewer.attributes.list.invalidate(); - }, - onError: (err) => { - showToast(err.message, "error"); - }, - }); - const handleToggle = (checked: boolean) => { // Optimistically update the local state setIsEnabled(checked); @@ -68,10 +65,6 @@ function AttributeItem({ attribute }: { attribute: AttributeItemProps }) { ); }; - const handleDelete = () => { - deleteMutation.mutate({ id: attribute.id }); - }; - return (