2018-08-06 10:08:28 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-09-05 14:32:49 +02:00
|
|
|
import type { Repository } from "@scm-manager/ui-types";
|
2019-01-23 13:20:57 +01:00
|
|
|
import { Subtitle, DeleteButton, confirmAlert } from "@scm-manager/ui-components";
|
2018-08-06 10:08:28 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
confirmDialog?: boolean,
|
|
|
|
|
|
2019-01-23 12:07:28 +01:00
|
|
|
// dispatcher functions
|
|
|
|
|
delete: Repository => void,
|
|
|
|
|
|
2018-08-06 10:08:28 +02:00
|
|
|
// context props
|
|
|
|
|
t: string => string
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-23 10:08:15 +01:00
|
|
|
class DeleteRepo extends React.Component<Props> {
|
2018-08-06 10:08:28 +02:00
|
|
|
static defaultProps = {
|
|
|
|
|
confirmDialog: true
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-23 13:20:57 +01:00
|
|
|
deleteRepo = () => {
|
2019-01-23 12:07:28 +01:00
|
|
|
this.props.delete(this.props.repository);
|
2018-08-06 10:08:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
confirmDelete = () => {
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
confirmAlert({
|
2019-01-23 13:20:57 +01:00
|
|
|
title: t("deleteRepo.confirmAlert.title"),
|
|
|
|
|
message: t("deleteRepo.confirmAlert.message"),
|
2018-08-06 10:08:28 +02:00
|
|
|
buttons: [
|
|
|
|
|
{
|
2019-01-23 13:20:57 +01:00
|
|
|
label: t("deleteRepo.confirmAlert.submit"),
|
|
|
|
|
onClick: () => this.deleteRepo()
|
2018-08-06 10:08:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-01-23 13:20:57 +01:00
|
|
|
label: t("deleteRepo.confirmAlert.cancel"),
|
2018-08-06 10:08:28 +02:00
|
|
|
onClick: () => null
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isDeletable = () => {
|
|
|
|
|
return this.props.repository._links.delete;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { confirmDialog, t } = this.props;
|
2019-01-23 13:20:57 +01:00
|
|
|
const action = confirmDialog ? this.confirmDelete : this.deleteRepo;
|
2018-08-06 10:08:28 +02:00
|
|
|
|
|
|
|
|
if (!this.isDeletable()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-01-18 17:28:38 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-01-23 13:20:57 +01:00
|
|
|
<Subtitle subtitle={t("deleteRepo.subtitle")} />
|
2019-01-18 17:28:38 +01:00
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
|
|
|
|
<DeleteButton
|
2019-01-23 13:20:57 +01:00
|
|
|
label={t("deleteRepo.button")}
|
2019-01-18 17:28:38 +01:00
|
|
|
action={action}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2018-08-06 10:08:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 10:08:15 +01:00
|
|
|
export default translate("repos")(DeleteRepo);
|