Files
SCM-Manager/scm-ui/ui-webapp/src/repos/permissions/components/buttons/DeletePermissionButton.tsx

73 lines
1.7 KiB
TypeScript
Raw Normal View History

import React from "react";
import { translate } from "react-i18next";
import { Permission } from "@scm-manager/ui-types";
import { confirmAlert } from "@scm-manager/ui-components";
2018-08-30 09:49:36 +02:00
type Props = {
permission: Permission;
namespace: string;
repoName: string;
confirmDialog?: boolean;
t: (p: string) => string;
2018-08-30 11:33:49 +02:00
deletePermission: (
permission: Permission,
namespace: string,
repoName: string
) => void;
loading: boolean;
2018-08-30 09:49:36 +02:00
};
class DeletePermissionButton extends React.Component<Props> {
static defaultProps = {
confirmDialog: true
2018-08-30 09:49:36 +02:00
};
deletePermission = () => {
2018-08-30 11:33:49 +02:00
this.props.deletePermission(
this.props.permission,
this.props.namespace,
this.props.repoName
2018-08-30 11:33:49 +02:00
);
2018-08-30 09:49:36 +02:00
};
confirmDelete = () => {
const { t } = this.props;
confirmAlert({
title: t("permission.delete-permission-button.confirm-alert.title"),
message: t("permission.delete-permission-button.confirm-alert.message"),
2018-08-30 09:49:36 +02:00
buttons: [
{
label: t("permission.delete-permission-button.confirm-alert.submit"),
onClick: () => this.deletePermission()
2018-08-30 09:49:36 +02:00
},
{
label: t("permission.delete-permission-button.confirm-alert.cancel"),
onClick: () => null
}
]
2018-08-30 09:49:36 +02:00
});
};
isDeletable = () => {
return this.props.permission._links.delete;
};
render() {
const { confirmDialog } = this.props;
2018-08-30 09:49:36 +02:00
const action = confirmDialog ? this.confirmDelete : this.deletePermission;
if (!this.isDeletable()) {
return null;
}
2018-08-30 11:33:49 +02:00
return (
<a className="level-item" onClick={action}>
<span className="icon is-small">
<i className="fas fa-trash" />
</span>
</a>
2018-08-30 11:33:49 +02:00
);
2018-08-30 09:49:36 +02:00
}
}
export default translate("repos")(DeletePermissionButton);