import React from "react"; import { OneOrMany } from "@/helpers"; import useTheme from "@material-ui/core/styles/useTheme"; import { Trans, useTranslation } from "react-i18next"; import { Confirm } from "@/components/confirm"; import { Button, IconButton, Tooltip } from "@material-ui/core"; import { Delete } from "mdi-material-ui"; import { createBoundComponent } from "@/management/common/helpers"; export type DeleteResourceActionProps = { onDelete: (resource: OneOrMany) => void; resource: OneOrMany; label: (resource: T) => string; children?: (action: any) => React.ReactNode; }; export function DeleteResourceAction({ onDelete, resource, children, label }: DeleteResourceActionProps) { const theme = useTheme(); const { t } = useTranslation("management"); const confirmation = <> { !Array.isArray(resource) ? Czy na pewno chcesz usunąć { label(resource) }? : <> { t("confirm.bulk-delete") }
    { resource.map(current =>
  • { label(current) }
  • ) }
} ; return onDelete(resource) } content={ confirmation } confirm={ props => } > { action => children ? children(action) : } ; } export function createDeleteAction(props: Pick, 'label' | 'onDelete'>) { return createBoundComponent(DeleteResourceAction, props); }