All files / src/sections Delete.tsx

11.11% Statements 1/9
0% Branches 0/2
0% Functions 0/3
11.11% Lines 1/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                                2x                                                      
import * as React from "react";
// nice-modal
import NiceModal, { muiDialogV5, useModal } from "@ebay/nice-modal-react";
// components
import Popup from "@common/Popup";
// localization
import { useTranslation } from "react-i18next";
import { namespaces } from "localization/resources/i18n.constants";
 
type DeleteProps = {
  title: string;
  deleteAction: () => void;
  children?: React.ReactNode;
  actionLabel?: string;
};
 
const Delete = NiceModal.create(
  ({ title, children, deleteAction, actionLabel }: DeleteProps) => {
    const modal = useModal();
    const { t } = useTranslation(namespaces.common);
 
    const primaryActionLabel = actionLabel
      ? actionLabel
      : t("delete.delete", { ns: namespaces.common });
 
    const handleDelete = () => {
      deleteAction();
      modal.hide();
    };
 
    return (
      <Popup
        {...muiDialogV5(modal)}
        title={title}
        onCancel={() => modal.hide()}
        onSubmit={handleDelete}
        actionLabel={primaryActionLabel}
      />
    );
  },
);
 
export default Delete;