All files / src/features/Settings/Team/Modals DeleteTeamMemberModal.tsx

100% Statements 10/10
75% Branches 6/8
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                              3x   13x 13x 13x   13x     2x 2x   2x         13x                                                                                        
import { useDeleteMutation } from "@common/Modal/DeleteModal/useDeleteMutation";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { showMessage } from "@common/Toast";
import { QKEY_LIST_TEAM_MEMBERS } from "@constants/queryKeys";
import NiceModal from "@ebay/nice-modal-react";
import GivePopup from "@shared/Popup/GivePopup";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { checkPortals } from "@utils/routing";
 
export type Props = {
  itemName?: string;
  url?: string;
  onSuccess?: (res: any) => void;
};
 
const DeleteTeamMemberModal = NiceModal.create(
  ({ itemName, onSuccess, url }: Props) => {
    const { open, onClose } = useNiceModal();
    const { isMobileView } = useCustomThemeV2();
    const { isEnterprisePortal } = checkPortals();
 
    const { handleDelete, mutation } = useDeleteMutation({
      url: url,
      onSuccess: (res: any) => {
        Eif (onSuccess) onSuccess(res);
        showMessage("Success", "", !isMobileView, "Team Member Deleted");
 
        onClose();
      },
      refetchQuerieKeys: [QKEY_LIST_TEAM_MEMBERS],
    });
 
    return (
      <GivePopup
        open={open}
        description={`Are you sure you want to delete ${itemName}? This team member will be permanently deleted.`}
        onClose={onClose}
        isMobile={isMobileView}
        iconType="destructive"
        title={
          !isEnterprisePortal ? "Delete Team Member" : "Remove Team Member"
        }
        type="destructive"
        paperSx={{
          height: "fit-content !important",
        }}
        buttons={[
          {
            label: "Cancel",
            onClick: onClose,
            variant: "ghost",
          },
          {
            label: !isEnterprisePortal ? "Yes, Delete" : "Yes, Remove",
            onClick: handleDelete,
            color: "destructive",
            variant: "filled",
            disabled: mutation.isLoading,
          },
        ]}
        sx={{
          ...(isMobileView && {
            "& .MuiDialogActions-root": {
              display: "flex",
              flexDirection: "row",
              width: "100%",
              marginLeft: "auto",
              justifyContent: "flex-end",
            },
          }),
        }}
      />
    );
  },
);
export default DeleteTeamMemberModal;